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

chore: adds viem compatibility from @arbitrum/sdk #1743

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions packages/arb-token-bridge-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
"@headlessui/tailwindcss": "^0.1.2",
"@heroicons/react": "^2.0.18",
"@offchainlabs/cobalt": "0.3.2",
"@rainbow-me/rainbowkit": "^0.12.16",
"@rainbow-me/rainbowkit": "^2.1.2",
"@rehooks/local-storage": "^2.4.4",
"@sentry/react": "^7.73.0",
"@sentry/tracing": "^7.73.0",
"@tanstack/react-query": "^5.49.2",
"@tippyjs/react": "^4.2.6",
"@uidotdev/usehooks": "^2.4.1",
"@uniswap/token-lists": "^1.0.0-beta.31",
Expand All @@ -26,7 +27,6 @@
"boring-avatars": "^1.7.0",
"cheerio": "^1.0.0-rc.12",
"dayjs": "^1.11.8",
"ethers": "^5.6.0",
"fetch-retry": "^5.0.3",
"graphql": "^16.8.1",
"lodash-es": "^4.17.21",
Expand All @@ -46,7 +46,8 @@
"swr": "^2.1.2",
"tailwind-merge": "^2.0.0",
"use-query-params": "^2.2.1",
"wagmi": "^0.12.18",
"viem": "2.16.5",
"wagmi": "^2.10.8",
"zod": "^3.22.4",
"zustand": "^4.3.9"
},
Expand Down
34 changes: 19 additions & 15 deletions packages/arb-token-bridge-ui/src/components/App/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useCallback, useEffect, useState } from 'react'
import * as Sentry from '@sentry/react'

