-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(transfer to L2): max amount (#62)
- Loading branch information
Showing
9 changed files
with
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
import {getString} from '../../../utils'; | ||
import {evaluate, getString} from '../../../utils'; | ||
|
||
export const INSUFFICIENT_BALANCE_ERROR_MSG = getString( | ||
'menus.transfer.insufficient_balance_error_msg' | ||
); | ||
|
||
export const MAX_AMOUNT_ERROR_MSG = (maxAmount, symbol) => | ||
evaluate(getString('menus.transfer.max_amount_error_msg'), {maxAmount, symbol}); |
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,30 @@ | ||
import {useAsyncMemo} from 'use-async-memo'; | ||
|
||
import {maxDeposit} from '../api/bridge'; | ||
import {useTransferData} from '../components/Features/Transfer/Transfer.hooks'; | ||
import {useTokenBridgeContract} from './useContract'; | ||
|
||
const cache = {}; | ||
|
||
export const useMaxAmount = () => { | ||
const {symbol, isL1, selectedToken} = useTransferData(); | ||
const getTokenBridgeContract = useTokenBridgeContract(); | ||
|
||
const fetchMaxAmount = async () => { | ||
const {decimals, bridgeAddress} = selectedToken; | ||
const contract = getTokenBridgeContract(bridgeAddress); | ||
return await maxDeposit({decimals, contract}); | ||
}; | ||
|
||
return useAsyncMemo(async () => { | ||
if (symbol && isL1) { | ||
if (!cache[symbol]) { | ||
const value = await fetchMaxAmount(); | ||
cache[symbol] = value; | ||
return value; | ||
} | ||
return cache[symbol]; | ||
} | ||
return null; | ||
}, [symbol, isL1]); | ||
}; |
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