From 7f9d8daba419fd1090981b61c7212eb15a285077 Mon Sep 17 00:00:00 2001 From: Leonard Ge Date: Thu, 24 Dec 2020 18:53:00 +0800 Subject: [PATCH] Added max button. --- src/components/SendDialog.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/components/SendDialog.js b/src/components/SendDialog.js index ffa0d3d..2539ad8 100644 --- a/src/components/SendDialog.js +++ b/src/components/SendDialog.js @@ -464,9 +464,18 @@ function useForm(balanceInfo, addressHelperText, passAddressValidation) { margin="normal" type="number" InputProps={{ - endAdornment: tokenSymbol ? ( - {tokenSymbol} - ) : null, + endAdornment: ( + + + {tokenSymbol ? tokenSymbol : null} + + ), inputProps: { step: Math.pow(10, -decimals), }, @@ -477,11 +486,11 @@ function useForm(balanceInfo, addressHelperText, passAddressValidation) { setTransferAmountString( - (balanceAmount / Math.pow(10, decimals)).toFixed(decimals), + balanceAmountToUserAmount(balanceAmount, decimals), ) } > - Max: {balanceAmount / Math.pow(10, decimals)} + Max: {balanceAmountToUserAmount(balanceAmount, decimals)} } /> @@ -497,6 +506,10 @@ function useForm(balanceInfo, addressHelperText, passAddressValidation) { }; } +function balanceAmountToUserAmount(balanceAmount, decimals) { + return (balanceAmount / Math.pow(10, decimals)).toFixed(decimals) +} + function EthWithdrawalCompleter({ ethAccount, publicKey }) { const [swaps] = useSwapApiGet(`swaps_from/sol/${publicKey.toBase58()}`, { refreshInterval: 10000,