@tomo-inc/wallet-adaptor-base 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/index.cjs +331 -48
  2. package/dist/index.d.cts +23 -3
  3. package/dist/index.d.ts +23 -3
  4. package/dist/index.js +331 -50
  5. package/package.json +2 -1
  6. package/src/index.ts +3 -0
  7. package/src/type.ts +5 -0
  8. package/src/utils/browsers.ts +13 -0
  9. package/src/utils/chainId.ts +1 -1
  10. package/src/wallet-api/chain.ts +9 -2
  11. package/src/wallet-api/connect.ts +83 -20
  12. package/src/wallet-api/sign-in.ts +4 -1
  13. package/src/wallet-api/sign-message.ts +38 -5
  14. package/src/wallets/Wallet.ts +4 -0
  15. package/src/wallets/default/binanceWallet/binanceWallet.ts +27 -0
  16. package/src/wallets/default/bitgetWallet/bitgetWallet.ts +10 -0
  17. package/src/wallets/default/bitverseWallet/bitverseWallet.ts +3 -0
  18. package/src/wallets/default/bybitWallet/bybitWallet.ts +5 -0
  19. package/src/wallets/default/coinbaseWallet/coinbaseWallet.ts +7 -0
  20. package/src/wallets/default/foxWallet/foxWallet.ts +5 -0
  21. package/src/wallets/default/gateWallet/gateWallet.ts +6 -0
  22. package/src/wallets/default/imTokenWallet/imTokenWallet.ts +9 -0
  23. package/src/wallets/default/iopayWallet/iopayWallet.ts +6 -0
  24. package/src/wallets/default/kaiaWallet/kaiaWallet.ts +5 -0
  25. package/src/wallets/default/kaikasWallet/kaikasWallet.ts +5 -0
  26. package/src/wallets/default/krakenWallet/krakenWallet.ts +5 -0
  27. package/src/wallets/default/kresusWallet/kresusWallet.ts +3 -0
  28. package/src/wallets/default/ledgerWallet/ledgerWallet.ts +6 -0
  29. package/src/wallets/default/metaMaskWallet/metaMaskWallet.ts +17 -0
  30. package/src/wallets/default/oktoWallet/oktoWallet.ts +6 -0
  31. package/src/wallets/default/okxWallet/okxWallet.ts +11 -0
  32. package/src/wallets/default/omniWallet/omniWallet.ts +6 -0
  33. package/src/wallets/default/oneInchWallet/oneInchWallet.ts +3 -0
  34. package/src/wallets/default/paraSwapWallet/paraswapWallet.ts +5 -0
  35. package/src/wallets/default/phantomWallet/phantomWallet.ts +7 -0
  36. package/src/wallets/default/rainbowWallet/rainbowWallet.ts +10 -0
  37. package/src/wallets/default/solflareWallet/solflareWallet.ts +7 -0
  38. package/src/wallets/default/tokenPocketWallet/tokenPocketWallet.ts +6 -0
  39. package/src/wallets/default/trustWallet/trustWallet.ts +6 -0
  40. package/src/wallets/default/uniswapWallet/uniswapWallet.ts +5 -0
  41. package/src/wallets/default/valoraWallet/valoraWallet.ts +4 -0
  42. package/src/wallets/default/zealWallet/zealWallet.ts +5 -0
  43. package/src/wallets/default/zerionWallet/zerionWallet.ts +6 -0
  44. package/src/wallets/detector.ts +32 -16
  45. package/src/wallets/providers/WalletConnectProvider.ts +3 -2
  46. package/src/wallets/wallet-walletconnect.ts +1 -1
@@ -19,5 +19,12 @@ export const solflareWallet = (): WalletConfig => {
19
19
  mobile: "https://solflare.com/",
20
20
  qrCode: "https://solflare.com/",
21
21
  },
22
+ mobile: {
23
+ getDeeplink: (dappUrl?: string): string => {
24
+ if (!dappUrl) return "";
25
+ const encodedDappUrl = encodeURIComponent(dappUrl);
26
+ return `https://solflare.com/ul/v1/browse/${encodedDappUrl}?ref=${encodedDappUrl}`;
27
+ },
28
+ },
22
29
  };
