From 9661e86cd8749552ab34a1e1365985db27867160 Mon Sep 17 00:00:00 2001 From: Aref Eghbali Date: Mon, 20 Jan 2025 14:16:01 +0330 Subject: [PATCH] Fix community chains and issue 515 (#1) --- packages/core/src/manager.ts | 13 +++++++++++-- packages/core/src/utils/convert.ts | 6 +++++- packages/react-lite/src/hooks/useChains.ts | 8 ++++---- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/packages/core/src/manager.ts b/packages/core/src/manager.ts index 4e19ee7d3..7c88a4cfa 100644 --- a/packages/core/src/manager.ts +++ b/packages/core/src/manager.ts @@ -129,6 +129,7 @@ export class WalletManager extends StateBase { this.isLazy, this.logger ); + return converted; }); @@ -142,10 +143,17 @@ export class WalletManager extends StateBase { }); this.chainRecords.forEach((chainRecord, index) => { + const chainWallets = wallets.map( + ({ getChainWallet }) => getChainWallet(chainRecord.name)! + ); + const repo = new WalletRepo( - chainRecord, - wallets.map(({ getChainWallet }) => getChainWallet(chainRecord.name)!) + chainWallets.find( + (prev) => prev.chainName === chainRecord.name + ).chainRecord, + chainWallets ); + repo.logger = this.logger; repo.repelWallet = this.repelWallet; repo.session = this.session; @@ -154,6 +162,7 @@ export class WalletManager extends StateBase { this.chainRecords[index] = repo.chainRecord; } }); + this.checkEndpoints(endpointOptions?.endpoints); } diff --git a/packages/core/src/utils/convert.ts b/packages/core/src/utils/convert.ts index d92f8dff9..47a8eb12e 100644 --- a/packages/core/src/utils/convert.ts +++ b/packages/core/src/utils/convert.ts @@ -1,4 +1,5 @@ import { AssetList, Chain } from '@chain-registry/types'; +import { chains } from 'chain-registry'; import { ChainName, ChainRecord, Endpoints, SignerOptions } from '../types'; import { getIsLazy } from './endpoint'; @@ -26,7 +27,10 @@ export function convertChain( }; const converted = { name: chainName, - chain: typeof chain === 'string' ? void 0 : chain, + chain: + typeof chain === 'string' + ? chains.find((prev) => prev.chain_name === chainName) + : chain, assetList, clientOptions: { stargate: signerOptions?.stargate?.(chain), diff --git a/packages/react-lite/src/hooks/useChains.ts b/packages/react-lite/src/hooks/useChains.ts index 8678d82a6..52da2ab29 100644 --- a/packages/react-lite/src/hooks/useChains.ts +++ b/packages/react-lite/src/hooks/useChains.ts @@ -20,8 +20,8 @@ export function useChains(chainNames: ChainName[], sync = true) { ); } - const repos = names.map(name => walletManager.getWalletRepo(name)); - const ids = repos.map(repo => repo.chainRecord.chain.chain_id); + const repos = names.map((name) => walletManager.getWalletRepo(name)); + const ids = repos.map((repo) => repo.chainRecord.chain.chain_id); return names.reduce((result, chainName, index) => { const walletRepo = repos[index]; @@ -35,11 +35,11 @@ export function useChains(chainNames: ChainName[], sync = true) { await wallet.client?.enable?.(ids); } catch (e) { for (const repo of repos) { - await wallet.client?.addChain?.(repo.chainRecord) + await wallet.client?.addChain?.(repo.chainRecord); } await wallet.client?.enable?.(ids); } - } + }; } if (wallet.isModeWalletConnect) {