From 90df2bf462e74f4c3e492791e26559b9ee5bc72f Mon Sep 17 00:00:00 2001 From: bigboydiamonds <57741810+bigboydiamonds@users.noreply.github.com> Date: Fri, 8 Mar 2024 13:03:08 -0800 Subject: [PATCH] feat(synapse-interface): update button states (#2214) * Add "Swap" button state * Stake button detects insufficient balance based on user input compared to balance * Disable Unstake button when input greater than staked balance * Unstake Button text when input too great * Update check for no lp token balance * Trim trailing zeroes after balances * Trim trailing zeroes off stake pool lp data * Rm unused var * Remove unused imports on Swap page * Add conditions for when Approve button label appears * Actions dropdown positioning * Trim zeroes when updating balance from Portfolio select button * Update Bridge Button State when necessary, reduce state changes when quote loading * Implement same for Swap * Update swap button disabled conditions to prevent flash post-approve * Update default WithdrawButton state * Withdraw Button state * Fix duplicate import --- .../components/Pools/PoolActionOptions.tsx | 15 ++- .../components/PortfolioTokenAsset.tsx | 7 +- .../BridgeTransactionButton.tsx | 2 +- .../SwapTransactionButton.tsx | 13 ++- .../pool/poolManagement/WithdrawButton.tsx | 16 +--- .../pages/stake/StakeCard.tsx | 91 ++++++++++++------- .../synapse-interface/pages/swap/index.tsx | 7 +- 7 files changed, 87 insertions(+), 64 deletions(-) diff --git a/packages/synapse-interface/components/Pools/PoolActionOptions.tsx b/packages/synapse-interface/components/Pools/PoolActionOptions.tsx index 33025fe6a2..a4b2bb9295 100644 --- a/packages/synapse-interface/components/Pools/PoolActionOptions.tsx +++ b/packages/synapse-interface/components/Pools/PoolActionOptions.tsx @@ -53,13 +53,12 @@ export const PoolActionOptions = ({ >
Actions
@@ -128,7 +127,7 @@ export function TransactionPopoverContainer({ { inputRef.current.focus() @@ -50,7 +51,11 @@ export const PortfolioTokenAsset = ({ dispatch(setFromChainId(portfolioChainId)) dispatch(setFromToken(token)) handleFocusOnBridgeInput() - dispatch(updateFromValue(getParsedBalance(balance, tokenDecimals))) + dispatch( + updateFromValue( + trimTrailingZeroesAfterDecimal(getParsedBalance(balance, tokenDecimals)) + ) + ) }, [token, balance, portfolioChainId]) return ( diff --git a/packages/synapse-interface/components/StateManagedBridge/BridgeTransactionButton.tsx b/packages/synapse-interface/components/StateManagedBridge/BridgeTransactionButton.tsx index fd32f093d4..3e046652f5 100644 --- a/packages/synapse-interface/components/StateManagedBridge/BridgeTransactionButton.tsx +++ b/packages/synapse-interface/components/StateManagedBridge/BridgeTransactionButton.tsx @@ -143,7 +143,7 @@ export const BridgeTransactionButton = ({ onClick: () => switchNetwork(fromChainId), pendingLabel: 'Switching chains', } - } else if (!isApproved) { + } else if (!isApproved && fromValueBigInt > 0 && bridgeQuote?.destQuery) { buttonProperties = { onClick: approveTxn, label: `Approve ${fromToken?.symbol}`, diff --git a/packages/synapse-interface/components/StateManagedSwap/SwapTransactionButton.tsx b/packages/synapse-interface/components/StateManagedSwap/SwapTransactionButton.tsx index baa2654f04..1f18649a19 100644 --- a/packages/synapse-interface/components/StateManagedSwap/SwapTransactionButton.tsx +++ b/packages/synapse-interface/components/StateManagedSwap/SwapTransactionButton.tsx @@ -54,10 +54,10 @@ export const SwapTransactionButton = ({ }, [balanceForToken, swapFromValue, swapChainId, swapFromToken, swapToToken]) const isButtonDisabled = - isLoading || + (isLoading && !isApproved) || + (isConnected && !sufficientBalance) || swapQuote === EMPTY_SWAP_QUOTE_ZERO || - swapQuote === EMPTY_SWAP_QUOTE || - (isConnected && !sufficientBalance) + swapQuote === EMPTY_SWAP_QUOTE let buttonProperties @@ -101,7 +101,12 @@ export const SwapTransactionButton = ({ onClick: () => switchNetwork(swapChainId), pendingLabel: 'Switching chains', } - } else if (!isApproved) { + } else if ( + !isApproved && + !isLoading && + fromValueBigInt > 0 && + swapQuote?.quote + ) { buttonProperties = { onClick: approveTxn, label: `Approve ${swapFromToken?.symbol}`, diff --git a/packages/synapse-interface/pages/pool/poolManagement/WithdrawButton.tsx b/packages/synapse-interface/pages/pool/poolManagement/WithdrawButton.tsx index 29ef872d4b..f3c2768da9 100644 --- a/packages/synapse-interface/pages/pool/poolManagement/WithdrawButton.tsx +++ b/packages/synapse-interface/pages/pool/poolManagement/WithdrawButton.tsx @@ -33,23 +33,17 @@ const WithdrawButton = ({ approveTxn, withdrawTxn, isApproved }) => { const poolDecimals = pool?.decimals[pool?.chainId] - const needsInput = stringToBigInt(inputValue, poolDecimals) === 0n - const isBalanceEnough = stringToBigInt(inputValue, poolDecimals) !== 0n && stringToBigInt(inputValue, poolDecimals) <= poolUserData.lpTokenBalance - const isButtonDisabled = - isLoading || !isBalanceEnough || withdrawQuote === DEFAULT_WITHDRAW_QUOTE + const isValidInput = stringToBigInt(inputValue, poolDecimals) !== 0n + const isValidQuote = withdrawQuote !== DEFAULT_WITHDRAW_QUOTE + const isButtonDisabled = isLoading || !isBalanceEnough || !isValidQuote let buttonProperties - if (needsInput) { - buttonProperties = { - label: 'Enter amount', - onClick: null, - } - } else if (!isBalanceEnough) { + if (!isBalanceEnough && isValidQuote && isValidInput) { buttonProperties = { label: 'Insufficient Balance', onClick: null, @@ -74,7 +68,7 @@ const WithdrawButton = ({ approveTxn, withdrawTxn, isApproved }) => { onClick: () => switchNetwork(pool.chainId), pendingLabel: 'Switching chains', } - } else if (!isApproved) { + } else if (!isApproved && isValidQuote && isValidInput) { buttonProperties = { onClick: approveTxn, label: `Approve Token`, diff --git a/packages/synapse-interface/pages/stake/StakeCard.tsx b/packages/synapse-interface/pages/stake/StakeCard.tsx index 06847657a8..d8c830db83 100644 --- a/packages/synapse-interface/pages/stake/StakeCard.tsx +++ b/packages/synapse-interface/pages/stake/StakeCard.tsx @@ -15,6 +15,7 @@ import { formatBigIntToString } from '@/utils/bigint/format' import { stringToBigInt } from '@/utils/bigint/format' import { Token } from '@/utils/types' import { InteractiveInputRowButton } from '@/components/InteractiveInputRowButton' +import { trimTrailingZeroesAfterDecimal } from '@/utils/trimTrailingZeroesAfterDecimal' import ButtonLoadingDots from '@/components/buttons/ButtonLoadingDots' import InteractiveInputRow from '@/components/InteractiveInputRow' import Button from '@/components/ui/tailwind/Button' @@ -131,12 +132,10 @@ const StakeCard = ({ address, chainId, pool }: StakeCardProps) => {
Unstaked
- {lpTokenBalance === 0n + {!lpTokenBalance ? '\u2212' - : formatBigIntToString( - lpTokenBalance, - tokenInfo.decimals, - 6 + : trimTrailingZeroesAfterDecimal( + formatBigIntToString(lpTokenBalance, tokenInfo.decimals, 6) )}{' '} {pool ? pool.symbol : ''} @@ -146,7 +145,9 @@ const StakeCard = ({ address, chainId, pool }: StakeCardProps) => {
Staked
- {formatBigIntToString(userStakeData.amount, tokenInfo.decimals, 6)}{' '} + {trimTrailingZeroesAfterDecimal( + formatBigIntToString(userStakeData.amount, tokenInfo.decimals, 6) + )}{' '} {pool ? pool.symbol : ''} @@ -157,17 +158,19 @@ const StakeCard = ({ address, chainId, pool }: StakeCardProps) => { {pool?.customRewardToken ?? 'SYN'} Earned
- {userStakeData.reward === 0n + {!userStakeData.reward ? '\u2212' - : formatBigIntToString(userStakeData.reward, 18, 6)}{' '} + : trimTrailingZeroesAfterDecimal( + formatBigIntToString(userStakeData.reward, 18, 6) + )}{' '} {pool?.customRewardToken ?? 'SYN'}
- {userStakeData.reward === 0n ? null : ( + {!userStakeData.reward ? null : (