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 Nov 22, 2024
1 parent d107948 commit 31b866b
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 @@ -36,6 +36,7 @@ import { isNetwork } from '../util/networks'
import { useDestinationAddressStore } from '../components/TransferPanel/AdvancedSettings'
import { isValidTeleportChainPair } from '@/token-bridge-sdk/teleport'
import { getProviderForChainId } from '@/token-bridge-sdk/utils'
import { useBridgeTokensStore } from './useBridgeTokensStore'

export const wait = (ms = 0) => {
return new Promise(res => setTimeout(res, ms))
Expand Down Expand Up @@ -90,9 +91,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 } = useDestinationAddressStore()

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 31b866b

Please sign in to comment.