Skip to content

Commit c295f22

Browse files
committed
feat: add imToken wallet
1 parent dea7c21 commit c295f22

File tree

6 files changed

+113
-46
lines changed

6 files changed

+113
-46
lines changed

packages/web/config/generate-cosmos-kit-wallet-list.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import path from "node:path";
55
import { cdcwalletExtensionInfo } from "@cosmos-kit/cdcwallet-extension";
66
import { Wallet as DefaultWallet } from "@cosmos-kit/core";
77
import { cosmostationExtensionInfo } from "@cosmos-kit/cosmostation-extension";
8+
import { imTokenWalletInfo } from "@cosmos-kit/imtoken-extension"
89
import { keplrExtensionInfo } from "@cosmos-kit/keplr-extension";
910
import { keplrMobileInfo } from "@cosmos-kit/keplr-mobile";
1011
import { leapExtensionInfo } from "@cosmos-kit/leap-extension";
@@ -38,6 +39,7 @@ const CosmosKitWalletList: Wallet[] = [
3839
cosmostationExtensionInfo,
3940
stationExtensionInfo,
4041
cdcwalletExtensionInfo,
42+
imTokenWalletInfo,
4143
];
4244

4345
function isObject(value: any): value is Record<any, any> {
@@ -106,7 +108,7 @@ async function generateCosmosKitWalletList() {
106108
).join(",")}}
107109
export const CosmosKitWalletList: Record<AvailableCosmosWallets, Wallet> = ${getStringifiedWallet(
108110
registryObject
109-
)}
111+
)}
110112
`;
111113

112114
const prettierConfig = await prettier.resolveConfig("./");

packages/web/config/wallet-registry.ts

Lines changed: 51 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const CosmosWalletRegistry: CosmosRegistryWallet[] = [
2626
import("~/integrations/keplr-walletconnect").then(
2727
(m) => m.KeplrMobileWallet
2828
),
29-
supportsChain: async (chainId) => {
29+
supportsChain: async (chainId: string) => {
3030
const keplrMobileAvailableChains: MainnetChainIds[] = [
3131
"cosmoshub-4",
3232
"osmosis-1",
@@ -54,9 +54,9 @@ export const CosmosWalletRegistry: CosmosRegistryWallet[] = [
5454
"gitopia",
5555
"likecoin-mainnet-2",
5656
"akashnet-2",
57-
];
57+
]
5858

59-
return keplrMobileAvailableChains.includes(chainId as MainnetChainIds);
59+
return keplrMobileAvailableChains.includes(chainId as MainnetChainIds)
6060
},
6161
stakeUrl: "https://wallet.keplr.app/chains/osmosis?tab=staking",
6262
governanceUrl: "https://wallet.keplr.app/chains/osmosis?tab=governance",
@@ -78,7 +78,7 @@ export const CosmosWalletRegistry: CosmosRegistryWallet[] = [
7878
logo: "/wallets/leap.svg",
7979
lazyInstall: () =>
8080
import("@cosmos-kit/leap-mobile").then((m) => m.LeapMobileWallet),
81-
supportsChain: async (chainId) => {
81+
supportsChain: async (chainId: string) => {
8282
const leapMobileAvailableChains: MainnetChainIds[] = [
8383
"agoric-3",
8484
"akashnet-2",
@@ -146,8 +146,8 @@ export const CosmosWalletRegistry: CosmosRegistryWallet[] = [
146146
"phoenix-1",
147147
"umee-1",
148148
"dimension_37-1",
149-
];
150-
return leapMobileAvailableChains.includes(chainId as MainnetChainIds);
149+
]
150+
return leapMobileAvailableChains.includes(chainId as MainnetChainIds)
151151
},
152152

153153
stakeUrl: "https://cosmos.leapwallet.io/transact/stake/plain?chain=osmosis",
@@ -162,27 +162,27 @@ export const CosmosWalletRegistry: CosmosRegistryWallet[] = [
162162
(m) => m.OkxwalletExtensionWallet
163163
),
164164
windowPropertyName: "okxwallet",
165-
async supportsChain(chainId, retryCount = 0) {
166-
if (typeof window === "undefined") return true;
165+
async supportsChain(chainId: string, retryCount = 0) {
166+
if (typeof window === "undefined") return true
167167

168168
const okxWallet = (window as any)?.okxwallet?.keplr as {
169-
getKey: (chainId: string) => Promise<boolean>;
170-
};
169+
getKey: (chainId: string) => Promise<boolean>
170+
}
171171

172-
if (!okxWallet) return true;
172+
if (!okxWallet) return true
173173

174174
try {
175-
await okxWallet.getKey(chainId);
176-
return true;
175+
await okxWallet.getKey(chainId)
176+
return true
177177
} catch (e) {
178-
const error = e as { code: number; message: string };
178+
const error = e as { code: number; message: string }
179179

180180
// Check for chain not supported error
181181
if (
182182
error.code === -32603 &&
183183
error.message.includes("There is no chain info")
184184
) {
185-
return false;
185+
return false
186186
}
187187

188188
// Retry if the wallet is already processing
@@ -199,26 +199,26 @@ export const CosmosWalletRegistry: CosmosRegistryWallet[] = [
199199
*/
200200
await new Promise((resolve) =>
201201
setTimeout(resolve, Math.pow(2, retryCount) * 100)
202-
);
202+
)
203203
// @ts-ignore
204-
return this.supportsChain(chainId, retryCount + 1);
204+
return this.supportsChain(chainId, retryCount + 1)
205205
}
206206

207-
return false;
207+
return false
208208
}
209209
},
210210
matchError: (error) => {
211-
if (typeof error !== "string") return error;
211+
if (typeof error !== "string") return error
212212

213213
if (
214214
error.includes(
215215
"Already processing wallet_requestIdentities. Please wait."
216216
)
217217
) {
218-
return new WalletConnectionInProgressError();
218+
return new WalletConnectionInProgressError()
219219
}
220220

221-
return error;
221+
return error
222222
},
223223
signOptions: {
224224
preferNoSetFee: true,
@@ -262,13 +262,13 @@ export const CosmosWalletRegistry: CosmosRegistryWallet[] = [
262262
(m) => m.CdcwalletExtensionWallet
263263
),
264264
mobileDisabled: false,
265-
async supportsChain(chainId) {
265+
async supportsChain(chainId: string) {
266266
const cdcAvailableChains: MainnetChainIds[] = [
267267
"cosmoshub-4",
268268
"osmosis-1",
269269
"crypto-org-chain-mainnet-1",
270-
];
271-
return cdcAvailableChains.includes(chainId as MainnetChainIds);
270+
]
271+
return cdcAvailableChains.includes(chainId as MainnetChainIds)
272272
},
273273
windowPropertyName: "cdc_wallet",
274274
stakeUrl: "https://crypto.com/staking",
@@ -281,19 +281,19 @@ export const CosmosWalletRegistry: CosmosRegistryWallet[] = [
281281
lazyInstall: () =>
282282
import("@cosmos-kit/xdefi-extension").then((m) => m.XDEFIExtensionWallet),
283283
windowPropertyName: "xfi",
284-
async supportsChain(chainId) {
285-
if (typeof window === "undefined") return true;
284+
async supportsChain(chainId: string) {
285+
if (typeof window === "undefined") return true
286286

287287
const xfiWallet = (window as any)?.xfi?.keplr as {
288-
getKey: (chainId: string) => Promise<boolean>;
289-
};
288+
getKey: (chainId: string) => Promise<boolean>
289+
}
290290

291-
if (!xfiWallet) return true;
291+
if (!xfiWallet) return true
292292

293293
return xfiWallet
294294
.getKey(chainId)
295295
.then(() => true)
296-
.catch(() => false);
296+
.catch(() => false)
297297
},
298298
features: [],
299299
},
@@ -318,21 +318,34 @@ export const CosmosWalletRegistry: CosmosRegistryWallet[] = [
318318
(m) => m.StationExtensionWallet
319319
),
320320
windowPropertyName: "station",
321-
supportsChain: async (chainId) => {
322-
if (typeof window === "undefined") return true;
321+
supportsChain: async (chainId: string) => {
322+
if (typeof window === "undefined") return true
323323

324324
const stationWallet = (window as any)?.station?.keplr as {
325-
getChainInfosWithoutEndpoints: () => Promise<{ chainId: string }[]>;
326-
};
325+
getChainInfosWithoutEndpoints: () => Promise<{ chainId: string }[]>
326+
}
327327

328-
if (!stationWallet) return true;
328+
if (!stationWallet) return true
329329

330-
const chainInfos = await stationWallet.getChainInfosWithoutEndpoints();
331-
return chainInfos.some((info) => info.chainId === chainId);
330+
const chainInfos = await stationWallet.getChainInfosWithoutEndpoints()
331+
return chainInfos.some((info) => info.chainId === chainId)
332332
},
333333
signOptions: {
334334
preferNoSetFee: true,
335335
},
336336
features: [],
337337
},
338-
];
338+
{
339+
...CosmosKitWalletList["imtoken-extension"],
340+
logo: "/wallets/imtoken.svg",
341+
mobileDisabled: false,
342+
windowPropertyName: "cosmos",
343+
features: [],
344+
lazyInstall: () =>
345+
import("@cosmos-kit/imtoken-extension").then((m) => m.IMTokenWallet),
346+
async supportsChain(chainId: string) {
347+
const cdcAvailableChains: MainnetChainIds[] = ["cosmoshub-4", "osmosis-1"]
348+
return cdcAvailableChains.includes(chainId as MainnetChainIds)
349+
},
350+
},
351+
]

packages/web/modals/wallet-select/use-selectable-wallets.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ export const useSelectableWallets = ({
7979
* Therefore, we should only show that compatible extension wallet.
8080
* */
8181
if (acc.length > 0 && acc[0].name.endsWith("-extension")) {
82-
return acc;
82+
return acc
8383
}
8484

85-
const _window = window as Record<string, any>;
86-
const mobileWebModeName = "mobile-web";
85+
const _window = window as Record<string, any>
86+
const mobileWebModeName = "mobile-web"
8787

8888
/**
8989
* If on mobile and `leap` is in `window`, it means that the user enters
@@ -99,7 +99,23 @@ export const useSelectableWallets = ({
9999
(wallet) =>
100100
wallet.name === AvailableCosmosWallets.CryptocomWallet
101101
)
102-
.map((wallet) => ({ ...wallet, mobileDisabled: false }));
102+
.map((wallet) => ({ ...wallet, mobileDisabled: false }))
103+
}
104+
105+
/**
106+
* If on mobile and `imToken` is in `window`, it means that the user enters
107+
* the frontend from imToken's app in app browser. So, there is no need
108+
* to use wallet connect, as it resembles the extension's usage.
109+
*/
110+
if (
111+
_window?.imToken &&
112+
_window?.cosmos?.mode === mobileWebModeName
113+
) {
114+
return array
115+
.filter(
116+
(wallet) => wallet.name === AvailableCosmosWallets.imToken
117+
)
118+
.map((wallet) => ({ ...wallet, mobileDisabled: false }))
103119
}
104120

105121
/**
@@ -110,7 +126,7 @@ export const useSelectableWallets = ({
110126
if (_window?.leap && _window?.leap?.mode === mobileWebModeName) {
111127
return array
112128
.filter((wallet) => wallet.name === AvailableCosmosWallets.Leap)
113-
.map((wallet) => ({ ...wallet, mobileDisabled: false }));
129+
.map((wallet) => ({ ...wallet, mobileDisabled: false }))
114130
}
115131

116132
/**
@@ -123,13 +139,13 @@ export const useSelectableWallets = ({
123139
.filter(
124140
(wallet) => wallet.name === AvailableCosmosWallets.Keplr
125141
)
126-
.map((wallet) => ({ ...wallet, mobileDisabled: false }));
142+
.map((wallet) => ({ ...wallet, mobileDisabled: false }))
127143
}
128144

129145
/**
130146
* If user is in a normal mobile browser, show only wallet connect
131147
*/
132-
return wallet.name.endsWith("mobile") ? [...acc, wallet] : acc;
148+
return wallet.name.endsWith("mobile") ? [...acc, wallet] : acc
133149
}
134150

135151
return [...acc, wallet];

packages/web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"@cosmos-kit/keplr": "^2.12.2",
3939
"@cosmos-kit/leap": "^2.12.2",
4040
"@cosmos-kit/okxwallet": "^2.9.2",
41+
"@cosmos-kit/imtoken": "^1.0.0",
4142
"@cosmos-kit/station": "^2.10.2",
4243
"@cosmos-kit/trust": "^2.11.2",
4344
"@cosmos-kit/xdefi": "^2.10.2",
Lines changed: 20 additions & 0 deletions
Loading

yarn.lock

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2941,6 +2941,21 @@
29412941
"@cosmos-kit/cosmostation-extension" "^2.12.2"
29422942
"@cosmos-kit/cosmostation-mobile" "^2.11.2"
29432943

2944+
"@cosmos-kit/imtoken-extension@^1.1.0":
2945+
version "1.1.0"
2946+
resolved "https://registry.yarnpkg.com/@cosmos-kit/imtoken-extension/-/imtoken-extension-1.1.0.tgz#4d1c4ea2a0bd4548969cf4fd58503321230336c4"
2947+
integrity sha512-6vNrjVqLXdFcAEFaPCM0uFQjbLMaKymbahk2YW3qN8fUGopdmfDbFuBJj6IKqKEu9uOijmfvUcmKDZIax+gurg==
2948+
dependencies:
2949+
"@chain-registry/keplr" "1.68.2"
2950+
"@cosmos-kit/core" "^2.13.1"
2951+
2952+
"@cosmos-kit/imtoken@^1.0.0":
2953+
version "1.1.0"
2954+
resolved "https://registry.yarnpkg.com/@cosmos-kit/imtoken/-/imtoken-1.1.0.tgz#962e281a783a8fd1647fb9aa437d0fcf0159db46"
2955+
integrity sha512-PRN8OzMDbT1j5Zs5HgN34laXUUStZgxMs6cDibd9yOa3BBf0LU74CQQe+ucTLhfydrD8uqXxfsq2jg7YVxAPPg==
2956+
dependencies:
2957+
"@cosmos-kit/imtoken-extension" "^1.1.0"
2958+
29442959
"@cosmos-kit/keplr-extension@^2.12.2":
29452960
version "2.12.2"
29462961
resolved "https://registry.yarnpkg.com/@cosmos-kit/keplr-extension/-/keplr-extension-2.12.2.tgz#d632a1e53eb821b70851ae2aba6c473b4b79dd67"

0 commit comments

Comments
 (0)