From 6a55ee09914b605bc59dce310b47b5770da5ff18 Mon Sep 17 00:00:00 2001 From: Jonah Lin <57741810+linjonah@users.noreply.github.com> Date: Wed, 11 Oct 2023 15:32:21 -0700 Subject: [PATCH 1/2] Add resetBridgeQuote reducer --- packages/synapse-interface/slices/bridge/reducer.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/synapse-interface/slices/bridge/reducer.ts b/packages/synapse-interface/slices/bridge/reducer.ts index 5e93696ea7..3f92f0ee2a 100644 --- a/packages/synapse-interface/slices/bridge/reducer.ts +++ b/packages/synapse-interface/slices/bridge/reducer.ts @@ -456,6 +456,9 @@ export const bridgeSlice = createSlice({ setBridgeQuote: (state, action: PayloadAction) => { state.bridgeQuote = action.payload }, + resetBridgeQuote: (state) => { + state.bridgeQuote = initialState.bridgeQuote + }, updateFromValue: (state, action: PayloadAction) => { state.fromValue = action.payload }, @@ -563,6 +566,7 @@ export const bridgeSlice = createSlice({ export const { setBridgeQuote, + resetBridgeQuote, setFromChainId, setToChainId, setFromToken, From 99bff1fa059ef355a7e1b62062cbc9b13bf99f3f Mon Sep 17 00:00:00 2001 From: Jonah Lin <57741810+linjonah@users.noreply.github.com> Date: Wed, 11 Oct 2023 15:39:40 -0700 Subject: [PATCH 2/2] Clear bridge quote if input is empty --- packages/synapse-interface/slices/bridge/updater.tsx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/synapse-interface/slices/bridge/updater.tsx b/packages/synapse-interface/slices/bridge/updater.tsx index f035ec7e44..100f31c03f 100644 --- a/packages/synapse-interface/slices/bridge/updater.tsx +++ b/packages/synapse-interface/slices/bridge/updater.tsx @@ -10,6 +10,7 @@ import { updateDebouncedFromValue, updateDebouncedToTokensFromValue, } from './actions' +import { resetBridgeQuote } from './reducer' import { Token } from '@/utils/types' import { stringToBigInt } from '@/utils/bigint/format' import { useSynapseContext } from '@/utils/providers/SynapseProvider' @@ -25,6 +26,7 @@ export default function Updater(): null { toToken, toTokens, fromValue, + bridgeQuote, debouncedFromValue, debouncedToTokensFromValue, }: BridgeState = useBridgeState() @@ -106,6 +108,13 @@ export default function Updater(): null { } }, [debouncedToTokensFromValue, toTokens]) + // Clear bridge quote if input is empty + useEffect(() => { + if (debouncedFromValue === initialState.debouncedFromValue) { + dispatch(resetBridgeQuote()) + } + }, [debouncedFromValue, bridgeQuote]) + return null }