Skip to content

Commit

Permalink
request user confirm every quote
Browse files Browse the repository at this point in the history
  • Loading branch information
bigboydiamonds committed Sep 11, 2024
1 parent 54a9e01 commit 1ded454
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,18 @@ export const BridgeTransactionButton = ({
onClick: () => switchChain({ chainId: fromChainId }),
pendingLabel: t('Switching chains'),
}
} else if (
isApproved &&
hasValidQuote &&
!hasSameSelectionsAsPreviousQuote &&
!hasUserConfirmedChange
) {
buttonProperties = {
label: t('Confirm quote'),
onClick: () => onUserAcceptChange(),
className:
'!outline !outline-1 !outline-synapsePurple !outline-offset-[-1px] !from-bgLight !to-bgLight',
}
} else if (
isApproved &&
hasValidQuote &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { useState, useEffect, useMemo, useRef } from 'react'

import { useBridgeState } from '@/slices/bridge/hooks'
import { useBridgeQuoteState } from '@/slices/bridgeQuote/hooks'
import { constructStringifiedBridgeSelections } from './useBridgeValidations'
import {
constructStringifiedBridgeSelections,
useBridgeValidations,
} from './useBridgeValidations'
import { BridgeQuote } from '@/utils/types'

export const useConfirmNewBridgePrice = () => {
Expand All @@ -15,6 +18,7 @@ export const useConfirmNewBridgePrice = () => {
useState<boolean>(false)

const { bridgeQuote, previousBridgeQuote } = useBridgeQuoteState()
const { hasValidQuote } = useBridgeValidations()
const { debouncedFromValue, fromToken, toToken, fromChainId, toChainId } =
useBridgeState()

Expand Down Expand Up @@ -64,10 +68,17 @@ export const useConfirmNewBridgePrice = () => {
hasSameSelectionsAsPreviousQuote
) {
requestUserConfirmChange(previousBridgeQuote)
} else if (hasValidQuote && !hasSameSelectionsAsPreviousQuote) {
requestUserConfirmChange(bridgeQuote)
} else {
resetConfirm()
}
}, [bridgeQuote, previousBridgeQuote, hasSameSelectionsAsPreviousQuote])
}, [
bridgeQuote,
previousBridgeQuote,
hasSameSelectionsAsPreviousQuote,
hasValidQuote,
])

const requestUserConfirmChange = (previousQuote: BridgeQuote) => {
if (!hasQuoteOutputChanged && !hasUserConfirmedChange) {
Expand Down

0 comments on commit 1ded454

Please sign in to comment.