Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use fresh swapState when updaring swapStateVar #73

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/lib/modules/swap/SwapProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export function _useSwap({ urlTxHash, ...pathParams }: PathParams) {
})

function handleSimulationResponse({ returnAmount, swapType }: SimulateSwapResponse) {
const swapState = swapStateVar()
swapStateVar({
...swapState,
swapType,
Expand All @@ -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({
Expand All @@ -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({
Expand All @@ -222,6 +225,7 @@ export function _useSwap({ urlTxHash, ...pathParams }: PathParams) {
}

function switchTokens() {
const swapState = swapStateVar()
swapStateVar({
...swapState,
tokenIn: swapState.tokenOut,
Expand Down Expand Up @@ -288,6 +292,7 @@ export function _useSwap({ urlTxHash, ...pathParams }: PathParams) {
}

function getDefaultTokenState(chain: GqlChain) {
const swapState = swapStateVar()
const {
tokens: { defaultSwapTokens },
} = getNetworkConfig(chain)
Expand Down
Loading