Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(useChains): fix missing endpoints & chain name crash #534

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions packages/core/src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export class WalletManager extends StateBase {
this.isLazy,
this.logger
);

return converted;
});

Expand All @@ -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;
Expand All @@ -154,6 +162,7 @@ export class WalletManager extends StateBase {
this.chainRecords[index] = repo.chainRecord;
}
});

this.checkEndpoints(endpointOptions?.endpoints);
}

Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/utils/convert.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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),
Expand Down
8 changes: 4 additions & 4 deletions packages/react-lite/src/hooks/useChains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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) {
Expand Down