Skip to content

Commit

Permalink
chore: remove rounding of amount (#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
abcrane123 authored Jun 13, 2024
1 parent 9af516c commit 75060d1
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 21 deletions.
15 changes: 0 additions & 15 deletions src/swap/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@ describe('isValidAmount', () => {
expect(isValidAmount('')).toBe(true);
});

it('should return true for a valid number string with less than 11 characters', () => {
expect(isValidAmount('12345')).toBe(true);
});

it('should return false for a number string with more than 11 characters', () => {
expect(isValidAmount('123456789012')).toBe(false);
});

it('should return true for a valid number string with a decimal point', () => {
expect(isValidAmount('123.45')).toBe(true);
});
Expand Down Expand Up @@ -85,13 +77,6 @@ describe('formatTokenAmount', () => {
expect(formattedAmount).toBe('1');
});

test('rounds to a maximum of 11 significant digits', () => {
const amount = '16732157880511600003860';
const decimals = 18;
const formattedAmount = formatTokenAmount(amount, decimals);
expect(formattedAmount).toBe('16732.157881');
});

test('handles very small amounts correctly', () => {
const amount = '1';
const decimals = 18;
Expand Down
7 changes: 1 addition & 6 deletions src/swap/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ import type { SwapError } from './types';

// checks that input is a number
export function isValidAmount(value: string) {
if (value.length > 11) {
return false;
}
if (value === '') {
return true;
}
Expand All @@ -21,7 +18,5 @@ export function isSwapError(response: unknown): response is SwapError {
export function formatTokenAmount(amount: string, decimals: number) {
// Convert the string amount to a number using decimals value
const numberAmount = Number(amount) / Math.pow(10, decimals);
// Round to a maximum of 11 significant digits
const roundedAmount = Number(numberAmount.toPrecision(11));
return roundedAmount.toString();
return numberAmount.toString();
}

0 comments on commit 75060d1

Please sign in to comment.