From 2d4be62235a7af840dfd70701a99aac509e23ace Mon Sep 17 00:00:00 2001 From: Alexander Khramov Date: Tue, 2 Apr 2024 18:35:00 +0300 Subject: [PATCH] feat: add deeplinks for bitkeep, coin98, imtoken, metamask, okx, trust --- packages/wallets/bitkeep/src/index.ts | 4 ++++ packages/wallets/coin98/src/index.ts | 4 +++- packages/wallets/imtoken/src/index.ts | 4 ++++ packages/wallets/metamask/src/index.ts | 6 +++++- packages/wallets/okx/src/index.ts | 9 +++++++++ packages/wallets/trust/src/index.ts | 2 ++ 6 files changed, 27 insertions(+), 2 deletions(-) diff --git a/packages/wallets/bitkeep/src/index.ts b/packages/wallets/bitkeep/src/index.ts index a302fb8c..682a9cb9 100644 --- a/packages/wallets/bitkeep/src/index.ts +++ b/packages/wallets/bitkeep/src/index.ts @@ -15,6 +15,9 @@ declare global { // using previous "bitkeep" name here not to break metrics export const id = 'bitget'; export const name = 'Bitget'; +const currentHref = globalThis.window + ? encodeURIComponent(globalThis.window.location.href) + : ''; export class BitgetConnector extends InjectedConnector { readonly id = id; @@ -37,6 +40,7 @@ export const Bitget: WalletAdapterType = ({ chains }) => ({ downloadURLs: { default: 'https://web3.bitget.com/', }, + deeplink: `https://bkcode.vip?action=dapp&url=${currentHref}`, connector: new BitgetConnector(chains), }); diff --git a/packages/wallets/coin98/src/index.ts b/packages/wallets/coin98/src/index.ts index 0af529c1..100a444a 100644 --- a/packages/wallets/coin98/src/index.ts +++ b/packages/wallets/coin98/src/index.ts @@ -19,6 +19,7 @@ declare global { export const id = 'coin98'; export const name = 'Coin98'; +const currentHost = globalThis.window?.location.host || ''; export class Coin98Connector extends InjectedConnector { readonly id = id; @@ -34,13 +35,14 @@ export class Coin98Connector extends InjectedConnector { } } -export const Coin98: WalletAdapterType = ({ chains }) => ({ +export const Coin98: WalletAdapterType = ({ chains, defaultChain }) => ({ walletName: name, walletId: id, icon: WalletIcon, detector: () => !!globalThis.window?.coin98?.provider || !!globalThis.window?.ethereum?.isCoin98, + deeplink: `https://coin98.com/dapp/${currentHost}/${defaultChain.id}`, downloadURLs: { default: 'https://coin98.com/wallet', ios: 'https://ios.coin98.com', diff --git a/packages/wallets/imtoken/src/index.ts b/packages/wallets/imtoken/src/index.ts index 1caf88f3..81604a2c 100644 --- a/packages/wallets/imtoken/src/index.ts +++ b/packages/wallets/imtoken/src/index.ts @@ -11,6 +11,9 @@ declare module '@wagmi/core' { export const id = 'imToken'; export const name = 'imToken'; +const currentHref = globalThis.window + ? encodeURIComponent(globalThis.window.location.href) + : ''; export class ImTokenConnector extends InjectedConnector { readonly id = id; @@ -30,6 +33,7 @@ export const ImToken: WalletAdapterType = ({ chains }) => ({ walletId: id, icon: WalletIcon, detector: () => !!globalThis.window?.ethereum?.isImToken, + deeplink: `imtokenv2://navigate/DappView?url=${currentHref}`, downloadURLs: { default: 'https://token.im/download', }, diff --git a/packages/wallets/metamask/src/index.ts b/packages/wallets/metamask/src/index.ts index 7f51e2a4..ff194d0b 100644 --- a/packages/wallets/metamask/src/index.ts +++ b/packages/wallets/metamask/src/index.ts @@ -4,6 +4,9 @@ import { WalletIcon, WalletIconInverted } from './icons/index.js'; export const id = 'metamask'; export const name = 'MetaMask'; +const currentHref = globalThis.window + ? globalThis.window.location.hostname + globalThis.window.location.pathname // encoding not supported + : ''; export const MetaMask: WalletAdapterType = ({ chains }) => ({ walletName: name, @@ -14,8 +17,9 @@ export const MetaMask: WalletAdapterType = ({ chains }) => ({ }, detector: () => !!globalThis.window?.ethereum?.isMetaMask, downloadURLs: { - default: 'https://metamask.app.link/dapp/', + default: 'https://metamask.io/download/', }, + deeplink: `https://metamask.app.link/dapp/${currentHref}`, connector: new MetaMaskConnector({ chains, options: { diff --git a/packages/wallets/okx/src/index.ts b/packages/wallets/okx/src/index.ts index 0256ef8f..0854552f 100644 --- a/packages/wallets/okx/src/index.ts +++ b/packages/wallets/okx/src/index.ts @@ -19,6 +19,14 @@ declare global { export const id = 'okx'; export const name = 'OKX Wallet'; +const dappUrl = globalThis.window + ? encodeURIComponent(globalThis.window.location.href) + : ''; +const encodedDappUrl = encodeURIComponent(dappUrl); +const deeplink = 'okx://wallet/dapp/url?dappUrl=' + encodedDappUrl; +const urlWithDeeplinkEncoded = + 'https://www.okx.com/download?deeplink=' + encodeURIComponent(deeplink); + export class OkxConnector extends InjectedConnector { readonly id = id; readonly name = name; @@ -46,5 +54,6 @@ export const Okx: WalletAdapterType = ({ chains }) => ({ downloadURLs: { default: 'https://www.okx.com/download', }, + deeplink: urlWithDeeplinkEncoded, connector: new OkxConnector(chains), }); diff --git a/packages/wallets/trust/src/index.ts b/packages/wallets/trust/src/index.ts index 54be53cd..f01d7419 100644 --- a/packages/wallets/trust/src/index.ts +++ b/packages/wallets/trust/src/index.ts @@ -11,6 +11,7 @@ declare module '@wagmi/core' { export const id = 'trust'; export const name = 'Trust'; +const currentHost = globalThis.window?.location.host || ''; export class TrustConnector extends InjectedConnector { readonly id = id; @@ -33,5 +34,6 @@ export const Trust: WalletAdapterType = ({ chains }) => ({ downloadURLs: { default: 'https://trustwallet.com/browser-extension', }, + deeplink: `https://link.trustwallet.com/open_url?coin_id=60&url=${currentHost}`, connector: new TrustConnector(chains), });