-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
166 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { isSwapError } from './isSwapError'; | ||
|
||
describe('isSwapError', () => { | ||
it('returns true for a valid SwapError object', () => { | ||
const response = { | ||
error: 'Swap failed', | ||
details: 'Insufficient balance', | ||
}; | ||
|
||
expect(isSwapError(response)).toBe(true); | ||
}); | ||
|
||
it('returns false for null or non-object inputs', () => { | ||
expect(isSwapError(null)).toBe(false); | ||
expect(isSwapError(undefined)).toBe(false); | ||
expect(isSwapError('error')).toBe(false); | ||
expect(isSwapError(123)).toBe(false); | ||
}); | ||
|
||
it('returns false for objects without the "error" property', () => { | ||
const response = { | ||
message: 'An error occurred', | ||
}; | ||
|
||
expect(isSwapError(response)).toBe(false); | ||
}); | ||
|
||
it('returns false for empty objects', () => { | ||
const response = {}; | ||
|
||
expect(isSwapError(response)).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { SwapError } from '../types'; | ||
|
||
export function isSwapError(response: unknown): response is SwapError { | ||
return ( | ||
response !== null && typeof response === 'object' && 'error' in response | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { formatTokenAmount } from './formatTokenAmount'; | ||
|
||
describe('formatTokenAmount', () => { | ||
test('formats amount correctly with 18 decimals', () => { | ||
const amount = '100000000000000000'; | ||
const decimals = 18; | ||
const formattedAmount = formatTokenAmount(amount, decimals); | ||
expect(formattedAmount).toBe('0.1'); | ||
}); | ||
|
||
test('formats amount correctly with different decimals', () => { | ||
const amount = '1000000000'; | ||
const decimals = 9; | ||
const formattedAmount = formatTokenAmount(amount, decimals); | ||
expect(formattedAmount).toBe('1'); | ||
}); | ||
|
||
test('handles very small amounts correctly', () => { | ||
const amount = '1'; | ||
const decimals = 18; | ||
const formattedAmount = formatTokenAmount(amount, decimals); | ||
expect(formattedAmount).toBe('1e-18'); | ||
}); | ||
|
||
test('handles zero amount correctly', () => { | ||
const amount = '0'; | ||
const decimals = 18; | ||
const formattedAmount = formatTokenAmount(amount, decimals); | ||
expect(formattedAmount).toBe('0'); | ||
}); | ||
|
||
test('handles large amounts correctly', () => { | ||
const amount = '1000000000000000000000000000'; | ||
const decimals = 18; | ||
const formattedAmount = formatTokenAmount(amount, decimals); | ||
expect(formattedAmount).toBe('1000000000'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export function formatTokenAmount(amount: string, decimals: number) { | ||
// Convert the string amount to a number using decimals value | ||
const numberAmount = Number(amount) / 10 ** decimals; | ||
return numberAmount.toString(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { getRoundedAmount } from './getRoundedAmount'; | ||
|
||
describe('getRoundedAmount', () => { | ||
it('returns a rounded number with specified decimal places', () => { | ||
const balance = '0.0002851826238227'; | ||
const fractionDigits = 5; | ||
const result = getRoundedAmount(balance, fractionDigits); | ||
expect(result).toBe('0.00029'); | ||
}); | ||
|
||
it('returns a rounded number with more decimal places than available', () => { | ||
const balance = '123.456'; | ||
const fractionDigits = 10; | ||
const result = getRoundedAmount(balance, fractionDigits); | ||
expect(result).toBe('123.456'); | ||
}); | ||
}); |
Oops, something went wrong.