import { useAccount, useNetwork, WagmiConfig, useDisconnect } from 'wagmi'
import { useAccount, WagmiProvider, useDisconnect } from 'wagmi'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import {
darkTheme,
RainbowKitProvider,
Expand Down Expand Up @@ -319,7 +320,7 @@ function ConnectedChainSyncer() {

const [{ sourceChain, destinationChain }, setQueryParams] =
useArbQueryParams()
const { chain } = useNetwork()
const { chain } = useAccount()

const setSourceChainToConnectedChain = useCallback(() => {
if (typeof chain === 'undefined') {
Expand Down Expand Up @@ -402,22 +403,25 @@ function ConnectedChainSyncer() {

export default function App() {
const [overmind] = useState<Overmind<typeof config>>(createOvermind(config))
const queryClient = new QueryClient()

return (
<Provider value={overmind}>
<ArbQueryParamProvider>
<WagmiConfig {...wagmiConfigProps}>
<RainbowKitProvider
theme={rainbowkitTheme}
{...rainbowKitProviderProps}
>
<ConnectedChainSyncer />
<AppContextProvider>
<AppContent />
</AppContextProvider>
</RainbowKitProvider>
</WagmiConfig>
</ArbQueryParamProvider>
<QueryClientProvider client={queryClient}>
<ArbQueryParamProvider>
<WagmiProvider config={wagmiConfigProps.config}>
<RainbowKitProvider
theme={rainbowkitTheme}
{...rainbowKitProviderProps}
>
<ConnectedChainSyncer />
<AppContextProvider>
<AppContent />
</AppContextProvider>
</RainbowKitProvider>
</WagmiProvider>
</ArbQueryParamProvider>
</QueryClientProvider>
</Provider>
)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useMemo } from 'react'
import { Address } from 'wagmi'
import { Address } from 'viem'
import { twMerge } from 'tailwind-merge'
import {
ArrowTopRightOnSquareIcon,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getNetworkName } from '../../util/networks'
import { errorToast } from '../common/atoms/Toast'
import { Button } from '../common/Button'
import { useSwitchNetworkWithConfig } from '../../hooks/useSwitchNetworkWithConfig'
import { useNetwork } from 'wagmi'
import { useAccount } from 'wagmi'
import { isDepositReadyToRedeem } from '../../state/app/utils'
import { useRedeemRetryable } from '../../hooks/useRedeemRetryable'
import { WithdrawalCountdown } from '../common/WithdrawalCountdown'
Expand All @@ -30,7 +30,7 @@ export function TransactionsTableRowAction({
type: 'deposits' | 'withdrawals'
address: Address | undefined
}) {
const { chain } = useNetwork()
const { chain } = useAccount()
const { switchNetworkAsync } = useSwitchNetworkWithConfig()
const networkName = getNetworkName(chain?.id ?? 0)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useMemo, useState } from 'react'
import { useSigner } from 'wagmi'
import { useWalletClient } from 'wagmi'
import { BigNumber, constants, utils } from 'ethers'
import { Dialog, UseDialogProps } from '../common/Dialog'
import { Checkbox } from '../common/Checkbox'
Expand Down Expand Up @@ -35,7 +35,7 @@ export function CustomFeeTokenApprovalDialog(
const { parentChain, parentChainProvider } = useNetworksRelationship(networks)
const { isEthereumMainnet } = isNetwork(parentChain.id)

const { data: l1Signer } = useSigner({ chainId: parentChain.id })
const { data: l1Signer } = useWalletClient({ chainId: parentChain.id })
const l1GasPrice = useGasPrice({ provider: parentChainProvider })

const [checked, setChecked] = useState(false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Listbox } from '@headlessui/react'
import { ChevronDownIcon } from '@heroicons/react/24/outline'
import { twMerge } from 'tailwind-merge'
import { Chain } from 'wagmi'
import { Chain } from 'viem'

import { getNetworkName } from '../../util/networks'
import { getBridgeUiConfigForChain } from '../../util/bridgeUiConfig'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect, useMemo, useState } from 'react'
import { BigNumber, constants, utils } from 'ethers'
import { useAccount, useChainId } from 'wagmi'

import { useSigner } from 'wagmi'
import { useWalletClient } from 'wagmi'
import { Dialog, UseDialogProps } from '../common/Dialog'
import { Checkbox } from '../common/Checkbox'
import { ExternalLink } from '../common/ExternalLink'
Expand Down Expand Up @@ -56,7 +56,7 @@ export function TokenApprovalDialog(props: TokenApprovalDialogProps) {
const provider = isDepositMode ? parentChainProvider : childChainProvider
const gasPrice = useGasPrice({ provider })
const chainId = useChainId()
const { data: signer } = useSigner({
const { data: signer } = useWalletClient({
chainId
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
CheckCircleIcon,
ExclamationCircleIcon
} from '@heroicons/react/24/outline'
import { Chain } from 'wagmi'
import { Chain } from 'viem'

import { Loader } from '../common/atoms/Loader'
import { useAppState } from '../../state'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Tippy from '@tippyjs/react'
import { constants, utils } from 'ethers'
import { useLatest } from 'react-use'
import * as Sentry from '@sentry/react'
import { useAccount, useChainId, useSigner } from 'wagmi'
import { useAccount, useChainId, useWalletClient } from 'wagmi'
import { TransactionResponse } from '@ethersproject/providers'
import { twMerge } from 'tailwind-merge'

Expand Down Expand Up @@ -130,10 +130,10 @@ export function TransferPanel() {

const { isEOA, isSmartContractWallet } = useAccountType()

const { data: l1Signer } = useSigner({
const { data: l1Signer } = useWalletClient({
chainId: parentChain.id
})
const { data: l2Signer } = useSigner({
const { data: l2Signer } = useWalletClient({
chainId: childChain.id
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react'
import { ArrowsUpDownIcon, ArrowDownIcon } from '@heroicons/react/24/outline'
import { twMerge } from 'tailwind-merge'
import { BigNumber, constants, utils } from 'ethers'
import { Chain, useAccount } from 'wagmi'
import { useAccount } from 'wagmi'
import { Chain } from 'viem'
import { useMedia } from 'react-use'

import { Loader } from '../common/atoms/Loader'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ExternalLink } from '../../common/ExternalLink'
import { Checkbox } from '../../common/Checkbox'
import { useEffect, useState } from 'react'
import { isNetwork } from '../../../util/networks'
import { useNetwork } from 'wagmi'
import { useAccount } from 'wagmi'

export function USDCDepositConfirmationDialogCheckbox({
onChange,
Expand All @@ -19,7 +19,7 @@ export function USDCDepositConfirmationDialogCheckbox({
false
])
const externalLinkClassnames = 'arb-hover underline'
const { chain } = useNetwork()
const { chain } = useAccount()
const { isTestnet } = isNetwork(chain?.id ?? 0)

const destinationNetworkName = isTestnet ? 'Arbitrum Sepolia' : 'Arbitrum One'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
useRef,
useState
} from 'react'
import { Chain } from 'wagmi'
import { Chain } from 'viem'
import { useDebounce } from '@uidotdev/usehooks'
import { ShieldExclamationIcon } from '@heroicons/react/24/outline'
import { twMerge } from 'tailwind-merge'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BigNumber, Signer } from 'ethers'
import useSWR from 'swr'
import { useSigner } from 'wagmi'
import { useWalletClient } from 'wagmi'

import { DepositGasEstimates, GasEstimates } from '../arbTokenBridge.types'
import { BridgeTransferStarterFactory } from '@/token-bridge-sdk/BridgeTransferStarterFactory'
Expand Down Expand Up @@ -55,7 +55,7 @@ export function useGasEstimates({
gasEstimates: GasEstimates | DepositGasEstimates | undefined
error: any
} {
const { data: signer } = useSigner()
const { data: signer } = useWalletClient()

const { data: gasEstimates, error } = useSWR(
signer && sourceChainBalance && sourceChainBalance.gte(amount)
Expand Down
4 changes: 2 additions & 2 deletions packages/arb-token-bridge-ui/src/hooks/useAccountIsBlocked.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useMemo } from 'react'
import { useAccount, useNetwork } from 'wagmi'
import { useAccount } from 'wagmi'
import useSWRImmutable from 'swr/immutable'

import { ApiResponseSuccess } from '../pages/api/screenings'
Expand Down Expand Up @@ -40,7 +40,7 @@ async function fetcher(address: Address): Promise<boolean> {

export function useAccountIsBlocked() {
const { address } = useAccount()
const { chain } = useNetwork()
const { chain } = useAccount()

const queryKey = useMemo(() => {
if (typeof address === 'undefined') {
Expand Down
7 changes: 3 additions & 4 deletions packages/arb-token-bridge-ui/src/hooks/useAccountMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import { useState, useEffect, useMemo } from 'react'
import Resolution from '@unstoppabledomains/resolution'

import {
useProvider,
usePublicClient,
useAccount,
useDisconnect,
useNetwork,
useEnsName,
useEnsAvatar
} from 'wagmi'
Expand Down Expand Up @@ -46,12 +45,12 @@ async function tryLookupUDName(provider: JsonRpcProvider, address: string) {
}

export const useAccountMenu = () => {
const l1Provider = useProvider({ chainId: 1 })
const l1Provider = usePublicClient({ chainId: 1 })
const { address } = useAccount()
const { disconnect } = useDisconnect({
onSettled: onDisconnectHandler
})
const { chain } = useNetwork()
const { chain } = useAccount()

const { openTransactionHistoryPanel } = useAppContextActions()
const [, setQueryParams] = useArbQueryParams()
Expand Down
3 changes: 2 additions & 1 deletion packages/arb-token-bridge-ui/src/hooks/useArbTokenBridge.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useCallback, useState, useMemo } from 'react'
import { Chain, useAccount } from 'wagmi'
import { useAccount } from 'wagmi'
import { Chain } from 'viem'
import { BigNumber } from 'ethers'
import { Signer } from '@ethersproject/abstract-signer'
import { JsonRpcProvider } from '@ethersproject/providers'
Expand Down
4 changes: 2 additions & 2 deletions packages/arb-token-bridge-ui/src/hooks/useClaimWithdrawal.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback, useState } from 'react'
import * as Sentry from '@sentry/react'
import { useAccount, useSigner } from 'wagmi'
import { useAccount, useWalletClient } from 'wagmi'

import { useAppState } from '../state'
import { MergedTransaction, WithdrawalStatus } from '../state/app/state'
Expand Down Expand Up @@ -30,7 +30,7 @@ export function useClaimWithdrawal(
app: { arbTokenBridge }
} = useAppState()
const { address } = useAccount()
const { data: signer } = useSigner({ chainId: tx.parentChainId })
const { data: signer } = useWalletClient({ chainId: tx.parentChainId })
const { updatePendingTransaction } = useTransactionHistory(address)
const [isClaiming, setIsClaiming] = useState(false)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useNetwork } from 'wagmi'
import { useAccount } from 'wagmi'

import { isNetwork } from '../util/networks'

export function useIsConnectedToArbitrum() {
const { chain } = useNetwork()
const { chain } = useAccount()

if (typeof chain === 'undefined') {
return undefined
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useNetwork } from 'wagmi'
import { useAccount } from 'wagmi'

import { isNetwork } from '../util/networks'

export function useIsConnectedToOrbitChain() {
const { chain } = useNetwork()
const { chain } = useAccount()

if (typeof chain === 'undefined') {
return undefined
Expand Down
2 changes: 1 addition & 1 deletion packages/arb-token-bridge-ui/src/hooks/useNetworks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Chain } from 'wagmi'
import { Chain } from 'viem'
import { StaticJsonRpcProvider } from '@ethersproject/providers'
import { useCallback, useMemo } from 'react'
import { mainnet, arbitrum } from '@wagmi/core/chains'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { StaticJsonRpcProvider } from '@ethersproject/providers'
import { useMemo } from 'react'
import { Chain } from 'wagmi'
import { Chain } from 'viem'
import { UseNetworksState } from './useNetworks'
import { isDepositMode } from '../util/isDepositMode'
import { isTeleport } from '@/token-bridge-sdk/teleport'
Expand Down
4 changes: 2 additions & 2 deletions packages/arb-token-bridge-ui/src/hooks/useRedeemRetryable.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback, useState } from 'react'
import { L1ToL2MessageStatus } from '@arbitrum/sdk'
import { useSigner } from 'wagmi'
import { useWalletClient } from 'wagmi'
import dayjs from 'dayjs'
import { TransactionReceipt } from '@ethersproject/providers'

Expand All @@ -23,7 +23,7 @@ export function useRedeemRetryable(
tx: MergedTransaction,
address: Address | undefined
): UseRedeemRetryableResult {
const { data: signer } = useSigner({ chainId: tx.destinationChainId })
const { data: signer } = useWalletClient({ chainId: tx.destinationChainId })
const { updatePendingTransaction } = useTransactionHistory(address)

const destinationNetworkName = getNetworkName(tx.destinationChainId)
Expand Down
4 changes: 2 additions & 2 deletions packages/arb-token-bridge-ui/src/hooks/useRedeemTeleporter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback, useState } from 'react'
import { Signer } from 'ethers'
import { L1ToL2MessageStatus, L1ToL2MessageWriter } from '@arbitrum/sdk'
import { useSigner } from 'wagmi'
import { useWalletClient } from 'wagmi'
import dayjs from 'dayjs'
import { TransactionReceipt } from '@ethersproject/providers'
import { getProviderForChainId } from '@/token-bridge-sdk/utils'
Expand Down Expand Up @@ -149,7 +149,7 @@ export function useRedeemTeleporter(
): UseRedeemRetryableResult {
const chainIdForRedeemingRetryable = getChainIdForRedeemingRetryable(tx)

const { data: signer } = useSigner({
const { data: signer } = useWalletClient({
chainId: chainIdForRedeemingRetryable
})
const { updatePendingTransaction } = useTransactionHistory(address)
Expand Down
Loading