Skip to content

Commit 126ad8b

Browse files
authored
130 clicking on an asset and/or getting back to list/card view view causes a crash (#131)
* Fix connector prop changing on every page change using memo() Error: The connectors prop passed to Web3ReactProvider must be referentially static. If connectors is changing, try providing a key prop to Web3ReactProvider that changes every time connectors changes. * use contracts addresses as IDs * prettier
1 parent 5620fde commit 126ad8b

File tree

2 files changed

+50
-40
lines changed

2 files changed

+50
-40
lines changed

src/pages/_app.tsx

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect } from 'react'
1+
import { useEffect, useMemo } from 'react'
22
import { QueryClient, QueryClientProvider } from 'react-query'
33
import { Provider } from 'react-redux'
44

@@ -116,45 +116,54 @@ const App = ({
116116

117117
// Customize chains config for Gnosis and Ethereum
118118
// using rpc urls from props
119-
const CustomChainsConfig = {
120-
// Keep Goerli as testnet else an error will arise at init
121-
[ChainsID.Goerli]: RealtCommonsDefaultChainsConfig[ChainsID.Goerli],
122-
[ChainsID.Gnosis]: {
123-
...RealtCommonsDefaultChainsConfig[ChainsID.Gnosis],
124-
rpcUrl:
125-
GnosisRpcUrl || RealtCommonsDefaultChainsConfig[ChainsID.Gnosis].rpcUrl,
126-
},
127-
[ChainsID.Ethereum]: {
128-
...RealtCommonsDefaultChainsConfig[ChainsID.Ethereum],
129-
rpcUrl:
130-
EthereumRpcUrl ||
131-
RealtCommonsDefaultChainsConfig[ChainsID.Ethereum].rpcUrl,
132-
},
133-
// TODO: add Polygon
134-
}
119+
const CustomChainsConfig = useMemo(
120+
() => ({
121+
// Keep Goerli as testnet else an error will arise at init
122+
[ChainsID.Goerli]: RealtCommonsDefaultChainsConfig[ChainsID.Goerli],
123+
[ChainsID.Gnosis]: {
124+
...RealtCommonsDefaultChainsConfig[ChainsID.Gnosis],
125+
rpcUrl:
126+
GnosisRpcUrl ||
127+
RealtCommonsDefaultChainsConfig[ChainsID.Gnosis].rpcUrl,
128+
},
129+
[ChainsID.Ethereum]: {
130+
...RealtCommonsDefaultChainsConfig[ChainsID.Ethereum],
131+
rpcUrl:
132+
EthereumRpcUrl ||
133+
RealtCommonsDefaultChainsConfig[ChainsID.Ethereum].rpcUrl,
134+
},
135+
// TODO: add Polygon
136+
}),
137+
[GnosisRpcUrl, EthereumRpcUrl],
138+
)
135139

136-
const dashbordChains: ChainSelectConfig<RealtChains> = {
137-
allowedChains: parseAllowedChain(ChainsID),
138-
chainsConfig: CustomChainsConfig,
139-
defaultChainId: ChainsID.Gnosis, // Explicitly setting Gnosis as the defaultChainId
140-
}
140+
const dashbordChains: ChainSelectConfig<RealtChains> = useMemo(
141+
() => ({
142+
allowedChains: parseAllowedChain(ChainsID),
143+
chainsConfig: CustomChainsConfig,
144+
defaultChainId: ChainsID.Gnosis, // Explicitly setting Gnosis as the defaultChainId
145+
}),
146+
[CustomChainsConfig],
147+
)
141148

142149
const envName = process.env.NEXT_PUBLIC_ENV ?? 'development'
143150
const walletConnectKey = process.env.NEXT_PUBLIC_WALLET_CONNECT_KEY ?? ''
144151

145-
const readOnly = getReadOnlyConnector(dashbordChains)
146-
const walletConnect = getWalletConnectV2(
147-
dashbordChains,
148-
envName,
149-
walletConnectKey,
150-
false,
151-
)
152-
153-
const libraryConnectors = getConnectors({
154-
readOnly: readOnly,
155-
metamask: [metaMask, metaMaskHooks],
156-
walletConnectV2: walletConnect,
157-
} as unknown as ConnectorsAvailable)
152+
const libraryConnectors = useMemo(() => {
153+
const readOnly = getReadOnlyConnector(dashbordChains)
154+
const walletConnect = getWalletConnectV2(
155+
dashbordChains,
156+
envName,
157+
walletConnectKey,
158+
false,
159+
)
160+
161+
return getConnectors({
162+
readOnly: readOnly,
163+
metamask: [metaMask, metaMaskHooks],
164+
walletConnectV2: walletConnect,
165+
} as unknown as ConnectorsAvailable)
166+
}, [dashbordChains, envName, walletConnectKey])
158167

159168
return (
160169
<QueryClientProvider client={queryClient}>

src/utils/blockchain/consts/otherTokens.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
// Each asset must have a different ID (used as KEY assets view)
2-
const RWA_asset_ID = 0
3-
const REG_asset_ID = 1
4-
const REGVotingPower_asset_ID = 2
5-
61
// Gnosis/xDai, Ethereum
72
const RWA_ContractAddress = '0x0675e8F4A52eA6c845CB6427Af03616a2af42170'
83
// Gnosis/xDai, Ethereum
@@ -14,6 +9,12 @@ const REG_Vault_Gnosis_ContractAddress =
149
const RegVotingPower_Gnosis_ContractAddress =
1510
'0x6382856a731Af535CA6aea8D364FCE67457da438'
1611

12+
// Asset IDs for RWA, REG, and REG Voting Power
13+
// Each asset must have a different ID (used as KEY assets view)
14+
const RWA_asset_ID = RWA_ContractAddress
15+
const REG_asset_ID = REG_ContractAddress
16+
const REGVotingPower_asset_ID = RegVotingPower_Gnosis_ContractAddress
17+
1718
// Gnosis/xDai tokens for prices calculation
1819
const WXDAI_ContractAddress = '0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d'
1920
const USDConXdai_ContractAddress = '0xDDAfbb505ad214D7b80b1f830fcCc89B60fb7A83'

0 commit comments

Comments
 (0)