diff --git a/.changeset/curly-cameras-call.md b/.changeset/curly-cameras-call.md index c07338c9e7..eefd54537b 100644 --- a/.changeset/curly-cameras-call.md +++ b/.changeset/curly-cameras-call.md @@ -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 diff --git a/.changeset/long-bags-shave.md b/.changeset/long-bags-shave.md index aa066a419b..864c725e4e 100644 --- a/.changeset/long-bags-shave.md +++ b/.changeset/long-bags-shave.md @@ -1,5 +1,4 @@ --- -'@reown/appkit-adapter-polkadot': patch '@reown/appkit-adapter-ethers5': patch '@reown/appkit-adapter-ethers': patch '@reown/appkit-adapter-solana': patch diff --git a/.changeset/short-comics-allow.md b/.changeset/short-comics-allow.md new file mode 100644 index 0000000000..f4bb37ae50 --- /dev/null +++ b/.changeset/short-comics-allow.md @@ -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 diff --git a/packages/adapters/ethers/src/client.ts b/packages/adapters/ethers/src/client.ts index 5573605ce1..fd575de361 100644 --- a/packages/adapters/ethers/src/client.ts +++ b/packages/adapters/ethers/src/client.ts @@ -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: '' } diff --git a/packages/adapters/ethers5/src/client.ts b/packages/adapters/ethers5/src/client.ts index 079e557e69..d39dfad30c 100644 --- a/packages/adapters/ethers5/src/client.ts +++ b/packages/adapters/ethers5/src/client.ts @@ -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: '' } diff --git a/packages/appkit-utils/src/ethers/EthersHelpersUtil.ts b/packages/appkit-utils/src/ethers/EthersHelpersUtil.ts index 2949118467..8d0e630e6e 100644 --- a/packages/appkit-utils/src/ethers/EthersHelpersUtil.ts +++ b/packages/appkit-utils/src/ethers/EthersHelpersUtil.ts @@ -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]] } ] diff --git a/packages/core/src/controllers/ChainController.ts b/packages/core/src/controllers/ChainController.ts index b0efb16cce..3c7ada84f4 100644 --- a/packages/core/src/controllers/ChainController.ts +++ b/packages/core/src/controllers/ChainController.ts @@ -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)