Skip to content

Commit

Permalink
Define quote timeout for hook + callback
Browse files Browse the repository at this point in the history
  • Loading branch information
bigboydiamonds committed Jul 22, 2024
1 parent 1196773 commit 669734c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions packages/synapse-interface/pages/state-managed-bridge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import { useStaleQuoteUpdater } from '@/utils/hooks/useStaleQuoteUpdater'
import { convertUuidToUnix } from '@/utils/convertUuidToUnix'

const StateManagedBridge = () => {
const dispatch = useAppDispatch()
const { address } = useAccount()
const { synapseSDK } = useSynapseContext()
const router = useRouter()
Expand All @@ -83,6 +84,7 @@ const StateManagedBridge = () => {
const bridgeDisplayRef = useRef(null)
const currentSDKRequestID = useRef(0)
const quoteToastRef = useRef({ id: '' })
const quoteTimeout = 15000

const {
fromChainId,
Expand All @@ -95,14 +97,13 @@ const StateManagedBridge = () => {
isLoading: isQuoteLoading,
isWalletPending,
}: BridgeState = useBridgeState()
const { showSettingsSlideOver, showDestinationAddress } = useSelector(

const { showSettingsSlideOver } = useSelector(
(state: RootState) => state.bridgeDisplay
)

const [isApproved, setIsApproved] = useState<boolean>(false)

const dispatch = useAppDispatch()

useEffect(() => {
segmentAnalyticsEvent(`[Bridge page] arrives`, {
fromChainId,
Expand Down Expand Up @@ -327,7 +328,8 @@ const StateManagedBridge = () => {
bridgeQuote,
getAndSetBridgeQuote,
isQuoteLoading,
isWalletPending
isWalletPending,
quoteTimeout
)

const approveTxn = async () => {
Expand Down Expand Up @@ -359,7 +361,7 @@ const StateManagedBridge = () => {
bridgeQuoteTimestamp
)

if (timeDifference > 15000) {
if (timeDifference > quoteTimeout) {
await getAndSetBridgeQuote()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isEmpty, isNull, isNumber, isUndefined } from 'lodash'
import { isNull, isNumber } from 'lodash'
import { useEffect, useRef } from 'react'

import { BridgeQuote } from '@/utils/types'
Expand All @@ -15,7 +15,7 @@ export const useStaleQuoteUpdater = (
refreshQuoteCallback: () => Promise<void>,
isQuoteLoading: boolean,
isWalletPending: boolean,
staleTimeout: number = 15000 // 15_000ms or 15s
staleTimeout: number = 15000 // Default 15_000ms or 15s
) => {
const eventListenerRef = useRef<null | (() => void)>(null)

Expand Down

0 comments on commit 669734c

Please sign in to comment.