-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: disable CTA button based on balance wip
- Loading branch information
Showing
6 changed files
with
58 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,70 @@ | ||
import { useSelector } from 'react-redux'; | ||
import { useMemo } from 'react'; | ||
import { SWAPS_CHAINID_DEFAULT_TOKEN_MAP } from '../../../shared/constants/swaps'; | ||
import { | ||
getBridgeQuotes, | ||
getFromAmount, | ||
getFromChain, | ||
getFromToken, | ||
getToChain, | ||
getValidationErrors, | ||
getToToken, | ||
} from '../../ducks/bridge/selectors'; | ||
import { getMultichainCurrentChainId } from '../../selectors/multichain'; | ||
import { useMultichainSelector } from '../useMultichainSelector'; | ||
import { useIsMultichainSwap } from '../../pages/bridge/hooks/useIsMultichainSwap'; | ||
import useLatestBalance from './useLatestBalance'; | ||
|
||
export const useIsTxSubmittable = () => { | ||
const fromToken = useSelector(getFromToken); | ||
const toToken = useSelector(getToToken); | ||
const fromChain = useSelector(getFromChain); | ||
const fromChainId = useMultichainSelector(getMultichainCurrentChainId); | ||
const toChain = useSelector(getToChain); | ||
const fromAmount = useSelector(getFromAmount); | ||
const { activeQuote } = useSelector(getBridgeQuotes); | ||
|
||
const isSwap = useIsMultichainSwap(); | ||
const { | ||
isInsufficientBalance, | ||
isInsufficientGasBalance, | ||
isInsufficientGasForQuote, | ||
} = useSelector(getValidationErrors); | ||
|
||
const { balanceAmount } = useLatestBalance(fromToken, fromChain?.chainId); | ||
const { balanceAmount: nativeAssetBalance } = useLatestBalance( | ||
fromChain?.chainId | ||
const balanceAmount = useLatestBalance(fromToken, fromChainId); | ||
const nativeAssetBalance = useLatestBalance( | ||
fromChainId | ||
? SWAPS_CHAINID_DEFAULT_TOKEN_MAP[ | ||
fromChain.chainId as keyof typeof SWAPS_CHAINID_DEFAULT_TOKEN_MAP | ||
fromChainId as keyof typeof SWAPS_CHAINID_DEFAULT_TOKEN_MAP | ||
] | ||
: null, | ||
fromChain?.chainId, | ||
fromChainId, | ||
); | ||
|
||
return Boolean( | ||
fromToken && | ||
toToken && | ||
fromChain && | ||
toChain && | ||
fromAmount && | ||
activeQuote && | ||
!isInsufficientBalance(balanceAmount) && | ||
!isInsufficientGasBalance(nativeAssetBalance) && | ||
!isInsufficientGasForQuote(nativeAssetBalance), | ||
return useMemo( | ||
() => | ||
Boolean( | ||
fromToken && | ||
toToken && | ||
fromChainId && | ||
(isSwap || toChain) && | ||
fromAmount && | ||
activeQuote && | ||
!isInsufficientBalance(balanceAmount) && | ||
!isInsufficientGasBalance(nativeAssetBalance) && | ||
!isInsufficientGasForQuote(nativeAssetBalance), | ||
), | ||
[ | ||
activeQuote, | ||
balanceAmount, | ||
fromAmount, | ||
fromChainId, | ||
fromToken, | ||
isInsufficientBalance, | ||
isInsufficientGasBalance, | ||
isInsufficientGasForQuote, | ||
nativeAssetBalance, | ||
isSwap, | ||
toChain, | ||
toToken, | ||
], | ||
); | ||
}; |
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