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

feat: add imToken wallet #3820

Open
wants to merge 1 commit into
base: stage
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
4 changes: 3 additions & 1 deletion packages/web/config/generate-cosmos-kit-wallet-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import path from "node:path";
import { cdcwalletExtensionInfo } from "@cosmos-kit/cdcwallet-extension";
import { Wallet as DefaultWallet } from "@cosmos-kit/core";
import { cosmostationExtensionInfo } from "@cosmos-kit/cosmostation-extension";
import { imTokenWalletInfo } from "@cosmos-kit/imtoken-extension";
import { keplrExtensionInfo } from "@cosmos-kit/keplr-extension";
import { keplrMobileInfo } from "@cosmos-kit/keplr-mobile";
import { leapExtensionInfo } from "@cosmos-kit/leap-extension";
Expand Down Expand Up @@ -38,6 +39,7 @@ const CosmosKitWalletList: Wallet[] = [
cosmostationExtensionInfo,
stationExtensionInfo,
cdcwalletExtensionInfo,
imTokenWalletInfo,
];

function isObject(value: any): value is Record<any, any> {
Expand Down Expand Up @@ -106,7 +108,7 @@ async function generateCosmosKitWalletList() {
).join(",")}}
export const CosmosKitWalletList: Record<AvailableCosmosWallets, Wallet> = ${getStringifiedWallet(
registryObject
)}
)}
`;

const prettierConfig = await prettier.resolveConfig("./");
Expand Down
28 changes: 22 additions & 6 deletions packages/web/config/wallet-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const CosmosWalletRegistry: CosmosRegistryWallet[] = [
import("~/integrations/keplr-walletconnect").then(
(m) => m.KeplrMobileWallet
),
supportsChain: async (chainId) => {
supportsChain: async (chainId: string) => {
const keplrMobileAvailableChains: MainnetChainIds[] = [
"cosmoshub-4",
"osmosis-1",
Expand Down Expand Up @@ -78,7 +78,7 @@ export const CosmosWalletRegistry: CosmosRegistryWallet[] = [
logo: "/wallets/leap.svg",
lazyInstall: () =>
import("@cosmos-kit/leap-mobile").then((m) => m.LeapMobileWallet),
supportsChain: async (chainId) => {
supportsChain: async (chainId: string) => {
const leapMobileAvailableChains: MainnetChainIds[] = [
"agoric-3",
"akashnet-2",
Expand Down Expand Up @@ -162,7 +162,7 @@ export const CosmosWalletRegistry: CosmosRegistryWallet[] = [
(m) => m.OkxwalletExtensionWallet
),
windowPropertyName: "okxwallet",
async supportsChain(chainId, retryCount = 0) {
async supportsChain(chainId: string, retryCount = 0) {
if (typeof window === "undefined") return true;

const okxWallet = (window as any)?.okxwallet?.keplr as {
Expand Down Expand Up @@ -262,7 +262,7 @@ export const CosmosWalletRegistry: CosmosRegistryWallet[] = [
(m) => m.CdcwalletExtensionWallet
),
mobileDisabled: false,
async supportsChain(chainId) {
async supportsChain(chainId: string) {
const cdcAvailableChains: MainnetChainIds[] = [
"cosmoshub-4",
"osmosis-1",
Expand All @@ -281,7 +281,7 @@ export const CosmosWalletRegistry: CosmosRegistryWallet[] = [
lazyInstall: () =>
import("@cosmos-kit/xdefi-extension").then((m) => m.XDEFIExtensionWallet),
windowPropertyName: "xfi",
async supportsChain(chainId) {
async supportsChain(chainId: string) {
if (typeof window === "undefined") return true;

const xfiWallet = (window as any)?.xfi?.keplr as {
Expand Down Expand Up @@ -318,7 +318,7 @@ export const CosmosWalletRegistry: CosmosRegistryWallet[] = [
(m) => m.StationExtensionWallet
),
windowPropertyName: "station",
supportsChain: async (chainId) => {
supportsChain: async (chainId: string) => {
if (typeof window === "undefined") return true;

const stationWallet = (window as any)?.station?.keplr as {
Expand All @@ -335,4 +335,20 @@ export const CosmosWalletRegistry: CosmosRegistryWallet[] = [
},
features: [],
},
{
...CosmosKitWalletList["imToken"],
logo: "/wallets/imtoken.svg",
mobileDisabled: false,
windowPropertyName: "cosmos",
features: [],
lazyInstall: () =>
import("@cosmos-kit/imtoken-extension").then((m) => m.IMTokenWallet),
async supportsChain(chainId: string) {
const cdcAvailableChains: MainnetChainIds[] = [
"cosmoshub-4",
"osmosis-1",
];
return cdcAvailableChains.includes(chainId as MainnetChainIds);
},
},
];
16 changes: 16 additions & 0 deletions packages/web/modals/wallet-select/use-selectable-wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,22 @@ export const useSelectableWallets = ({
.map((wallet) => ({ ...wallet, mobileDisabled: false }));
}

/**
* If on mobile and `imToken` is in `window`, it means that the user enters
* the frontend from imToken's app in app browser. So, there is no need
* to use wallet connect, as it resembles the extension's usage.
*/
if (
_window?.imToken &&
_window?.cosmos?.mode === mobileWebModeName
) {
return array
.filter(
(wallet) => wallet.name === AvailableCosmosWallets.imToken
)
.map((wallet) => ({ ...wallet, mobileDisabled: false }));
}

/**
* If on mobile and `leap` is in `window`, it means that the user enters
* the frontend from Leap's app in app browser. So, there is no need
Expand Down
1 change: 1 addition & 0 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@cosmos-kit/cdcwallet": "^2.13.2",
"@cosmos-kit/core": "^2.13.1",
"@cosmos-kit/cosmostation": "^2.11.2",
"@cosmos-kit/imtoken": "^1.0.0",
"@cosmos-kit/keplr": "^2.12.2",
"@cosmos-kit/leap": "^2.12.2",
"@cosmos-kit/okxwallet": "^2.9.2",
Expand Down
20 changes: 20 additions & 0 deletions packages/web/public/wallets/imtoken.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2990,6 +2990,21 @@
"@cosmos-kit/cosmostation-extension" "^2.12.2"
"@cosmos-kit/cosmostation-mobile" "^2.11.2"

"@cosmos-kit/imtoken-extension@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@cosmos-kit/imtoken-extension/-/imtoken-extension-1.1.0.tgz#4d1c4ea2a0bd4548969cf4fd58503321230336c4"
integrity sha512-6vNrjVqLXdFcAEFaPCM0uFQjbLMaKymbahk2YW3qN8fUGopdmfDbFuBJj6IKqKEu9uOijmfvUcmKDZIax+gurg==
dependencies:
"@chain-registry/keplr" "1.68.2"
"@cosmos-kit/core" "^2.13.1"

"@cosmos-kit/imtoken@^1.0.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@cosmos-kit/imtoken/-/imtoken-1.1.0.tgz#962e281a783a8fd1647fb9aa437d0fcf0159db46"
integrity sha512-PRN8OzMDbT1j5Zs5HgN34laXUUStZgxMs6cDibd9yOa3BBf0LU74CQQe+ucTLhfydrD8uqXxfsq2jg7YVxAPPg==
dependencies:
"@cosmos-kit/imtoken-extension" "^1.1.0"

"@cosmos-kit/keplr-extension@^2.12.2":
version "2.12.2"
resolved "https://registry.yarnpkg.com/@cosmos-kit/keplr-extension/-/keplr-extension-2.12.2.tgz#d632a1e53eb821b70851ae2aba6c473b4b79dd67"
Expand Down