@getpara/solana-wallet-connectors 2.0.0-alpha.20 → 2.0.0-alpha.22
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 +129 -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,57 +131,108 @@ 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
|
}
|
|
172
|
+
console.error("Solana signature error:", e.message);
|
|
139
173
|
return { error: "An unknown error occurred" };
|
|
140
174
|
}
|
|
141
175
|
});
|
|
142
176
|
const signVerificationMessage = () => __async(this, null, function* () {
|
|
143
|
-
const signature = yield signMessage(verificationMessage.current);
|
|
177
|
+
const signature = yield signMessage({ message: verificationMessage.current });
|
|
144
178
|
return signature;
|
|
145
179
|
});
|
|
146
|
-
const
|
|
147
|
-
if (isIosAndRedirectable()) {
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
yield _disconnect();
|
|
180
|
+
const connectBase = (adapter, _switchWallet = false) => __async(this, null, function* () {
|
|
151
181
|
if (!adapter) {
|
|
152
|
-
|
|
182
|
+
throw new Error("Adapter not found.");
|
|
153
183
|
}
|
|
154
184
|
selectWallet(adapter.name);
|
|
155
185
|
yield new Promise((resolve) => setTimeout(resolve, 100));
|
|
156
186
|
let address;
|
|
157
187
|
let error;
|
|
158
|
-
let authState;
|
|
159
188
|
try {
|
|
160
189
|
yield adapter.connect();
|
|
161
|
-
|
|
190
|
+
if (adapter.publicKey) {
|
|
191
|
+
address = adapter.publicKey.toString();
|
|
192
|
+
} else {
|
|
193
|
+
yield new Promise((resolve, reject) => {
|
|
194
|
+
adapter.once("connect", () => __async(this, null, function* () {
|
|
195
|
+
try {
|
|
196
|
+
address = adapter.publicKey.toString();
|
|
197
|
+
resolve();
|
|
198
|
+
} catch (err) {
|
|
199
|
+
reject(err);
|
|
200
|
+
}
|
|
201
|
+
}));
|
|
202
|
+
adapter.once("error", (err) => {
|
|
203
|
+
error = (err == null ? void 0 : err.message) || "An unknown error occurred";
|
|
204
|
+
reject(err);
|
|
205
|
+
});
|
|
206
|
+
adapter.once("disconnect", () => {
|
|
207
|
+
error = "Disconnected before connect event";
|
|
208
|
+
reject(new Error(error));
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
return address;
|
|
213
|
+
} catch (e) {
|
|
214
|
+
console.error(e);
|
|
215
|
+
yield adapter.disconnect();
|
|
216
|
+
throw e;
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
const connect = (adapter) => __async(this, null, function* () {
|
|
220
|
+
var _a;
|
|
221
|
+
if (isIosAndRedirectable()) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
yield disconnect();
|
|
225
|
+
let address;
|
|
226
|
+
let error;
|
|
227
|
+
let authState;
|
|
228
|
+
try {
|
|
229
|
+
address = yield connectBase(adapter, true);
|
|
162
230
|
if (address) {
|
|
163
231
|
try {
|
|
164
|
-
authState = yield login({ address, providerName: adapter.name });
|
|
232
|
+
authState = yield login({ address, providerId: (_a = getWallet(adapter.name)) == null ? void 0 : _a.internalId, providerName: adapter.name });
|
|
165
233
|
verificationMessage.current = authState.stage === "verify" ? authState.signatureVerificationMessage : void 0;
|
|
166
234
|
} catch (err) {
|
|
167
|
-
yield
|
|
235
|
+
yield disconnect();
|
|
168
236
|
address = void 0;
|
|
169
237
|
error = err;
|
|
170
238
|
}
|
|
@@ -178,6 +246,7 @@ function SolanaExternalWalletProvider({
|
|
|
178
246
|
break;
|
|
179
247
|
}
|
|
180
248
|
default: {
|
|
249
|
+
console.error("Solana connection error:", err.message);
|
|
181
250
|
error = "An unknown error occurred";
|
|
182
251
|
break;
|
|
183
252
|
}
|
|
@@ -185,6 +254,40 @@ function SolanaExternalWalletProvider({
|
|
|
185
254
|
}
|
|
186
255
|
return { address, error, authState };
|
|
187
256
|
});
|
|
257
|
+
const requestInfo = (providerId) => __async(this, null, function* () {
|
|
258
|
+
var _a, _b;
|
|
259
|
+
const wallet2 = wallets.find((w) => w.internalId === providerId);
|
|
260
|
+
const adapter = getAdapter((_a = wallet2.name) != null ? _a : "");
|
|
261
|
+
isLinkingAccount.current = true;
|
|
262
|
+
try {
|
|
263
|
+
const address = yield connectBase(adapter);
|
|
264
|
+
const externalWallet = {
|
|
265
|
+
address,
|
|
266
|
+
type: "SOLANA",
|
|
267
|
+
providerId: wallet2.internalId,
|
|
268
|
+
provider: wallet2.name
|
|
269
|
+
};
|
|
270
|
+
return externalWallet;
|
|
271
|
+
} catch (e) {
|
|
272
|
+
console.error("Error linking account:", e);
|
|
273
|
+
throw new Error((_b = e == null ? void 0 : e.message) != null ? _b : e);
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
const disconnectBase = (providerId) => __async(this, null, function* () {
|
|
277
|
+
var _a, _b;
|
|
278
|
+
const wallet2 = wallets.find((w) => w.internalId === providerId);
|
|
279
|
+
const adapter = getAdapter((_a = wallet2.name) != null ? _a : "");
|
|
280
|
+
if (!(adapter == null ? void 0 : adapter.connected)) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
isLinkingAccount.current = true;
|
|
284
|
+
try {
|
|
285
|
+
yield adapter.disconnect();
|
|
286
|
+
} catch (e) {
|
|
287
|
+
console.error("Error disconnecting wallet:", e);
|
|
288
|
+
throw new Error((_b = e == null ? void 0 : e.message) != null ? _b : e);
|
|
289
|
+
}
|
|
290
|
+
});
|
|
188
291
|
const getAdapter = (name) => {
|
|
189
292
|
var _a;
|
|
190
293
|
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 +303,12 @@ function SolanaExternalWalletProvider({
|
|
|
200
303
|
installed: adapter && ((adapter == null ? void 0 : adapter.readyState) === WalletReadyState.Installed || (adapter == null ? void 0 : adapter.readyState) === WalletReadyState.Loadable)
|
|
201
304
|
}, metaData);
|
|
202
305
|
});
|
|
203
|
-
const disconnect = () => __async(this, null, function* () {
|
|
204
|
-
yield _disconnect();
|
|
205
|
-
});
|
|
206
306
|
return /* @__PURE__ */ jsx(
|
|
207
307
|
SolanaExternalWalletContext.Provider,
|
|
208
308
|
{
|
|
209
309
|
value: useMemo(
|
|
210
|
-
() => ({ wallets, disconnect, signMessage, signVerificationMessage }),
|
|
211
|
-
[wallets, disconnect, signMessage, signVerificationMessage]
|
|
310
|
+
() => ({ wallets, disconnect, signMessage, signVerificationMessage, requestInfo, disconnectBase }),
|
|
311
|
+
[wallets, disconnect, signMessage, signVerificationMessage, requestInfo, disconnectBase]
|
|
212
312
|
),
|
|
213
313
|
children
|
|
214
314
|
}
|
|
@@ -216,5 +316,6 @@ function SolanaExternalWalletProvider({
|
|
|
216
316
|
}
|
|
217
317
|
export {
|
|
218
318
|
SolanaExternalWalletContext,
|
|
219
|
-
SolanaExternalWalletProvider
|
|
319
|
+
SolanaExternalWalletProvider,
|
|
320
|
+
defaultSolanaExternalWallet
|
|
220
321
|
};
|
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.22",
|
|
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.22",
|
|
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.22",
|
|
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": "e23258f6af4d3445bf4717a9e524c63e0088e159"
|
|
39
39
|
}
|