From 505b9aa93b81c55b6b09e03ef223aadc70f08391 Mon Sep 17 00:00:00 2001 From: Fionna <13184582+fionnachan@users.noreply.github.com> Date: Tue, 24 Sep 2024 10:53:42 +0100 Subject: [PATCH 1/2] make rendering work --- .../src/util/chainQueryParamUtils.ts | 2 +- .../src/util/wagmi/getWagmiChain.ts | 3 +- .../src/util/wagmi/setup.ts | 83 +++++++++++-------- 3 files changed, 50 insertions(+), 38 deletions(-) diff --git a/packages/arb-token-bridge-ui/src/util/chainQueryParamUtils.ts b/packages/arb-token-bridge-ui/src/util/chainQueryParamUtils.ts index f8b5ee0458..c6e60dd145 100644 --- a/packages/arb-token-bridge-ui/src/util/chainQueryParamUtils.ts +++ b/packages/arb-token-bridge-ui/src/util/chainQueryParamUtils.ts @@ -7,7 +7,7 @@ import { localL1Network, localL2Network, localL3Network -} from '../util/wagmi/wagmiAdditionalNetworks' +} from './wagmi/wagmiAdditionalNetworks' import { ChainKeyQueryParam } from '../types/ChainQueryParam' import { getOrbitChains } from './orbitChainsList' import { chainToWagmiChain } from '../util/wagmi/wagmiAdditionalNetworks' diff --git a/packages/arb-token-bridge-ui/src/util/wagmi/getWagmiChain.ts b/packages/arb-token-bridge-ui/src/util/wagmi/getWagmiChain.ts index bd6774c656..5993766cb7 100644 --- a/packages/arb-token-bridge-ui/src/util/wagmi/getWagmiChain.ts +++ b/packages/arb-token-bridge-ui/src/util/wagmi/getWagmiChain.ts @@ -11,8 +11,7 @@ import { localL2Network, localL3Network } from './wagmiAdditionalNetworks' -import { ChainId } from '../networks' -import { getCustomChainFromLocalStorageById } from '../networks' +import { ChainId, getCustomChainFromLocalStorageById } from '../networks' import { orbitChains } from '../orbitChainsList' export function getWagmiChain(chainId: number): Chain { diff --git a/packages/arb-token-bridge-ui/src/util/wagmi/setup.ts b/packages/arb-token-bridge-ui/src/util/wagmi/setup.ts index 0023574b53..14f90def46 100644 --- a/packages/arb-token-bridge-ui/src/util/wagmi/setup.ts +++ b/packages/arb-token-bridge-ui/src/util/wagmi/setup.ts @@ -1,6 +1,7 @@ import { createClient, configureChains } from 'wagmi' import { mainnet, arbitrum } from '@wagmi/core/chains' import { publicProvider } from 'wagmi/providers/public' +import { jsonRpcProvider } from 'wagmi/providers/jsonRpc' import { connectorsForWallets, getDefaultWallets } from '@rainbow-me/rainbowkit' import { trustWallet, okxWallet } from '@rainbow-me/rainbowkit/wallets' @@ -14,7 +15,7 @@ import { holesky } from './wagmiAdditionalNetworks' import { isTestingEnvironment } from '../CommonUtils' -import { getCustomChainsFromLocalStorage, ChainId } from '../networks' +import { getCustomChainsFromLocalStorage, ChainId, rpcURLs } from '../networks' import { getOrbitChains } from '../orbitChainsList' import { getWagmiChain } from './getWagmiChain' import { customInfuraProvider } from '../infura' @@ -119,43 +120,55 @@ function getChains(targetChainKey: TargetChainKey) { } export function getProps(targetChainKey: string | null) { - const { chains, provider } = configureChains( - // Wagmi selects the first chain as the one to target in WalletConnect, so it has to be the first in the array. - // - // https://github.com/wagmi-dev/references/blob/main/packages/connectors/src/walletConnect.ts#L114 - getChains(sanitizeTargetChainKey(targetChainKey)), - [customInfuraProvider(), publicProvider()] - ) - - const { wallets } = getDefaultWallets({ - ...appInfo, - chains - }) - - const connectors = connectorsForWallets([ - ...wallets, - { - groupName: 'More', - wallets: [ - trustWallet({ chains, projectId }), - okxWallet({ chains, projectId }) + try { + const { chains, provider } = configureChains( + // Wagmi selects the first chain as the one to target in WalletConnect, so it has to be the first in the array. + // + // https://github.com/wagmi-dev/references/blob/main/packages/connectors/src/walletConnect.ts#L114 + getChains(sanitizeTargetChainKey(targetChainKey)), + [ + customInfuraProvider(), + publicProvider(), + jsonRpcProvider({ + rpc: chain => ({ + http: rpcURLs[chain.id]! + }) + }) ] - } - ]) - - const client = createClient({ - autoConnect: true, - connectors, - provider - }) + ) - return { - rainbowKitProviderProps: { - appInfo, + const { wallets } = getDefaultWallets({ + ...appInfo, chains - }, - wagmiConfigProps: { - client + }) + + const connectors = connectorsForWallets([ + ...wallets, + { + groupName: 'More', + wallets: [ + trustWallet({ chains, projectId }), + okxWallet({ chains, projectId }) + ] + } + ]) + + const client = createClient({ + autoConnect: true, + connectors, + provider + }) + + return { + rainbowKitProviderProps: { + appInfo, + chains + }, + wagmiConfigProps: { + client + } } + } catch (e) { + console.log('ERROR: ', e) } } From aebca22867556cf06f28e10de06729cd37196384 Mon Sep 17 00:00:00 2001 From: Fionna <13184582+fionnachan@users.noreply.github.com> Date: Tue, 24 Sep 2024 10:59:00 +0100 Subject: [PATCH 2/2] remove try catch --- .../src/util/wagmi/setup.ts | 86 +++++++++---------- 1 file changed, 41 insertions(+), 45 deletions(-) diff --git a/packages/arb-token-bridge-ui/src/util/wagmi/setup.ts b/packages/arb-token-bridge-ui/src/util/wagmi/setup.ts index 14f90def46..b4406b4187 100644 --- a/packages/arb-token-bridge-ui/src/util/wagmi/setup.ts +++ b/packages/arb-token-bridge-ui/src/util/wagmi/setup.ts @@ -120,55 +120,51 @@ function getChains(targetChainKey: TargetChainKey) { } export function getProps(targetChainKey: string | null) { - try { - const { chains, provider } = configureChains( - // Wagmi selects the first chain as the one to target in WalletConnect, so it has to be the first in the array. - // - // https://github.com/wagmi-dev/references/blob/main/packages/connectors/src/walletConnect.ts#L114 - getChains(sanitizeTargetChainKey(targetChainKey)), - [ - customInfuraProvider(), - publicProvider(), - jsonRpcProvider({ - rpc: chain => ({ - http: rpcURLs[chain.id]! - }) + const { chains, provider } = configureChains( + // Wagmi selects the first chain as the one to target in WalletConnect, so it has to be the first in the array. + // + // https://github.com/wagmi-dev/references/blob/main/packages/connectors/src/walletConnect.ts#L114 + getChains(sanitizeTargetChainKey(targetChainKey)), + [ + customInfuraProvider(), + publicProvider(), + jsonRpcProvider({ + rpc: chain => ({ + http: rpcURLs[chain.id]! }) + }) + ] + ) + + const { wallets } = getDefaultWallets({ + ...appInfo, + chains + }) + + const connectors = connectorsForWallets([ + ...wallets, + { + groupName: 'More', + wallets: [ + trustWallet({ chains, projectId }), + okxWallet({ chains, projectId }) ] - ) + } + ]) + + const client = createClient({ + autoConnect: true, + connectors, + provider + }) - const { wallets } = getDefaultWallets({ - ...appInfo, + return { + rainbowKitProviderProps: { + appInfo, chains - }) - - const connectors = connectorsForWallets([ - ...wallets, - { - groupName: 'More', - wallets: [ - trustWallet({ chains, projectId }), - okxWallet({ chains, projectId }) - ] - } - ]) - - const client = createClient({ - autoConnect: true, - connectors, - provider - }) - - return { - rainbowKitProviderProps: { - appInfo, - chains - }, - wagmiConfigProps: { - client - } + }, + wagmiConfigProps: { + client } - } catch (e) { - console.log('ERROR: ', e) } }