Skip to content

Commit

Permalink
:fix fix an issue where adding chains in ethers doesn't work (#3355)
Browse files Browse the repository at this point in the history
  • Loading branch information
svenvoskamp authored Nov 29, 2024
1 parent 824f1df commit 2c87bc5
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 14 deletions.
1 change: 0 additions & 1 deletion .changeset/curly-cameras-call.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
'@reown/appkit-siwe': patch
'@reown/appkit-adapter-ethers': patch
'@reown/appkit-adapter-ethers5': patch
'@reown/appkit-adapter-polkadot': patch
'@reown/appkit-adapter-solana': patch
'@reown/appkit-adapter-wagmi': patch
'@reown/appkit': patch
Expand Down
1 change: 0 additions & 1 deletion .changeset/long-bags-shave.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
'@reown/appkit-adapter-polkadot': patch
'@reown/appkit-adapter-ethers5': patch
'@reown/appkit-adapter-ethers': patch
'@reown/appkit-adapter-solana': patch
Expand Down
20 changes: 20 additions & 0 deletions .changeset/short-comics-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
'@reown/appkit-adapter-ethers5': patch
'@reown/appkit-adapter-ethers': patch
'@reown/appkit-utils': patch
'@reown/appkit-core': patch
'@reown/appkit-adapter-solana': patch
'@reown/appkit-adapter-wagmi': patch
'@reown/appkit': patch
'@reown/appkit-cdn': patch
'@reown/appkit-common': patch
'@reown/appkit-experimental': patch
'@reown/appkit-polyfills': patch
'@reown/appkit-scaffold-ui': patch
'@reown/appkit-siwe': patch
'@reown/appkit-siwx': patch
'@reown/appkit-ui': patch
'@reown/appkit-wallet': patch
---

Fix a case where adding chains on ethers doesn't work
14 changes: 10 additions & 4 deletions packages/adapters/ethers/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,16 @@ export class EthersAdapter extends AdapterBlueprint {
name: caipNetwork.name
})

const balance = await jsonRpcProvider.getBalance(params.address)
const formattedBalance = formatEther(balance)

return { balance: formattedBalance, symbol: caipNetwork.nativeCurrency.symbol }
if (jsonRpcProvider) {
try {
const balance = await jsonRpcProvider.getBalance(params.address)
const formattedBalance = formatEther(balance)

return { balance: formattedBalance, symbol: caipNetwork.nativeCurrency.symbol }
} catch (error) {
return { balance: '', symbol: '' }
}
}
}

return { balance: '', symbol: '' }
Expand Down
14 changes: 10 additions & 4 deletions packages/adapters/ethers5/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,16 @@ export class Ethers5Adapter extends AdapterBlueprint {
}
)

const balance = await jsonRpcProvider.getBalance(params.address)
const formattedBalance = formatEther(balance)

return { balance: formattedBalance, symbol: caipNetwork.nativeCurrency.symbol }
if (jsonRpcProvider) {
try {
const balance = await jsonRpcProvider.getBalance(params.address)
const formattedBalance = formatEther(balance)

return { balance: formattedBalance, symbol: caipNetwork.nativeCurrency.symbol }
} catch (error) {
return { balance: '', symbol: '' }
}
}
}

return { balance: '', symbol: '' }
Expand Down
10 changes: 7 additions & 3 deletions packages/appkit-utils/src/ethers/EthersHelpersUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@ export const EthersHelpersUtil = {
params: [
{
chainId: EthersHelpersUtil.numberToHexString(caipNetwork.id),
rpcUrls: caipNetwork.rpcUrls.default.http,
rpcUrls: [caipNetwork.rpcUrls.default.http[0]],
chainName: caipNetwork.name,
nativeCurrency: caipNetwork.nativeCurrency,
blockExplorerUrls: caipNetwork.blockExplorers,
nativeCurrency: {
name: caipNetwork.nativeCurrency.name,
decimals: caipNetwork.nativeCurrency.decimals,
symbol: caipNetwork.nativeCurrency.symbol
},
blockExplorerUrls: [caipNetwork.blockExplorers?.default.url],
iconUrls: [PresetsUtil.NetworkImageIds[caipNetwork.id]]
}
]
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/controllers/ChainController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export const ChainController = {
)

const unsupportedNetwork = !activeAdapter?.caipNetworks?.some(
caipNetwork => caipNetwork.id === network.id
caipNetwork => caipNetwork.id === state.activeCaipNetwork?.id
)
const networkControllerClient = this.getNetworkControllerClient(network.chainNamespace)

Expand Down

0 comments on commit 2c87bc5

Please sign in to comment.