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

don't call experimentalSuggestChain() if it's natively supported #475

Merged
merged 4 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
27 changes: 14 additions & 13 deletions packages/core/src/types/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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?: {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions wallets/keplr-extension/src/extension/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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)) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@theothersideofgod make sure chainInfo.name is chain_name

console.warn(
`${chainInfo.name} is already added. No need to call experimentalSuggestChain()`
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this after verifying that it works correctly @theothersideofgod

);
return;
}
}

const suggestChain = chainRegistryChainToKeplr(
chainInfo.chain,
chainInfo.assetList ? [chainInfo.assetList] : []
Expand Down
28 changes: 28 additions & 0 deletions wallets/keplr-extension/src/extension/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,34 @@ export const keplrExtensionInfo: Wallet = {
source: 'Request rejected',
},
connectEventNamesOnWindow: ['keplr_keystorechange'],
supportedChains: [
'agoric',
'akash',
'axelar',
'bostrom',
'certik',
'cosmoshub',
'cryptoorgchain',
'emoney',
'evmos',
'gravitybridge',
'irisnet',
'ixo',
'juno',
'kava',
'osmosis',
'persistence',
'regen',
'secretnetwork',
Copy link
Collaborator Author

@pyramation pyramation Jun 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add any one of these chains to test if it still works, then we've succeeded — using the useChains hook @theothersideofgod

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@theothersideofgod

test

  1. checkout the branch of this PR, in the useChains example in the package
  2. a) add a chain like osmosis that is "supported"
  3. b) add a chain like noise that is not supported

both should work, and provide an address at least, with no errors from cosmos-kit

'sentinel',
'sifchain',
'sommelier',
'stargaze',
'starname',
'stride',
'tgrade',
'umee',
],
downloads: [
{
device: 'desktop',
Expand Down
40 changes: 40 additions & 0 deletions wallets/keplr-mobile/src/wallet-connect/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading