Skip to content

Commit

Permalink
refactor: Add useBridgeTokensStore
Browse files Browse the repository at this point in the history
  • Loading branch information
chrstph-dvx committed Dec 9, 2024
1 parent 1b63a37 commit 54e32b1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
7 changes: 3 additions & 4 deletions packages/arb-token-bridge-ui/src/hooks/useArbTokenBridge.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useState, useMemo } from 'react'
import { useCallback, useMemo } from 'react'
import { Chain, useAccount } from 'wagmi'
import { BigNumber } from 'ethers'
import { Signer } from '@ethersproject/abstract-signer'
Expand Down Expand Up @@ -35,6 +35,7 @@ import { isNetwork } from '../util/networks'
import { isValidTeleportChainPair } from '@/token-bridge-sdk/teleport'
import { getProviderForChainId } from '@/token-bridge-sdk/utils'
import { useArbQueryParams } from './useArbQueryParams'
import { useBridgeTokensStore } from './useBridgeTokensStore'

export const wait = (ms = 0) => {
return new Promise(res => setTimeout(res, ms))
Expand Down Expand Up @@ -89,9 +90,7 @@ export const useArbTokenBridge = (
): ArbTokenBridge => {
const { l1, l2 } = params
const { address: walletAddress } = useAccount()
const [bridgeTokens, setBridgeTokens] = useState<
ContractStorage<ERC20BridgeToken> | undefined
>(undefined)
const { bridgeTokens, setBridgeTokens } = useBridgeTokensStore()

const [{ destinationAddress }] = useArbQueryParams()

Expand Down
16 changes: 16 additions & 0 deletions packages/arb-token-bridge-ui/src/hooks/useBridgeTokensStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { create } from 'zustand'
import { ContractStorage, ERC20BridgeToken } from './arbTokenBridge.types'

type BridgeTokens = ContractStorage<ERC20BridgeToken> | undefined
type BridgeTokensStore = {
bridgeTokens: BridgeTokens
setBridgeTokens: (
fn: (prevBridgeTokens: BridgeTokens) => BridgeTokens
) => void
}
export const useBridgeTokensStore = create<BridgeTokensStore>(set => ({
bridgeTokens: undefined,
setBridgeTokens: fn => {
set(state => ({ bridgeTokens: fn(state.bridgeTokens) }))
}
}))

0 comments on commit 54e32b1

Please sign in to comment.