From 36a35d225cef28f8d56fc73062cffd6ab87e0d14 Mon Sep 17 00:00:00 2001 From: abtestingalpha Date: Wed, 19 Jun 2024 10:05:11 -0400 Subject: [PATCH 1/2] RFQ input vs bridgeQuote validation --- .../BridgeTransactionButton.tsx | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/packages/synapse-interface/components/StateManagedBridge/BridgeTransactionButton.tsx b/packages/synapse-interface/components/StateManagedBridge/BridgeTransactionButton.tsx index e087beeabc..eb3fe88574 100644 --- a/packages/synapse-interface/components/StateManagedBridge/BridgeTransactionButton.tsx +++ b/packages/synapse-interface/components/StateManagedBridge/BridgeTransactionButton.tsx @@ -67,23 +67,31 @@ export const BridgeTransactionButton = ({ ) }, [balanceForToken, fromValue, fromChainId, toChainId, toToken]) + const fromTokenDecimals: number | undefined = + fromToken && fromToken?.decimals[fromChainId] + + const fromValueBigInt = useMemo(() => { + return fromTokenDecimals ? stringToBigInt(fromValue, fromTokenDecimals) : 0 + }, [fromValue, fromTokenDecimals]) + + const bridgeQuoteAmountGreaterThanInputForRfq = useMemo(() => { + return ( + bridgeQuote.bridgeModuleName === 'SynapseRFQ' && + bridgeQuote.outputAmount > fromValueBigInt + ) + }, [bridgeQuote.outputAmount, fromValueBigInt]) + const isButtonDisabled = isLoading || bridgeQuote === EMPTY_BRIDGE_QUOTE_ZERO || bridgeQuote === EMPTY_BRIDGE_QUOTE || (destinationAddress && !isAddress(destinationAddress)) || (isConnected && !sufficientBalance) || + bridgeQuoteAmountGreaterThanInputForRfq || isBridgePaused let buttonProperties - const fromTokenDecimals: number | undefined = - fromToken && fromToken?.decimals[fromChainId] - - const fromValueBigInt = useMemo(() => { - return fromTokenDecimals ? stringToBigInt(fromValue, fromTokenDecimals) : 0 - }, [fromValue, fromTokenDecimals]) - if (isBridgePaused) { buttonProperties = { label: 'Bridge paused', @@ -113,6 +121,11 @@ export const BridgeTransactionButton = ({ label: `Amount must be greater than fee`, onClick: null, } + } else if (bridgeQuoteAmountGreaterThanInputForRfq) { + buttonProperties = { + label: 'Invalid bridge quote', + onClick: null, + } } else if (!isConnected && fromValueBigInt > 0) { buttonProperties = { label: `Connect Wallet to Bridge`, From b6461b660d02faaf37dfebeab316a247defc943a Mon Sep 17 00:00:00 2001 From: abtestingalpha Date: Wed, 19 Jun 2024 16:15:07 -0400 Subject: [PATCH 2/2] Remove unused --- .../StateManagedBridge/BridgeTransactionButton.tsx | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/synapse-interface/components/StateManagedBridge/BridgeTransactionButton.tsx b/packages/synapse-interface/components/StateManagedBridge/BridgeTransactionButton.tsx index eb3fe88574..e88f4720c0 100644 --- a/packages/synapse-interface/components/StateManagedBridge/BridgeTransactionButton.tsx +++ b/packages/synapse-interface/components/StateManagedBridge/BridgeTransactionButton.tsx @@ -1,8 +1,6 @@ -import { useSelector } from 'react-redux' import { useMemo } from 'react' import { TransactionButton } from '@/components/buttons/TransactionButton' import { EMPTY_BRIDGE_QUOTE, EMPTY_BRIDGE_QUOTE_ZERO } from '@/constants/bridge' -import { RootState } from '@/store/store' import { useAccount, useAccountEffect, useSwitchChain } from 'wagmi' import { useEffect, useState } from 'react' import { isAddress } from 'viem' @@ -12,10 +10,7 @@ import { stringToBigInt } from '@/utils/bigint/format' import { useBridgeDisplayState, useBridgeState } from '@/slices/bridge/hooks' import { usePortfolioBalances } from '@/slices/portfolio/hooks' import { useAppDispatch } from '@/store/hooks' -import { - setIsDestinationWarningAccepted, - setShowDestinationWarning, -} from '@/slices/bridgeDisplaySlice' +import { setIsDestinationWarningAccepted } from '@/slices/bridgeDisplaySlice' export const BridgeTransactionButton = ({ approveTxn,