23
30
  };
@@ -20,5 +20,11 @@ export const tokenPocketWallet = (): WalletConfig => {
20
20
  qrCode: "https://tokenpocket.pro/en/download/app",
21
21
  mobile: "https://tokenpocket.pro/en/download/app",
22
22
  },
23
+ mobile: {
24
+ getDeeplink: (dappUrl?: string): string => {
25
+ if (!dappUrl) return "";
26
+ return `tpdapp://open?params={"url":"${dappUrl}"}`;
27
+ },
28
+ },
23
29
  };
24
30
  };
@@ -19,5 +19,11 @@ export const trustWallet = (): WalletConfig => {
19
19
  chrome: "https://chrome.google.com/webstore/detail/trust-wallet/egjidjbpglichdcondbcbdnbeeppgdph",
20
20
  browserExtension: "https://trustwallet.com/browser-extension",
21
21
  },
22
+ mobile: {
23
+ getDeeplink: (dappUrl?: string): string => {
24
+ if (!dappUrl) return "";
25
+ return `https://link.trustwallet.com/open_url?coin_id=60&url=${dappUrl}`;
26
+ },
27
+ },
22
28
  };
23
29
  };
@@ -12,4 +12,9 @@ export const uniswapWallet = (): WalletConfig => ({
12
12
  mobile: "https://wallet.uniswap.org/",
13
13
  qrCode: "https://wallet.uniswap.org/",
14
14
  },
15
+ mobile: {
16
+ getUri: (uri: string) => {
17
+ return `uniswap://wc?uri=${encodeURIComponent(uri)}`;
18
+ },
19
+ },
15
20
  });
@@ -1,4 +1,5 @@
1
1
  import type { WalletConfig } from "../../Wallet";
2
+ import { isAndroid } from "../../../utils/isMobile";
2
3
  import icon from "./valoraWallet.svg";
3
4
 
4
5
  export const valoraWallet = (): WalletConfig => ({
@@ -13,4 +14,7 @@ export const valoraWallet = (): WalletConfig => ({
13
14
  mobile: "https://valora.xyz",
14
15
  qrCode: "https://valora.xyz",
15
16
  },
17
+ mobile: {
18
+ getUri: (uri: string) => (isAndroid() ? uri : `celo://wallet/wc?uri=${encodeURIComponent(uri)}`),
19
+ },
16
20
  });
@@ -19,5 +19,10 @@ export const zealWallet = (): WalletConfig => {
19
19
  mobile: "https://zeal.app",
20
20
  qrCode: "https://zeal.app",
21
21
  },
22
+ mobile: {
23
+ getUri: (uri: string) => {
24
+ return `zeal://wc?uri=${encodeURIComponent(uri)}`;
25
+ },
26
+ },
22
27
  };
23
28
  };
@@ -1,4 +1,5 @@
1
1
  import type { WalletConfig } from "../../Wallet";
2
+ import { isIOS } from "../../../utils/isMobile";
2
3
  import icon from "./zerionWallet.svg";
3
4
 
4
5
  export const zerionWallet = (): WalletConfig => {
@@ -18,5 +19,10 @@ export const zerionWallet = (): WalletConfig => {
18
19
  chrome: "https://chrome.google.com/webstore/detail/klghhnkeealcohjjanjjdaeeggmfmlpl",
19
20
  browserExtension: "https://zerion.io/extension",
20
21
  },
22
+ mobile: {
23
+ getUri: (uri: string) => {
24
+ return isIOS() ? `zerion://wc?uri=${encodeURIComponent(uri)}` : uri;
25
+ },
26
+ },
21
27
  };
22
28
  };
@@ -1,5 +1,5 @@
1
- import { WagmiWalletConfig, WalletConfig } from "./Wallet";
2
1
  import { Connector, ProviderProtocol, WalletConnectorType } from "../type";
2
+ import { WagmiWalletConfig, WalletConfig } from "./Wallet";
3
3
 
4
4
  type WalletProviderFlags = string;
5
5
  type WindowProvider = any;
