2026-06-02 00:32:46 +08:00
|
|
|
type WalletKind = "tokenPocket" | "metaMask" | "imToken";
|
|
|
|
|
|
|
|
|
|
function currentDappUrl(): string {
|
|
|
|
|
if (typeof window === "undefined") return "https://ark-library.com";
|
|
|
|
|
return window.location.href;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function walletDeepLink(
|
|
|
|
|
kind: WalletKind,
|
|
|
|
|
dappUrl = currentDappUrl(),
|
|
|
|
|
): string {
|
|
|
|
|
switch (kind) {
|
|
|
|
|
case "tokenPocket":
|
|
|
|
|
return `tpdapp://open?params=${encodeURIComponent(
|
2026-06-02 02:58:01 +08:00
|
|
|
JSON.stringify({ url: dappUrl, chain: "BSC" }),
|
2026-06-02 00:32:46 +08:00
|
|
|
)}`;
|
|
|
|
|
case "metaMask":
|
2026-06-02 01:06:55 +08:00
|
|
|
return `https://metamask.app.link/dapp/${encodeURIComponent(
|
|
|
|
|
dappUrl.replace(/^https?:\/\//, ""),
|
|
|
|
|
)}`;
|
2026-06-02 00:32:46 +08:00
|
|
|
case "imToken":
|
|
|
|
|
return `imtokenv2://navigate/DappView?url=${encodeURIComponent(dappUrl)}`;
|
|
|
|
|
default:
|
|
|
|
|
return dappUrl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function openWalletDeepLink(kind: WalletKind): void {
|
|
|
|
|
if (typeof window === "undefined") return;
|
|
|
|
|
window.location.href = walletDeepLink(kind);
|
|
|
|
|
}
|
2026-06-02 03:43:13 +08:00
|
|
|
|
|
|
|
|
const downloadUrls: Record<WalletKind, string> = {
|
|
|
|
|
tokenPocket: "https://www.tokenpocket.pro/en/download/app",
|
|
|
|
|
metaMask: "https://metamask.io/download/",
|
|
|
|
|
imToken: "https://token.im/download",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export function walletDownloadUrl(kind: WalletKind): string {
|
|
|
|
|
return downloadUrls[kind];
|
|
|
|
|
}
|