diff --git a/src/services/chains/index.test.ts b/src/services/chains/index.test.ts index e7145b44c..572ac77e5 100644 --- a/src/services/chains/index.test.ts +++ b/src/services/chains/index.test.ts @@ -1022,13 +1022,16 @@ function getTransactionDetailTestCases() { } function closeToTestCases() { - it('should 0.0008436 and 0.0008658 consider as closed amount', function () { - assert.isTrue(closeTo(0.0008436, 0.0008658)); + it('should not consider 0.0008436 and 0.0008658 as closed amount', function () { + assert.isFalse(closeTo(0.0008436, 0.0008658)); }); - it('should 0.0001 and 0.00011 consider as closed amount', function () { - assert.isTrue(closeTo(0.0001, 0.00011)); + it('should not consider 0.0001 and 0.00011 as closed amount', function () { + assert.isFalse(closeTo(0.0001, 0.00011)); }); it('should not consider 0.001 and 0.003 consider as closed amount', function () { assert.isFalse(closeTo(0.001, 0.003)); }); + it('should consider 1000.1 and 1000 consider as closed amount', function () { + assert.isTrue(closeTo(1000.1, 1000)); + }); } diff --git a/src/services/chains/index.ts b/src/services/chains/index.ts index acb23f2bc..0c32d1be7 100644 --- a/src/services/chains/index.ts +++ b/src/services/chains/index.ts @@ -107,5 +107,5 @@ export function getAppropriateNetworkId(params: { // This function is used to compare two numbers with a delta as a margin of error export const closeTo = (a: number, b: number, delta = 0.001) => { - return Math.abs(a - b) < delta; + return Math.abs(1 - a / b) < delta; };