@getpara/solana-wallet-connectors 2.0.0-alpha.20 → 2.0.0-alpha.21
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/dist/index.d.ts +1 -1
- package/dist/index.js +5 -1
- package/dist/providers/SolanaExternalWalletContext.d.ts +12 -27
- package/dist/providers/SolanaExternalWalletContext.js +108 -28
- package/dist/wallets/connectors/backpack/backpack.js +1 -0
- package/dist/wallets/connectors/glow/glow.js +1 -0
- package/dist/wallets/connectors/phantom/phantom.js +1 -0
- package/dist/wallets/connectors/solflare/solflare.js +1 -0
- package/package.json +8 -8
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { SolanaExternalWalletContext } from './providers/SolanaExternalWalletContext.js';
|
|
2
|
-
export type
|
|
2
|
+
export { type SolanaExternalWalletContextType, defaultSolanaExternalWallet, } from './providers/SolanaExternalWalletContext.js';
|
|
3
3
|
export { ParaSolanaProvider } from './providers/ParaSolanaProvider.js';
|
|
4
4
|
export type { ParaSolanaProviderConfig, ParaSolanaProviderProps } from './providers/ParaSolanaProvider.js';
|
|
5
5
|
export * from './wallets/connectors/index.js';
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { SolanaExternalWalletContext } from "./providers/SolanaExternalWalletContext.js";
|
|
3
|
+
import {
|
|
4
|
+
defaultSolanaExternalWallet
|
|
5
|
+
} from "./providers/SolanaExternalWalletContext.js";
|
|
3
6
|
import { ParaSolanaProvider } from "./providers/ParaSolanaProvider.js";
|
|
4
7
|
export * from "./wallets/connectors/index.js";
|
|
5
8
|
export {
|
|
6
9
|
ParaSolanaProvider,
|
|
7
|
-
SolanaExternalWalletContext
|
|
10
|
+
SolanaExternalWalletContext,
|
|
11
|
+
defaultSolanaExternalWallet
|
|
8
12
|
};
|
|
@@ -1,33 +1,18 @@
|
|
|
1
1
|
import { PropsWithChildren } from 'react';
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
export
|
|
6
|
-
wallets:
|
|
2
|
+
import { ExternalWalletInfo } from '@getpara/web-sdk';
|
|
3
|
+
import { CreateWalletFn } from '../types/Wallet.js';
|
|
4
|
+
import { ExternalWalletContextType, ExternalWalletProviderConfig, ExternalWalletProviderConfigBase } from '@getpara/react-common';
|
|
5
|
+
export declare const defaultSolanaExternalWallet: {
|
|
6
|
+
wallets: any[];
|
|
7
7
|
disconnect: () => Promise<void>;
|
|
8
|
-
signMessage: (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
signVerificationMessage: () => Promise<{
|
|
13
|
-
address?: string;
|
|
14
|
-
signature?: string;
|
|
15
|
-
error?: string;
|
|
16
|
-
}>;
|
|
8
|
+
signMessage: () => Promise<{}>;
|
|
9
|
+
signVerificationMessage: () => Promise<{}>;
|
|
10
|
+
requestInfo: () => Promise<ExternalWalletInfo>;
|
|
11
|
+
disconnectBase: () => Promise<void>;
|
|
17
12
|
};
|
|
13
|
+
export type SolanaExternalWalletContextType = ExternalWalletContextType;
|
|
18
14
|
export declare const SolanaExternalWalletContext: import("react").Context<SolanaExternalWalletContextType>;
|
|
19
|
-
export type SolanaExternalWalletProviderConfig =
|
|
20
|
-
|
|
21
|
-
address?: string;
|
|
22
|
-
error?: string;
|
|
23
|
-
}) => void;
|
|
24
|
-
para: ParaWeb;
|
|
25
|
-
walletsWithFullAuth: TExternalWallet[];
|
|
26
|
-
includeWalletVerification?: boolean;
|
|
27
|
-
connectionOnly?: boolean;
|
|
28
|
-
};
|
|
29
|
-
type SolanaExternalWalletProviderConfigFull = {
|
|
30
|
-
wallets: WalletList;
|
|
31
|
-
} & SolanaExternalWalletProviderConfig;
|
|
15
|
+
export type SolanaExternalWalletProviderConfig = ExternalWalletProviderConfigBase;
|
|
16
|
+
type SolanaExternalWalletProviderConfigFull = ExternalWalletProviderConfig<CreateWalletFn>;
|
|
32
17
|
export declare function SolanaExternalWalletProvider({ children, wallets: walletFns, onSwitchWallet, para, walletsWithFullAuth, includeWalletVerification, connectionOnly, }: SolanaExternalWalletProviderConfigFull & PropsWithChildren): import("react/jsx-runtime").JSX.Element;
|
|
33
18
|
export {};
|
|
@@ -44,7 +44,9 @@ const defaultSolanaExternalWallet = {
|
|
|
44
44
|
wallets: [],
|
|
45
45
|
disconnect: () => Promise.resolve(),
|
|
46
46
|
signMessage: () => Promise.resolve({}),
|
|
47
|
-
signVerificationMessage: () => Promise.resolve({})
|
|
47
|
+
signVerificationMessage: () => Promise.resolve({}),
|
|
48
|
+
requestInfo: () => Promise.resolve({}),
|
|
49
|
+
disconnectBase: () => Promise.resolve()
|
|
48
50
|
};
|
|
49
51
|
const SolanaExternalWalletContext = createContext(defaultSolanaExternalWallet);
|
|
50
52
|
function SolanaExternalWalletProvider({
|
|
@@ -59,18 +61,31 @@ function SolanaExternalWalletProvider({
|
|
|
59
61
|
const {
|
|
60
62
|
wallets: adapters,
|
|
61
63
|
select: selectWallet,
|
|
62
|
-
disconnect
|
|
64
|
+
disconnect,
|
|
63
65
|
publicKey: solanaAddress,
|
|
64
66
|
wallet,
|
|
65
67
|
connecting,
|
|
66
68
|
signMessage: solanaSignMessage
|
|
67
69
|
} = useWallet();
|
|
70
|
+
const isLinkingAccount = useRef(false);
|
|
71
|
+
const solanaSignMessageRef = useRef(solanaSignMessage);
|
|
72
|
+
const solanaAddressRef = useRef(solanaAddress);
|
|
68
73
|
const verificationMessage = useRef();
|
|
69
74
|
const reset = () => __async(this, null, function* () {
|
|
70
|
-
yield
|
|
75
|
+
yield disconnect();
|
|
71
76
|
yield para.logout();
|
|
72
77
|
});
|
|
73
|
-
const
|
|
78
|
+
const _reset = (..._0) => __async(this, [..._0], function* ({ logout = false } = {}) {
|
|
79
|
+
yield disconnect();
|
|
80
|
+
if (logout) {
|
|
81
|
+
yield para.logout();
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
const login = (_0) => __async(this, [_0], function* ({
|
|
85
|
+
address,
|
|
86
|
+
providerId,
|
|
87
|
+
providerName
|
|
88
|
+
}) {
|
|
74
89
|
var _a, _b;
|
|
75
90
|
try {
|
|
76
91
|
return yield para.loginExternalWallet({
|
|
@@ -78,6 +93,7 @@ function SolanaExternalWalletProvider({
|
|
|
78
93
|
address,
|
|
79
94
|
type: "SOLANA",
|
|
80
95
|
provider: providerName,
|
|
96
|
+
providerId,
|
|
81
97
|
withFullParaAuth: walletsWithFullAuth == null ? void 0 : walletsWithFullAuth.includes(
|
|
82
98
|
(_b = (_a = getWallet(providerName != null ? providerName : "")) == null ? void 0 : _a.id.toUpperCase()) != null ? _b : ""
|
|
83
99
|
),
|
|
@@ -91,7 +107,7 @@ function SolanaExternalWalletProvider({
|
|
|
91
107
|
}
|
|
92
108
|
});
|
|
93
109
|
const switchWallet = (address) => __async(this, null, function* () {
|
|
94
|
-
var _a;
|
|
110
|
+
var _a, _b, _c, _d;
|
|
95
111
|
let error;
|
|
96
112
|
if (!address) {
|
|
97
113
|
yield para.logout();
|
|
@@ -102,7 +118,8 @@ function SolanaExternalWalletProvider({
|
|
|
102
118
|
try {
|
|
103
119
|
yield login({
|
|
104
120
|
address,
|
|
105
|
-
|
|
121
|
+
providerId: (_c = getWallet((_b = (_a = wallet == null ? void 0 : wallet.adapter) == null ? void 0 : _a.name) != null ? _b : "")) == null ? void 0 : _c.internalId,
|
|
122
|
+
providerName: (_d = wallet == null ? void 0 : wallet.adapter) == null ? void 0 : _d.name
|
|
106
123
|
});
|
|
107
124
|
} catch (err) {
|
|
108
125
|
error = err;
|
|
@@ -114,25 +131,41 @@ function SolanaExternalWalletProvider({
|
|
|
114
131
|
useEffect(() => {
|
|
115
132
|
var _a;
|
|
116
133
|
const storedExternalWallet = para.externalWallets[(_a = solanaAddress == null ? void 0 : solanaAddress.toString()) != null ? _a : ""];
|
|
117
|
-
if (!!solanaAddress && !storedExternalWallet) {
|
|
134
|
+
if (!!solanaAddress && !storedExternalWallet && !isLinkingAccount.current) {
|
|
118
135
|
reset();
|
|
119
136
|
}
|
|
120
137
|
}, []);
|
|
138
|
+
useEffect(() => {
|
|
139
|
+
solanaSignMessageRef.current = solanaSignMessage;
|
|
140
|
+
}, [solanaSignMessage]);
|
|
141
|
+
useEffect(() => {
|
|
142
|
+
solanaAddressRef.current = solanaAddress;
|
|
143
|
+
}, [solanaAddress]);
|
|
121
144
|
useEffect(() => {
|
|
122
145
|
const storedExternalWallet = Object.values(para.externalWallets || {})[0];
|
|
123
|
-
if (!connecting && (!wallet || (wallet == null ? void 0 : wallet.adapter.connected)) && (storedExternalWallet == null ? void 0 : storedExternalWallet.type) === "SOLANA" && (storedExternalWallet == null ? void 0 : storedExternalWallet.address) !== (solanaAddress == null ? void 0 : solanaAddress.toString())) {
|
|
146
|
+
if (!connecting && (!wallet || (wallet == null ? void 0 : wallet.adapter.connected)) && (storedExternalWallet == null ? void 0 : storedExternalWallet.type) === "SOLANA" && (storedExternalWallet == null ? void 0 : storedExternalWallet.address) !== (solanaAddress == null ? void 0 : solanaAddress.toString()) && !isLinkingAccount.current) {
|
|
124
147
|
switchWallet(solanaAddress == null ? void 0 : solanaAddress.toString());
|
|
125
148
|
}
|
|
126
149
|
}, [solanaAddress, connecting, wallet]);
|
|
127
|
-
const signMessage = (
|
|
150
|
+
const signMessage = (_0) => __async(this, [_0], function* ({ message }) {
|
|
151
|
+
var _a, _b, _c, _d;
|
|
128
152
|
try {
|
|
153
|
+
let solanaAddressNow = (_a = solanaAddressRef.current) != null ? _a : solanaAddress, solanaSignMessageNow = (_b = solanaSignMessageRef.current) != null ? _b : solanaSignMessage;
|
|
154
|
+
while (!solanaAddressNow || !solanaSignMessageNow) {
|
|
155
|
+
yield new Promise((resolve) => setTimeout(resolve, 100));
|
|
156
|
+
solanaAddressNow = (_c = solanaAddressRef.current) != null ? _c : solanaAddress;
|
|
157
|
+
solanaSignMessageNow = (_d = solanaSignMessageRef.current) != null ? _d : solanaSignMessage;
|
|
158
|
+
}
|
|
129
159
|
const encodedMessage = new TextEncoder().encode(message);
|
|
130
|
-
const signature = yield
|
|
160
|
+
const signature = yield solanaSignMessageNow(encodedMessage);
|
|
161
|
+
solanaAddressRef.current = void 0;
|
|
162
|
+
solanaSignMessageRef.current = void 0;
|
|
131
163
|
return {
|
|
132
|
-
address:
|
|
164
|
+
address: solanaAddressNow.toString(),
|
|
133
165
|
signature: bs58.encode(signature)
|
|
134
166
|
};
|
|
135
167
|
} catch (e) {
|
|
168
|
+
console.error(e);
|
|
136
169
|
if (e.message.includes("User rejected the request")) {
|
|
137
170
|
return { error: "Signature request rejected" };
|
|
138
171
|
}
|
|
@@ -140,31 +173,46 @@ function SolanaExternalWalletProvider({
|
|
|
140
173
|
}
|
|
141
174
|
});
|
|
142
175
|
const signVerificationMessage = () => __async(this, null, function* () {
|
|
143
|
-
const signature = yield signMessage(verificationMessage.current);
|
|
176
|
+
const signature = yield signMessage({ message: verificationMessage.current });
|
|
144
177
|
return signature;
|
|
145
178
|
});
|
|
146
|
-
const
|
|
147
|
-
if (isIosAndRedirectable()) {
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
yield _disconnect();
|
|
179
|
+
const connectBase = (adapter, _switchWallet = false) => __async(this, null, function* () {
|
|
151
180
|
if (!adapter) {
|
|
152
|
-
|
|
181
|
+
throw new Error("Adapter not found.");
|
|
153
182
|
}
|
|
154
183
|
selectWallet(adapter.name);
|
|
155
184
|
yield new Promise((resolve) => setTimeout(resolve, 100));
|
|
185
|
+
try {
|
|
186
|
+
yield adapter.connect();
|
|
187
|
+
yield new Promise((resolve) => setTimeout(resolve, 100));
|
|
188
|
+
while (!adapter.publicKey) {
|
|
189
|
+
yield new Promise((resolve) => setTimeout(resolve, 100));
|
|
190
|
+
}
|
|
191
|
+
const address = adapter.publicKey.toString();
|
|
192
|
+
return address;
|
|
193
|
+
} catch (e) {
|
|
194
|
+
console.error(e);
|
|
195
|
+
yield adapter.disconnect();
|
|
196
|
+
throw e;
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
const connect = (adapter) => __async(this, null, function* () {
|
|
200
|
+
var _a;
|
|
201
|
+
if (isIosAndRedirectable()) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
yield disconnect();
|
|
156
205
|
let address;
|
|
157
206
|
let error;
|
|
158
207
|
let authState;
|
|
159
208
|
try {
|
|
160
|
-
yield adapter
|
|
161
|
-
address = adapter.publicKey.toString();
|
|
209
|
+
address = yield connectBase(adapter, true);
|
|
162
210
|
if (address) {
|
|
163
211
|
try {
|
|
164
|
-
authState = yield login({ address, providerName: adapter.name });
|
|
212
|
+
authState = yield login({ address, providerId: (_a = getWallet(adapter.name)) == null ? void 0 : _a.internalId, providerName: adapter.name });
|
|
165
213
|
verificationMessage.current = authState.stage === "verify" ? authState.signatureVerificationMessage : void 0;
|
|
166
214
|
} catch (err) {
|
|
167
|
-
yield
|
|
215
|
+
yield disconnect();
|
|
168
216
|
address = void 0;
|
|
169
217
|
error = err;
|
|
170
218
|
}
|
|
@@ -185,6 +233,40 @@ function SolanaExternalWalletProvider({
|
|
|
185
233
|
}
|
|
186
234
|
return { address, error, authState };
|
|
187
235
|
});
|
|
236
|
+
const requestInfo = (providerId) => __async(this, null, function* () {
|
|
237
|
+
var _a, _b;
|
|
238
|
+
const wallet2 = wallets.find((w) => w.internalId === providerId);
|
|
239
|
+
const adapter = getAdapter((_a = wallet2.name) != null ? _a : "");
|
|
240
|
+
isLinkingAccount.current = true;
|
|
241
|
+
try {
|
|
242
|
+
const address = yield connectBase(adapter);
|
|
243
|
+
const externalWallet = {
|
|
244
|
+
address,
|
|
245
|
+
type: "SOLANA",
|
|
246
|
+
providerId: wallet2.internalId,
|
|
247
|
+
provider: wallet2.name
|
|
248
|
+
};
|
|
249
|
+
return externalWallet;
|
|
250
|
+
} catch (e) {
|
|
251
|
+
console.error("Error linking account:", e);
|
|
252
|
+
throw new Error((_b = e == null ? void 0 : e.message) != null ? _b : e);
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
const disconnectBase = (providerId) => __async(this, null, function* () {
|
|
256
|
+
var _a, _b;
|
|
257
|
+
const wallet2 = wallets.find((w) => w.internalId === providerId);
|
|
258
|
+
const adapter = getAdapter((_a = wallet2.name) != null ? _a : "");
|
|
259
|
+
if (!(adapter == null ? void 0 : adapter.connected)) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
isLinkingAccount.current = true;
|
|
263
|
+
try {
|
|
264
|
+
yield adapter.disconnect();
|
|
265
|
+
} catch (e) {
|
|
266
|
+
console.error("Error disconnecting wallet:", e);
|
|
267
|
+
throw new Error((_b = e == null ? void 0 : e.message) != null ? _b : e);
|
|
268
|
+
}
|
|
269
|
+
});
|
|
188
270
|
const getAdapter = (name) => {
|
|
189
271
|
var _a;
|
|
190
272
|
return (_a = adapters.find((a) => a.adapter.name === "Mobile Wallet Adapter" ? a : a.adapter.name === name ? a : false)) == null ? void 0 : _a.adapter;
|
|
@@ -200,15 +282,12 @@ function SolanaExternalWalletProvider({
|
|
|
200
282
|
installed: adapter && ((adapter == null ? void 0 : adapter.readyState) === WalletReadyState.Installed || (adapter == null ? void 0 : adapter.readyState) === WalletReadyState.Loadable)
|
|
201
283
|
}, metaData);
|
|
202
284
|
});
|
|
203
|
-
const disconnect = () => __async(this, null, function* () {
|
|
204
|
-
yield _disconnect();
|
|
205
|
-
});
|
|
206
285
|
return /* @__PURE__ */ jsx(
|
|
207
286
|
SolanaExternalWalletContext.Provider,
|
|
208
287
|
{
|
|
209
288
|
value: useMemo(
|
|
210
|
-
() => ({ wallets, disconnect, signMessage, signVerificationMessage }),
|
|
211
|
-
[wallets, disconnect, signMessage, signVerificationMessage]
|
|
289
|
+
() => ({ wallets, disconnect, signMessage, signVerificationMessage, requestInfo, disconnectBase }),
|
|
290
|
+
[wallets, disconnect, signMessage, signVerificationMessage, requestInfo, disconnectBase]
|
|
212
291
|
),
|
|
213
292
|
children
|
|
214
293
|
}
|
|
@@ -216,5 +295,6 @@ function SolanaExternalWalletProvider({
|
|
|
216
295
|
}
|
|
217
296
|
export {
|
|
218
297
|
SolanaExternalWalletContext,
|
|
219
|
-
SolanaExternalWalletProvider
|
|
298
|
+
SolanaExternalWalletProvider,
|
|
299
|
+
defaultSolanaExternalWallet
|
|
220
300
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/solana-wallet-connectors",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.21",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -14,15 +14,15 @@
|
|
|
14
14
|
"test": "vitest run --coverage"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@getpara/web-sdk": "2.0.0-alpha.
|
|
18
|
-
"@solana-mobile/wallet-adapter-mobile": "2.
|
|
19
|
-
"@solana/wallet-adapter-base": "0.9.
|
|
20
|
-
"@solana/wallet-adapter-react": "0.15.
|
|
21
|
-
"@solana/wallet-adapter-walletconnect": "0.1.
|
|
17
|
+
"@getpara/web-sdk": "2.0.0-alpha.21",
|
|
18
|
+
"@solana-mobile/wallet-adapter-mobile": "2.2.0",
|
|
19
|
+
"@solana/wallet-adapter-base": "0.9.27",
|
|
20
|
+
"@solana/wallet-adapter-react": "0.15.39",
|
|
21
|
+
"@solana/wallet-adapter-walletconnect": "0.1.21",
|
|
22
22
|
"bs58": "6.0.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@getpara/react-common": "2.0.0-alpha.
|
|
25
|
+
"@getpara/react-common": "2.0.0-alpha.21",
|
|
26
26
|
"@types/react": "^18.0.31",
|
|
27
27
|
"@types/react-dom": "^18.2.7",
|
|
28
28
|
"typescript": "^5.4.3"
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"dist",
|
|
36
36
|
"package.json"
|
|
37
37
|
],
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "03daa3537312bc52e0640225c8abdbf8047c15da"
|
|
39
39
|
}
|