This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: disable max button after setting max balance (#360)
- Loading branch information
1 parent
d8e79f2
commit e2fedbf
Showing
7 changed files
with
154 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { SwapDirection } from '../types'; | ||
|
||
import { calculateMaxBalanceToSwap } from './helpers'; | ||
|
||
import { TOKENS } from '~/systems/Core'; | ||
|
||
const TX_COST = { | ||
byte: BigInt(1000), | ||
fee: BigInt(2), | ||
gas: BigInt(704176), | ||
total: BigInt(705176), | ||
}; | ||
|
||
const CTX_FROM_ETH_TO_DAI = { | ||
coinFrom: TOKENS[0], | ||
coinTo: TOKENS[1], | ||
coinFromBalance: BigInt(399999990), | ||
coinToBalance: BigInt(119567935145), | ||
txCost: TX_COST, | ||
}; | ||
|
||
const CTX_FROM_DAI_TO_ETH = { | ||
coinFrom: TOKENS[1], | ||
coinTo: TOKENS[0], | ||
coinFromBalance: BigInt(119567935145), | ||
coinToBalance: BigInt(399999990), | ||
txCost: TX_COST, | ||
}; | ||
|
||
describe('Swap Helpers', () => { | ||
describe('calculateMaxBalanceToSwap', () => { | ||
it('should discount network fee from ETH balance when ETH is from coin', () => { | ||
const maxBalanceToSwap = calculateMaxBalanceToSwap({ | ||
direction: SwapDirection.fromTo, | ||
ctx: CTX_FROM_ETH_TO_DAI, | ||
}); | ||
|
||
expect(maxBalanceToSwap.value).toEqual('0.399999988'); | ||
}); | ||
|
||
it('should discount network fee from ETH balance when ETH is to coin', () => { | ||
const maxBalanceToSwap = calculateMaxBalanceToSwap({ | ||
direction: SwapDirection.toFrom, | ||
ctx: CTX_FROM_DAI_TO_ETH, | ||
}); | ||
|
||
expect(maxBalanceToSwap.value).toEqual('0.399999988'); | ||
}); | ||
|
||
it('should not discount network fee from DAI balance when DAI is from coin', () => { | ||
const maxBalanceToSwap = calculateMaxBalanceToSwap({ | ||
direction: SwapDirection.fromTo, | ||
ctx: CTX_FROM_DAI_TO_ETH, | ||
}); | ||
|
||
expect(maxBalanceToSwap.value).toEqual('119.567935145'); | ||
}); | ||
|
||
it('should not discount network fee from DAI balance when DAI is to coin', () => { | ||
const maxBalanceToSwap = calculateMaxBalanceToSwap({ | ||
direction: SwapDirection.toFrom, | ||
ctx: CTX_FROM_ETH_TO_DAI, | ||
}); | ||
|
||
expect(maxBalanceToSwap.value).toEqual('119.567935145'); | ||
}); | ||
}); | ||
}); |
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