From d07af19538583360617eb347c88f5bc91d9994e1 Mon Sep 17 00:00:00 2001 From: Alberto Gualis Date: Wed, 16 Oct 2024 11:24:12 +0200 Subject: [PATCH] fix: use fresh swapState when updaring swapStateVar --- packages/lib/modules/swap/SwapProvider.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/lib/modules/swap/SwapProvider.tsx b/packages/lib/modules/swap/SwapProvider.tsx index ae67957ea..df1f0c6da 100644 --- a/packages/lib/modules/swap/SwapProvider.tsx +++ b/packages/lib/modules/swap/SwapProvider.tsx @@ -174,6 +174,7 @@ export function _useSwap({ urlTxHash, ...pathParams }: PathParams) { }) function handleSimulationResponse({ returnAmount, swapType }: SimulateSwapResponse) { + const swapState = swapStateVar() swapStateVar({ ...swapState, swapType, @@ -192,6 +193,7 @@ export function _useSwap({ urlTxHash, ...pathParams }: PathParams) { } function setTokenIn(tokenAddress: Address) { + const swapState = swapStateVar() const isSameAsTokenOut = isSameAddress(tokenAddress, swapState.tokenOut.address) swapStateVar({ @@ -207,6 +209,7 @@ export function _useSwap({ urlTxHash, ...pathParams }: PathParams) { } function setTokenOut(tokenAddress: Address) { + const swapState = swapStateVar() const isSameAsTokenIn = isSameAddress(tokenAddress, swapState.tokenIn.address) swapStateVar({ @@ -222,6 +225,7 @@ export function _useSwap({ urlTxHash, ...pathParams }: PathParams) { } function switchTokens() { + const swapState = swapStateVar() swapStateVar({ ...swapState, tokenIn: swapState.tokenOut, @@ -288,6 +292,7 @@ export function _useSwap({ urlTxHash, ...pathParams }: PathParams) { } function getDefaultTokenState(chain: GqlChain) { + const swapState = swapStateVar() const { tokens: { defaultSwapTokens }, } = getNetworkConfig(chain)