@tomo-inc/wallet-adaptor-base 0.0.2 → 0.0.4
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.
- package/package.json +2 -1
- package/project.json +0 -8
- package/src/index.ts +3 -0
- package/src/type.ts +5 -0
- package/src/utils/browsers.ts +13 -0
- package/src/utils/chainId.ts +1 -1
- package/src/wallet-api/chain.ts +9 -2
- package/src/wallet-api/connect.ts +85 -24
- package/src/wallet-api/sign-in.ts +4 -1
- package/src/wallet-api/sign-message.ts +38 -5
- package/src/wallets/Wallet.ts +4 -0
- package/src/wallets/default/binanceWallet/binanceWallet.ts +27 -0
- package/src/wallets/default/bitgetWallet/bitgetWallet.ts +10 -0
- package/src/wallets/default/bitverseWallet/bitverseWallet.ts +3 -0
- package/src/wallets/default/bybitWallet/bybitWallet.ts +5 -0
- package/src/wallets/default/coinbaseWallet/coinbaseWallet.ts +7 -0
- package/src/wallets/default/foxWallet/foxWallet.ts +5 -0
- package/src/wallets/default/gateWallet/gateWallet.ts +6 -0
- package/src/wallets/default/imTokenWallet/imTokenWallet.ts +9 -0
- package/src/wallets/default/iopayWallet/iopayWallet.ts +6 -0
- package/src/wallets/default/kaiaWallet/kaiaWallet.ts +5 -0
- package/src/wallets/default/kaikasWallet/kaikasWallet.ts +5 -0
- package/src/wallets/default/krakenWallet/krakenWallet.ts +5 -0
- package/src/wallets/default/kresusWallet/kresusWallet.ts +3 -0
- package/src/wallets/default/ledgerWallet/ledgerWallet.ts +6 -0
- package/src/wallets/default/metaMaskWallet/metaMaskWallet.ts +17 -0
- package/src/wallets/default/oktoWallet/oktoWallet.ts +6 -0
- package/src/wallets/default/okxWallet/okxWallet.ts +11 -0
- package/src/wallets/default/omniWallet/omniWallet.ts +6 -0
- package/src/wallets/default/oneInchWallet/oneInchWallet.ts +3 -0
- package/src/wallets/default/paraSwapWallet/paraswapWallet.ts +5 -0
- package/src/wallets/default/phantomWallet/phantomWallet.ts +7 -0
- package/src/wallets/default/rainbowWallet/rainbowWallet.ts +10 -0
- package/src/wallets/default/solflareWallet/solflareWallet.ts +7 -0
- package/src/wallets/default/tokenPocketWallet/tokenPocketWallet.ts +6 -0
- package/src/wallets/default/trustWallet/trustWallet.ts +6 -0
- package/src/wallets/default/uniswapWallet/uniswapWallet.ts +5 -0
- package/src/wallets/default/valoraWallet/valoraWallet.ts +4 -0
- package/src/wallets/default/zealWallet/zealWallet.ts +5 -0
- package/src/wallets/default/zerionWallet/zerionWallet.ts +6 -0
- package/src/wallets/detector.ts +32 -16
- package/src/wallets/providers/WalletConnectProvider.ts +23 -12
- package/src/wallets/providers/WalletConnectSolanaProvider.ts +32 -23
- package/src/wallets/wallet-walletconnect.ts +18 -9
- package/tsup.config.ts +3 -2
- package/dist/index.cjs +0 -2896
- package/dist/index.d.cts +0 -330
- package/dist/index.d.ts +0 -330
- package/dist/index.js +0 -2813
|
@@ -24,5 +24,12 @@ export const phantomWallet = (): WalletConfig => {
|
|
|
24
24
|
firefox: "https://addons.mozilla.org/firefox/addon/phantom-app/",
|
|
25
25
|
browserExtension: "https://phantom.app/download",
|
|
26
26
|
},
|
|
27
|
+
mobile: {
|
|
28
|
+
getDeeplink: (dappUrl?: string, _chainId?: number): string => {
|
|
29
|
+
if (!dappUrl) return "";
|
|
30
|
+
const encodedDappUrl = encodeURIComponent(dappUrl);
|
|
31
|
+
return `https://phantom.app/ul/v1/connect?app_url=${encodedDappUrl}`;
|
|
32
|
+
},
|
|
33
|
+
},
|
|
27
34
|
};
|
|
28
35
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { WalletConfig } from "../../Wallet";
|
|
2
|
+
import { isAndroid, isIOS } from "../../../utils/isMobile";
|
|
2
3
|
import icon from "./rainbowWallet.svg";
|
|
3
4
|
|
|
4
5
|
export const rainbowWallet = (): WalletConfig => {
|
|
@@ -18,5 +19,14 @@ export const rainbowWallet = (): WalletConfig => {
|
|
|
18
19
|
qrCode: "https://rainbow.download?utm_source=rainbowkit&utm_medium=qrcode",
|
|
19
20
|
browserExtension: "https://rainbow.me/extension?utm_source=rainbowkit",
|
|
20
21
|
},
|
|
22
|
+
mobile: {
|
|
23
|
+
getUri: (uri: string) => {
|
|
24
|
+
return isAndroid()
|
|
25
|
+
? uri
|
|
26
|
+
: isIOS()
|
|
27
|
+
? `rainbow://wc?uri=${encodeURIComponent(uri)}&connector=rainbowkit`
|
|
28
|
+
: `https://rnbwapp.com/wc?uri=${encodeURIComponent(uri)}&connector=rainbowkit`;
|
|
29
|
+
},
|
|
30
|
+
},
|
|
21
31
|
};
|
|
22
32
|
};
|
|
@@ -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
|
});
|
|
@@ -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
|
};
|
package/src/wallets/detector.ts
CHANGED
|
@@ -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 (
|
|
102
|
-
providers.evm =
|
|
103
|
-
|
|
104
|
-
|
|
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 (
|
|
108
|
-
providers.solana =
|
|
109
|
-
|
|
110
|
-
|
|
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 (
|
|
114
|
-
providers.aptos =
|
|
115
|
-
|
|
116
|
-
|
|
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 || "",
|
|
@@ -20,6 +20,7 @@ export interface WalletConnectProviderConfig {
|
|
|
20
20
|
optionalChains?: string[];
|
|
21
21
|
methods?: string[];
|
|
22
22
|
events?: string[];
|
|
23
|
+
namespaces?: Record<string, NamespaceConfig>;
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
const defaultNamespaces: Record<string, NamespaceConfig> = {
|
|
@@ -47,6 +48,7 @@ export class WalletConnectProvider {
|
|
|
47
48
|
private sessionMap: Map<string, SessionInfo> = new Map();
|
|
48
49
|
public uri: string | null = null;
|
|
49
50
|
public qrCode: string | null = null;
|
|
51
|
+
private namespaces: Record<string, NamespaceConfig> = defaultNamespaces;
|
|
50
52
|
|
|
51
53
|
constructor(config: WalletConnectProviderConfig) {
|
|
52
54
|
this.client = new WalletConnectClient({
|
|
@@ -54,6 +56,8 @@ export class WalletConnectProvider {
|
|
|
54
56
|
metadata: config.metadata,
|
|
55
57
|
});
|
|
56
58
|
|
|
59
|
+
this.namespaces = config.namespaces || defaultNamespaces;
|
|
60
|
+
|
|
57
61
|
this.setupClientListeners();
|
|
58
62
|
}
|
|
59
63
|
|
|
@@ -67,7 +71,7 @@ export class WalletConnectProvider {
|
|
|
67
71
|
if (sessions.length > 0) {
|
|
68
72
|
this.session = sessions[0];
|
|
69
73
|
this.updateAccountsFromSession();
|
|
70
|
-
this.emit("connect", { chainId: this.chainId });
|
|
74
|
+
this.emit("connect", { chainId: this.chainId, accounts: this.accounts });
|
|
71
75
|
}
|
|
72
76
|
});
|
|
73
77
|
|
|
@@ -107,13 +111,20 @@ export class WalletConnectProvider {
|
|
|
107
111
|
}
|
|
108
112
|
}
|
|
109
113
|
|
|
110
|
-
public async getUri(
|
|
114
|
+
public async getUri(): Promise<string> {
|
|
115
|
+
// Return existing URI if available to avoid creating duplicate proposals
|
|
116
|
+
if (this.uri) {
|
|
117
|
+
this.emit("uri_changed", { uri: this.uri });
|
|
118
|
+
return this.uri;
|
|
119
|
+
}
|
|
120
|
+
|
|
111
121
|
// Create connection and get URI
|
|
112
122
|
const uri = await this.client.connect({
|
|
113
|
-
requiredNamespaces:
|
|
123
|
+
requiredNamespaces: this.namespaces,
|
|
114
124
|
});
|
|
115
125
|
|
|
116
126
|
this.uri = uri;
|
|
127
|
+
this.emit("uri_changed", { uri: this.uri });
|
|
117
128
|
return uri;
|
|
118
129
|
}
|
|
119
130
|
/**
|
|
@@ -126,9 +137,11 @@ export class WalletConnectProvider {
|
|
|
126
137
|
sessions.forEach((session: SessionInfo) => {
|
|
127
138
|
this.sessionMap.set(session.topic, session);
|
|
128
139
|
});
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
140
|
+
|
|
141
|
+
// Only create new URI if we don't have an active session
|
|
142
|
+
if (sessions.length === 0) {
|
|
143
|
+
this.uri = await this.getUri();
|
|
144
|
+
}
|
|
132
145
|
}
|
|
133
146
|
|
|
134
147
|
/**
|
|
@@ -139,6 +152,8 @@ export class WalletConnectProvider {
|
|
|
139
152
|
async connect(): Promise<string[] | undefined> {
|
|
140
153
|
// Start waiting for connection in background (don't await)
|
|
141
154
|
// Connection will emit 'connect' event when established
|
|
155
|
+
this.uri = await this.getUri();
|
|
156
|
+
this.emit("uri_changed", { uri: this.uri });
|
|
142
157
|
const connected = await this.waitForConnection().catch((error) => {
|
|
143
158
|
console.error("WalletConnect connection failed:", error);
|
|
144
159
|
this.emit("error", error);
|
|
@@ -157,6 +172,7 @@ export class WalletConnectProvider {
|
|
|
157
172
|
return new Promise((resolve, reject) => {
|
|
158
173
|
const timeout = setTimeout(() => {
|
|
159
174
|
reject(new Error("Connection timeout"));
|
|
175
|
+
this.emit("error", new Error("Connection timeout"));
|
|
160
176
|
}, 300000); // 5 minutes
|
|
161
177
|
|
|
162
178
|
const checkConnection = () => {
|
|
@@ -166,7 +182,7 @@ export class WalletConnectProvider {
|
|
|
166
182
|
clearTimeout(timeout);
|
|
167
183
|
this.session = newSessions[0];
|
|
168
184
|
this.updateAccountsFromSession();
|
|
169
|
-
this.emit("connect", { chainId: this.chainId });
|
|
185
|
+
this.emit("connect", { chainId: this.chainId, accounts: this.accounts });
|
|
170
186
|
resolve(true);
|
|
171
187
|
} else {
|
|
172
188
|
setTimeout(checkConnection, 500);
|
|
@@ -198,11 +214,6 @@ export class WalletConnectProvider {
|
|
|
198
214
|
if (this.accounts.length > 0) {
|
|
199
215
|
return this.accounts;
|
|
200
216
|
}
|
|
201
|
-
if (this.uri === null) {
|
|
202
|
-
this.uri = await this.getUri({
|
|
203
|
-
requiredNamespaces: defaultNamespaces,
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
217
|
return this.connect();
|
|
207
218
|
}
|
|
208
219
|
|
|
@@ -19,6 +19,7 @@ export interface WalletConnectSolanaProviderConfig {
|
|
|
19
19
|
chains?: string[];
|
|
20
20
|
methods?: string[];
|
|
21
21
|
events?: string[];
|
|
22
|
+
namespaces?: Record<string, NamespaceConfig>;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
const defaultSolanaNamespaces: Record<string, NamespaceConfig> = {
|
|
@@ -39,12 +40,13 @@ const defaultSolanaNamespaces: Record<string, NamespaceConfig> = {
|
|
|
39
40
|
export class WalletConnectSolanaProvider {
|
|
40
41
|
private client: WalletConnectClient;
|
|
41
42
|
private session: SessionInfo | null = null;
|
|
42
|
-
private accounts: string[] = [];
|
|
43
|
+
private accounts: { publicKey: string }[] = [];
|
|
43
44
|
private chainId: string = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"; // Default to Solana mainnet
|
|
44
45
|
private eventListeners: Map<string, Set<(...args: any[]) => void>> = new Map();
|
|
45
46
|
private sessionMap: Map<string, SessionInfo> = new Map();
|
|
46
47
|
public uri: string | null = null;
|
|
47
48
|
public qrCode: string | null = null;
|
|
49
|
+
private namespaces: Record<string, NamespaceConfig> = defaultSolanaNamespaces;
|
|
48
50
|
|
|
49
51
|
constructor(config: WalletConnectSolanaProviderConfig) {
|
|
50
52
|
this.client = new WalletConnectClient({
|
|
@@ -52,6 +54,8 @@ export class WalletConnectSolanaProvider {
|
|
|
52
54
|
metadata: config.metadata,
|
|
53
55
|
});
|
|
54
56
|
|
|
57
|
+
this.namespaces = config.namespaces || defaultSolanaNamespaces;
|
|
58
|
+
|
|
55
59
|
this.setupClientListeners();
|
|
56
60
|
}
|
|
57
61
|
|
|
@@ -94,11 +98,13 @@ export class WalletConnectSolanaProvider {
|
|
|
94
98
|
|
|
95
99
|
const allAccounts = Object.values(this.session.namespaces).flatMap((ns: any) => ns.accounts || []);
|
|
96
100
|
|
|
97
|
-
this.accounts = allAccounts
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
this.accounts = allAccounts
|
|
102
|
+
.filter((account: string) => account.startsWith("solana:"))
|
|
103
|
+
.map((account) => {
|
|
104
|
+
const parts = account.split(":");
|
|
105
|
+
// Solana account format: solana:chainId:pubkey
|
|
106
|
+
return { publicKey: parts[2] };
|
|
107
|
+
});
|
|
102
108
|
|
|
103
109
|
if (allAccounts.length > 0) {
|
|
104
110
|
const chainIdPart = allAccounts[0].split(":")[1];
|
|
@@ -106,13 +112,20 @@ export class WalletConnectSolanaProvider {
|
|
|
106
112
|
}
|
|
107
113
|
}
|
|
108
114
|
|
|
109
|
-
public async getUri(
|
|
115
|
+
public async getUri(): Promise<string> {
|
|
116
|
+
// Return existing URI if available to avoid creating duplicate proposals
|
|
117
|
+
if (this.uri) {
|
|
118
|
+
this.emit("uri_changed", { uri: this.uri });
|
|
119
|
+
return this.uri;
|
|
120
|
+
}
|
|
121
|
+
|
|
110
122
|
// Create connection and get URI
|
|
111
123
|
const uri = await this.client.connect({
|
|
112
|
-
requiredNamespaces:
|
|
124
|
+
requiredNamespaces: this.namespaces,
|
|
113
125
|
});
|
|
114
126
|
|
|
115
127
|
this.uri = uri;
|
|
128
|
+
this.emit("uri_changed", { uri: this.uri });
|
|
116
129
|
return uri;
|
|
117
130
|
}
|
|
118
131
|
|
|
@@ -126,16 +139,17 @@ export class WalletConnectSolanaProvider {
|
|
|
126
139
|
sessions.forEach((session: SessionInfo) => {
|
|
127
140
|
this.sessionMap.set(session.topic, session);
|
|
128
141
|
});
|
|
129
|
-
this.uri = await this.getUri({
|
|
130
|
-
requiredNamespaces: defaultSolanaNamespaces,
|
|
131
|
-
});
|
|
132
142
|
}
|
|
133
143
|
|
|
134
144
|
/**
|
|
135
145
|
* Connect to wallet via WalletConnect
|
|
136
146
|
* Returns accounts when connected
|
|
137
147
|
*/
|
|
138
|
-
async connect(): Promise<string
|
|
148
|
+
async connect(): Promise<{ publicKey: string } | undefined> {
|
|
149
|
+
if (this.accounts.length > 0) {
|
|
150
|
+
return this.accounts[0];
|
|
151
|
+
}
|
|
152
|
+
this.uri = await this.getUri();
|
|
139
153
|
// Start waiting for connection in background (don't await)
|
|
140
154
|
// Connection will emit 'connect' event when established
|
|
141
155
|
const connected = await this.waitForConnection().catch((error) => {
|
|
@@ -145,7 +159,7 @@ export class WalletConnectSolanaProvider {
|
|
|
145
159
|
});
|
|
146
160
|
|
|
147
161
|
if (connected) {
|
|
148
|
-
return this.accounts;
|
|
162
|
+
return this.accounts?.length > 0 ? this.accounts[0] : undefined;
|
|
149
163
|
}
|
|
150
164
|
}
|
|
151
165
|
|
|
@@ -195,20 +209,15 @@ export class WalletConnectSolanaProvider {
|
|
|
195
209
|
// solana_requestAccounts
|
|
196
210
|
if (args.method === "solana_requestAccounts") {
|
|
197
211
|
if (this.accounts.length > 0) {
|
|
198
|
-
return
|
|
199
|
-
}
|
|
200
|
-
if (this.uri === null) {
|
|
201
|
-
this.uri = await this.getUri({
|
|
202
|
-
requiredNamespaces: defaultSolanaNamespaces,
|
|
203
|
-
});
|
|
212
|
+
return { publicKey: this.accounts[0] };
|
|
204
213
|
}
|
|
205
214
|
const accounts = await this.connect();
|
|
206
|
-
return accounts
|
|
215
|
+
return accounts;
|
|
207
216
|
}
|
|
208
217
|
|
|
209
218
|
// solana_getAccounts
|
|
210
219
|
if (args.method === "solana_getAccounts") {
|
|
211
|
-
return this.accounts
|
|
220
|
+
return this.accounts || [];
|
|
212
221
|
}
|
|
213
222
|
|
|
214
223
|
if (!this.session) {
|
|
@@ -234,9 +243,9 @@ export class WalletConnectSolanaProvider {
|
|
|
234
243
|
/**
|
|
235
244
|
* Get current accounts
|
|
236
245
|
*/
|
|
237
|
-
async getAccounts(): Promise<string[]> {
|
|
246
|
+
async getAccounts(): Promise<{ publicKey: string }[]> {
|
|
238
247
|
if (!this.session) {
|
|
239
|
-
return [];
|
|
248
|
+
return [{ publicKey: "" }];
|
|
240
249
|
}
|
|
241
250
|
return this.accounts;
|
|
242
251
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { NamespaceConfig } from "@tomo-inc/wallet-connect-protocol";
|
|
1
2
|
import { Connector, ProviderProtocol } from "../type";
|
|
2
3
|
import { walletConnectWallet } from "./default/walletConnectWallet/walletConnectWallet";
|
|
3
4
|
import { WalletConnectProvider } from "./providers/WalletConnectProvider";
|
|
@@ -15,6 +16,8 @@ let walletConnectConfig: {
|
|
|
15
16
|
url: string;
|
|
16
17
|
icons: string[];
|
|
17
18
|
};
|
|
19
|
+
solanaNamespaces?: Record<string, NamespaceConfig>;
|
|
20
|
+
evmNamespaces?: Record<string, NamespaceConfig>;
|
|
18
21
|
} | null = null;
|
|
19
22
|
|
|
20
23
|
let providerInstance: WalletConnectProvider | null = null;
|
|
@@ -66,13 +69,13 @@ function convertWalletToConnector(wallet: ReturnType<typeof walletConnectWallet>
|
|
|
66
69
|
isInstalled: true, // Always available
|
|
67
70
|
providers: {
|
|
68
71
|
evm: {
|
|
69
|
-
provider: createWalletConnectEVMProvider(),
|
|
72
|
+
provider: createWalletConnectEVMProvider(walletConnectConfig?.evmNamespaces),
|
|
73
|
+
protocol: ProviderProtocol.WALLET_CONNECT,
|
|
74
|
+
},
|
|
75
|
+
solana: {
|
|
76
|
+
provider: createWalletConnectSolanaProvider(walletConnectConfig?.solanaNamespaces),
|
|
70
77
|
protocol: ProviderProtocol.WALLET_CONNECT,
|
|
71
78
|
},
|
|
72
|
-
// solana: {
|
|
73
|
-
// provider: createWalletConnectSolanaProvider(),
|
|
74
|
-
// protocol: ProviderProtocol.WALLET_CONNECT,
|
|
75
|
-
// },
|
|
76
79
|
},
|
|
77
80
|
};
|
|
78
81
|
}
|
|
@@ -81,14 +84,17 @@ function convertWalletToConnector(wallet: ReturnType<typeof walletConnectWallet>
|
|
|
81
84
|
* Create a WalletConnect provider instance
|
|
82
85
|
* Provider will be initialized when connect() is called
|
|
83
86
|
*/
|
|
84
|
-
function createWalletConnectEVMProvider(): any {
|
|
87
|
+
export function createWalletConnectEVMProvider(namespaces?: Record<string, NamespaceConfig>): any {
|
|
85
88
|
const getProvider = async () => {
|
|
86
89
|
if (!providerInstance) {
|
|
87
90
|
if (!walletConnectConfig) {
|
|
88
91
|
throw new Error("WalletConnect not configured. Please call setWalletConnectConfig() first.");
|
|
89
92
|
}
|
|
90
93
|
|
|
91
|
-
providerInstance = new WalletConnectProvider(
|
|
94
|
+
providerInstance = new WalletConnectProvider({
|
|
95
|
+
...walletConnectConfig,
|
|
96
|
+
namespaces: namespaces || walletConnectConfig?.evmNamespaces,
|
|
97
|
+
});
|
|
92
98
|
await providerInstance.initialize();
|
|
93
99
|
}
|
|
94
100
|
return providerInstance;
|
|
@@ -143,14 +149,17 @@ function createWalletConnectEVMProvider(): any {
|
|
|
143
149
|
* Create a WalletConnect Solana provider instance
|
|
144
150
|
* Provider will be initialized when connect() is called
|
|
145
151
|
*/
|
|
146
|
-
function createWalletConnectSolanaProvider(): any {
|
|
152
|
+
function createWalletConnectSolanaProvider(namespaces?: Record<string, NamespaceConfig>): any {
|
|
147
153
|
const getProvider = async () => {
|
|
148
154
|
if (!solanaProviderInstance) {
|
|
149
155
|
if (!walletConnectConfig) {
|
|
150
156
|
throw new Error("WalletConnect not configured. Please call setWalletConnectConfig() first.");
|
|
151
157
|
}
|
|
152
158
|
|
|
153
|
-
solanaProviderInstance = new WalletConnectSolanaProvider(
|
|
159
|
+
solanaProviderInstance = new WalletConnectSolanaProvider({
|
|
160
|
+
...walletConnectConfig,
|
|
161
|
+
namespaces: namespaces || walletConnectConfig?.solanaNamespaces || {},
|
|
162
|
+
});
|
|
154
163
|
await solanaProviderInstance.initialize();
|
|
155
164
|
}
|
|
156
165
|
return solanaProviderInstance;
|
package/tsup.config.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { readFileSync, writeFileSync, readdirSync, statSync } from "fs";
|
|
1
|
+
import { readdirSync, readFileSync, statSync, writeFileSync } from "fs";
|
|
3
2
|
import { join } from "path";
|
|
3
|
+
import { defineConfig } from "tsup";
|
|
4
4
|
|
|
5
5
|
// Recursively find all JS files in dist directory
|
|
6
6
|
function findJsFiles(dir: string, fileList: string[] = []): string[] {
|
|
@@ -24,6 +24,7 @@ export default defineConfig({
|
|
|
24
24
|
treeshake: true,
|
|
25
25
|
clean: true,
|
|
26
26
|
platform: "browser",
|
|
27
|
+
tsconfig: "tsconfig.json",
|
|
27
28
|
loader: {
|
|
28
29
|
".svg": "base64",
|
|
29
30
|
},
|