@@ -98,23 +98,38 @@ export function connectorDector(wallet: WalletConfig): Connector {
98
98
  const isInstalled = isEvmExists || isSolanaExists || isAptosExists;
99
99
 
100
100
  const providers: any = {};
101
- if (isEvmExists) {
102
- providers.evm = {
103
- provider: getInjectedProvider(evmNS),
104
- protocol: ProviderProtocol.EIP6963,
105
- };
101
+ if (evmNS.namespace || evmNS.flag) {
102
+ providers.evm = isEvmExists
103
+ ? {
104
+ provider: getInjectedProvider(evmNS),
105
+ protocol: ProviderProtocol.EIP6963,
106
+ }
107
+ : {
108
+ provider: undefined,
109
+ protocol: undefined,
110
+ };
106
111
  }
107
- if (isSolanaExists) {
108
- providers.solana = {
109
- provider: getInjectedProvider(solanaNS),
110
- protocol: ProviderProtocol.INJECT,
111
- };
112
+ if (solanaNS.namespace) {
113
+ providers.solana = isSolanaExists
114
+ ? {
115
+ provider: getInjectedProvider(solanaNS),
116
+ protocol: ProviderProtocol.INJECT,
117
+ }
118
+ : {
119
+ provider: undefined,
120
+ protocol: undefined,
121
+ };
112
122
  }
113
- if (isAptosExists) {
114
- providers.aptos = {
115
- provider: getInjectedProvider(aptosNS),
116
- protocol: ProviderProtocol.INJECT,
117
- };
123
+ if (aptosNS.namespace) {
124
+ providers.aptos = isAptosExists
125
+ ? {
126
+ provider: getInjectedProvider(aptosNS),
127
+ protocol: ProviderProtocol.INJECT,
128
+ }
129
+ : {
130
+ provider: undefined,
131
+ protocol: undefined,
132
+ };
118
133
  }
119
134
  return {
120
135
  info: {
@@ -124,6 +139,7 @@ export function connectorDector(wallet: WalletConfig): Connector {
124
139
  iconBackground: wallet?.iconBackground,
125
140
  rdns: wallet?.rdns,
126
141
  deeplink: wallet?.deeplink,
142
+ mobile: wallet?.mobile,
127
143
  links: {
128
144
  homepage: wallet?.downloadUrls?.qrCode || "",
129
145
  ios_install: wallet?.downloadUrls?.ios || "",
@@ -67,7 +67,7 @@ export class WalletConnectProvider {
67
67
  if (sessions.length > 0) {
68
68
  this.session = sessions[0];
69
69
  this.updateAccountsFromSession();
70
- this.emit("connect", { chainId: this.chainId });
70
+ this.emit("connect", { chainId: this.chainId, accounts: this.accounts });
71
71
  }
72
72
  });
73
73
 
@@ -157,6 +157,7 @@ export class WalletConnectProvider {
157
157
  return new Promise((resolve, reject) => {
158
158
  const timeout = setTimeout(() => {
159
159
  reject(new Error("Connection timeout"));
160
+ this.emit("error", new Error("Connection timeout"));
160
161
  }, 300000); // 5 minutes
161
162
 
162
163
  const checkConnection = () => {
@@ -166,7 +167,7 @@ export class WalletConnectProvider {
166
167
  clearTimeout(timeout);
167
168
  this.session = newSessions[0];
168
169
  this.updateAccountsFromSession();
169
- this.emit("connect", { chainId: this.chainId });
170
+ this.emit("connect", { chainId: this.chainId, accounts: this.accounts });
170
171
  resolve(true);
171
172
  } else {
172
173
  setTimeout(checkConnection, 500);
@@ -81,7 +81,7 @@ function convertWalletToConnector(wallet: ReturnType<typeof walletConnectWallet>
81
81
  * Create a WalletConnect provider instance
82
82
  * Provider will be initialized when connect() is called
83
83
  */
84
- function createWalletConnectEVMProvider(): any {
84
+ export function createWalletConnectEVMProvider(): any {
85
85
  const getProvider = async () => {
86
86
  if (!providerInstance) {
87
87
  if (!walletConnectConfig) {