add transfer insufficient usdc gas warning (#19)
This commit is contained in:
+1
-1
@@ -39,7 +39,7 @@
|
|||||||
"@cosmjs/tendermint-rpc": "^0.31.0",
|
"@cosmjs/tendermint-rpc": "^0.31.0",
|
||||||
"@dydxprotocol/abacus": "^0.4.1",
|
"@dydxprotocol/abacus": "^0.4.1",
|
||||||
"@dydxprotocol/v4-client-js": "^0.32.0",
|
"@dydxprotocol/v4-client-js": "^0.32.0",
|
||||||
"@dydxprotocol/v4-localization": "^0.0.21",
|
"@dydxprotocol/v4-localization": "^0.0.25",
|
||||||
"@ethersproject/providers": "^5.7.2",
|
"@ethersproject/providers": "^5.7.2",
|
||||||
"@js-joda/core": "^5.5.3",
|
"@js-joda/core": "^5.5.3",
|
||||||
"@radix-ui/react-collapsible": "^1.0.3",
|
"@radix-ui/react-collapsible": "^1.0.3",
|
||||||
|
|||||||
Generated
+4
-4
@@ -29,8 +29,8 @@ dependencies:
|
|||||||
specifier: ^0.32.0
|
specifier: ^0.32.0
|
||||||
version: 0.32.0
|
version: 0.32.0
|
||||||
'@dydxprotocol/v4-localization':
|
'@dydxprotocol/v4-localization':
|
||||||
specifier: ^0.0.21
|
specifier: ^0.0.25
|
||||||
version: 0.0.21
|
version: 0.0.25
|
||||||
'@ethersproject/providers':
|
'@ethersproject/providers':
|
||||||
specifier: ^5.7.2
|
specifier: ^5.7.2
|
||||||
version: 5.7.2
|
version: 5.7.2
|
||||||
@@ -1186,8 +1186,8 @@ packages:
|
|||||||
- utf-8-validate
|
- utf-8-validate
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/@dydxprotocol/v4-localization@0.0.21:
|
/@dydxprotocol/v4-localization@0.0.25:
|
||||||
resolution: {integrity: sha512-HG6JdHSHIq39rSgYNv36DwiJ550POicJGg+3nJNHstKHMO+fnHMdPpDBIjqUx3fXRphF9NxfhdgnmYqj2x++rg==}
|
resolution: {integrity: sha512-Rp6VHA8z+nwgvTjjB3fvL8gY7bd4DYDHV+NPoL0MFuRm39vhFxGlBVAGDkXPkQTh6YU5BlZV2yXLkDeSfFqEBQ==}
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/@emotion/is-prop-valid@1.2.1:
|
/@emotion/is-prop-valid@1.2.1:
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import { getSelectedNetwork } from '@/state/appSelectors';
|
|||||||
|
|
||||||
import { useAccounts } from './useAccounts';
|
import { useAccounts } from './useAccounts';
|
||||||
import { usePollNativeTokenBalance } from './usePollNativeTokenBalance';
|
import { usePollNativeTokenBalance } from './usePollNativeTokenBalance';
|
||||||
|
import { usePollUSDCBalance } from './usePollUSDCBalance';
|
||||||
|
|
||||||
type UseAccountBalanceProps = {
|
type UseAccountBalanceProps = {
|
||||||
// Token Items
|
// Token Items
|
||||||
@@ -96,9 +97,13 @@ export const useAccountBalance = ({
|
|||||||
.div(QUANTUM_MULTIPLIER)
|
.div(QUANTUM_MULTIPLIER)
|
||||||
.toNumber();
|
.toNumber();
|
||||||
|
|
||||||
|
const usdcCoinBalance = usePollUSDCBalance({ dydxAddress });
|
||||||
|
const usdcBalance = MustBigNumber(usdcCoinBalance?.amount).div(QUANTUM_MULTIPLIER).toNumber();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
balance,
|
balance,
|
||||||
nativeTokenBalance,
|
nativeTokenBalance,
|
||||||
|
usdcBalance,
|
||||||
queryStatus: isCosmosChain ? cosmosQuery.status : evmQuery.status,
|
queryStatus: isCosmosChain ? cosmosQuery.status : evmQuery.status,
|
||||||
isQueryFetching: isCosmosChain ? cosmosQuery.isFetching : evmQuery.fetchStatus === 'fetching',
|
isQueryFetching: isCosmosChain ? cosmosQuery.isFetching : evmQuery.fetchStatus === 'fetching',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ export const DYDXBalancePanel = () => {
|
|||||||
size={ButtonSize.Small}
|
size={ButtonSize.Small}
|
||||||
onClick={() => dispatch(openDialog({ type: DialogTypes.Receive }))}
|
onClick={() => dispatch(openDialog({ type: DialogTypes.Receive }))}
|
||||||
>
|
>
|
||||||
{stringGetter({ key: STRING_KEYS.EXCHANGE_RECEIVED })}
|
{stringGetter({ key: STRING_KEYS.RECEIVE })}
|
||||||
</Styled.ReceiveButton>
|
</Styled.ReceiveButton>
|
||||||
<Button
|
<Button
|
||||||
slotLeft={<Icon iconName={IconName.Send} />}
|
slotLeft={<Icon iconName={IconName.Send} />}
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ export const TransferForm = ({
|
|||||||
const { dydxAddress } = useAccounts();
|
const { dydxAddress } = useAccounts();
|
||||||
const { address: recipientAddress, size } = useSelector(getTransferInputs, shallowEqual) || {};
|
const { address: recipientAddress, size } = useSelector(getTransferInputs, shallowEqual) || {};
|
||||||
const { transfer, simulateTransfer } = useSubaccount();
|
const { transfer, simulateTransfer } = useSubaccount();
|
||||||
const { nativeTokenBalance } = useAccountBalance();
|
const { nativeTokenBalance, usdcBalance } = useAccountBalance();
|
||||||
const { selectedNetwork } = useSelectedNetwork();
|
const { selectedNetwork } = useSelectedNetwork();
|
||||||
|
|
||||||
// User Input
|
// User Input
|
||||||
@@ -104,6 +104,8 @@ export const TransferForm = ({
|
|||||||
.toNumber();
|
.toNumber();
|
||||||
const amount = asset === DydxChainAsset.USDC ? size?.usdcSize : size?.size;
|
const amount = asset === DydxChainAsset.USDC ? size?.usdcSize : size?.size;
|
||||||
|
|
||||||
|
const showNotEnoughGasWarning = fees && asset === DydxChainAsset.USDC && usdcBalance < fees;
|
||||||
|
|
||||||
// BN
|
// BN
|
||||||
const amountBN = MustBigNumber(amount);
|
const amountBN = MustBigNumber(amount);
|
||||||
const balanceBN = MustBigNumber(balance);
|
const balanceBN = MustBigNumber(balance);
|
||||||
@@ -359,6 +361,15 @@ export const TransferForm = ({
|
|||||||
/>
|
/>
|
||||||
</WithDetailsReceipt>
|
</WithDetailsReceipt>
|
||||||
|
|
||||||
|
{showNotEnoughGasWarning && (
|
||||||
|
<AlertMessage type={AlertType.Warning}>
|
||||||
|
{stringGetter({
|
||||||
|
key: STRING_KEYS.TRANSFER_INSUFFICIENT_GAS,
|
||||||
|
params: { USDC_BALANCE: `(${usdcBalance})` },
|
||||||
|
})}
|
||||||
|
</AlertMessage>
|
||||||
|
)}
|
||||||
|
|
||||||
{error && <AlertMessage type={AlertType.Error}>{error.message}</AlertMessage>}
|
{error && <AlertMessage type={AlertType.Error}>{error.message}</AlertMessage>}
|
||||||
|
|
||||||
<Styled.Footer>
|
<Styled.Footer>
|
||||||
|
|||||||
Reference in New Issue
Block a user