From 90b3184b17480131f562caf2b2f562e1dd13a7e4 Mon Sep 17 00:00:00 2001 From: Dan Lynch Date: Mon, 17 Jun 2024 22:22:22 -0700 Subject: [PATCH] don't call experiementalSuggestChain() if it's natively supported already. No need to register. --- packages/core/src/types/wallet.ts | 27 +++++++------ .../mock-extension/extension/client.ts | 2 +- .../keplr-extension/src/extension/client.ts | 16 ++++++++ .../keplr-extension/src/extension/registry.ts | 28 +++++++++++++ .../src/wallet-connect/registry.ts | 40 +++++++++++++++++++ 5 files changed, 99 insertions(+), 14 deletions(-) diff --git a/packages/core/src/types/wallet.ts b/packages/core/src/types/wallet.ts index f20941600..b2c7a915c 100644 --- a/packages/core/src/types/wallet.ts +++ b/packages/core/src/types/wallet.ts @@ -64,13 +64,13 @@ export interface Metadata { export interface AppUrl { native?: - | string - | { - android?: string; - ios?: string; - macos?: string; - windows?: string; - }; + | string + | { + android?: string; + ios?: string; + macos?: string; + windows?: string; + }; universal?: string; } @@ -82,14 +82,15 @@ export interface Wallet { mobileDisabled: boolean | (() => boolean); description?: string; rejectMessage?: - | { - source: string; // message from wallet app - target?: string; // message stored in walletManager, default 'Request Rejected!' - } - | string; // message from wallet app + | { + source: string; // message from wallet app + target?: string; // message stored in walletManager, default 'Request Rejected!' + } + | string; // message from wallet app rejectCode?: number; // code from wallet app connectEventNamesOnWindow?: string[]; connectEventNamesOnClient?: string[]; + supportedChains?: string[]; // array of supported chains downloads?: DownloadInfo[]; logo?: string | { major: string; minor: string }; walletconnect?: { @@ -244,7 +245,7 @@ export interface WalletClient { export type WalletAdapter = ChainWalletBase | MainWalletBase; export interface IChainWallet { - new (walletInfo: Wallet, chainInfo: ChainRecord): ChainWalletBase; + new(walletInfo: Wallet, chainInfo: ChainRecord): ChainWalletBase; } export type NameServiceName = string; diff --git a/packages/core/test-utils/mock-extension/extension/client.ts b/packages/core/test-utils/mock-extension/extension/client.ts index 21a47e3af..5892b757b 100644 --- a/packages/core/test-utils/mock-extension/extension/client.ts +++ b/packages/core/test-utils/mock-extension/extension/client.ts @@ -11,8 +11,8 @@ import { } from '@cosmos-kit/core'; import Long from 'long'; -import { Mock } from './types'; import { DirectSignDoc, WalletClient } from '../../../src/types'; +import { Mock } from './types'; export class MockClient implements WalletClient { readonly client: Mock; diff --git a/wallets/keplr-extension/src/extension/client.ts b/wallets/keplr-extension/src/extension/client.ts index a21225949..0e4a620ca 100644 --- a/wallets/keplr-extension/src/extension/client.ts +++ b/wallets/keplr-extension/src/extension/client.ts @@ -14,6 +14,8 @@ import { import { BroadcastMode, Keplr } from '@keplr-wallet/types'; import Long from 'long'; +import { keplrExtensionInfo } from './registry'; + export class KeplrClient implements WalletClient { readonly client: Keplr; private _defaultSignOptions: SignOptions = { @@ -121,6 +123,20 @@ export class KeplrClient implements WalletClient { } async addChain(chainInfo: ChainRecord) { + // TODO later allow walletInfo getter to be available here + // make this more generic + if ( + keplrExtensionInfo.supportedChains && + keplrExtensionInfo.supportedChains.length + ) { + if (keplrExtensionInfo.supportedChains.includes(chainInfo.name)) { + console.warn( + `${chainInfo.name} is already added. No need to call experimentalSuggestChain()` + ); + return; + } + } + const suggestChain = chainRegistryChainToKeplr( chainInfo.chain, chainInfo.assetList ? [chainInfo.assetList] : [] diff --git a/wallets/keplr-extension/src/extension/registry.ts b/wallets/keplr-extension/src/extension/registry.ts index 45ec2f089..c14238e28 100644 --- a/wallets/keplr-extension/src/extension/registry.ts +++ b/wallets/keplr-extension/src/extension/registry.ts @@ -22,6 +22,34 @@ export const keplrExtensionInfo: Wallet = { source: 'Request rejected', }, connectEventNamesOnWindow: ['keplr_keystorechange'], + supportedChains: [ + 'cosmoshub', + 'osmosis', + 'secretnetwork', + 'regen', + 'akash', + 'sifchain', + 'stargaze', + 'sentinel', + 'persistence', + 'kava', + 'cryptoorgchain', + 'irisnet', + 'agoric', + 'axelar', + 'certik', + 'ixo', + 'emoney', + 'juno', + 'sommelier', + 'umee', + 'evmos', + 'bostrom', + 'starname', + 'gravitybridge', + 'stride', + 'tgrade', + ], downloads: [ { device: 'desktop', diff --git a/wallets/keplr-mobile/src/wallet-connect/registry.ts b/wallets/keplr-mobile/src/wallet-connect/registry.ts index dde7295ff..a81d38f4e 100644 --- a/wallets/keplr-mobile/src/wallet-connect/registry.ts +++ b/wallets/keplr-mobile/src/wallet-connect/registry.ts @@ -27,6 +27,46 @@ export const keplrMobileInfo: Wallet = { }, ], connectEventNamesOnWindow: ['keplr_keystorechange'], + supportedChains: [ + 'agoric', + 'akash', + 'axelar', + 'bitcanna', + 'bitsong', + 'bostrom', + 'certik', + 'cheqd', + 'chihuahua', + 'comdex', + 'cosmoshub', + 'cryptoorgchain', + 'desmos', + 'dig', + 'emoney', + 'evmos', + 'gravitybridge', + 'injective', + 'irisnet', + 'ixo', + 'juno', + 'ki', + 'likecoin', + 'lumnetwork', + 'osmosis', + 'panacea', + 'persistence', + 'regen', + 'secretnetwork', + 'sentinel', + 'sifchain', + 'sommelier', + 'stargaze', + 'starname', + 'terra', + 'tick', + 'umee', + 'vidulum', + ], walletconnect: { name: 'Keplr', projectId: