Skip to content

Commit

Permalink
Change compare logic in draft donation service (#1823)
Browse files Browse the repository at this point in the history
* Change compare amount logic, in draft donation service

related to #1819 https://github.com/GeneralMagicio/QAcc-BE/blob/809fa8e57f6cc881acfdf0c387a0a0a8ceebaeae/src/services/chains/index.ts#L105

* Fix test cases
  • Loading branch information
mohammadranjbarz authored Sep 23, 2024
1 parent f129c51 commit 312a395
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/services/chains/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1065,13 +1065,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));
});
}
2 changes: 1 addition & 1 deletion src/services/chains/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,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;
};

0 comments on commit 312a395

Please sign in to comment.