@getpara/solana-wallet-connectors 2.24.0 → 2.26.0
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.
|
@@ -50,6 +50,7 @@ import bs58 from "bs58";
|
|
|
50
50
|
import { externalHooks } from "./externalHooks.js";
|
|
51
51
|
import { farcasterWallet } from "../wallets/connectors/index.js";
|
|
52
52
|
const CONNECT_EVENT_TIMEOUT_MS = 3e4;
|
|
53
|
+
const SIGN_MESSAGE_REF_WAIT_MS = 5e3;
|
|
53
54
|
const isInSolanaWalletDappBrowser = () => {
|
|
54
55
|
var _a, _b;
|
|
55
56
|
if (typeof window === "undefined") return false;
|
|
@@ -85,6 +86,15 @@ function SolanaExternalWalletProvider({
|
|
|
85
86
|
useEffect(() => {
|
|
86
87
|
walletRef.current = wallet;
|
|
87
88
|
}, [wallet]);
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
disconnectRef.current = disconnect;
|
|
91
|
+
}, [disconnect]);
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
solanaSignMessageRef.current = solanaSignMessage;
|
|
94
|
+
}, [solanaSignMessage]);
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
solanaAddressRef.current = solanaAddress == null ? void 0 : solanaAddress.toString();
|
|
97
|
+
}, [solanaAddress]);
|
|
88
98
|
const [isFarcasterSetup, setIsFarcasterSetup] = useState(false);
|
|
89
99
|
useEffect(() => {
|
|
90
100
|
if (!para.isSetup) {
|
|
@@ -102,19 +112,29 @@ function SolanaExternalWalletProvider({
|
|
|
102
112
|
return (_a = solanaAddressRef.current) == null ? void 0 : _a.toString();
|
|
103
113
|
}),
|
|
104
114
|
signMessage: (_0) => __async(this, [_0], function* ({ message }) {
|
|
115
|
+
var _a, _b, _c, _d;
|
|
105
116
|
try {
|
|
117
|
+
const start = Date.now();
|
|
118
|
+
let fn = (_a = solanaSignMessageRef.current) != null ? _a : solanaSignMessage;
|
|
119
|
+
while (!fn) {
|
|
120
|
+
if (Date.now() - start > SIGN_MESSAGE_REF_WAIT_MS) {
|
|
121
|
+
throw new Error("Solana signMessage unavailable");
|
|
122
|
+
}
|
|
123
|
+
yield new Promise((resolve) => setTimeout(resolve, 100));
|
|
124
|
+
fn = (_b = solanaSignMessageRef.current) != null ? _b : solanaSignMessage;
|
|
125
|
+
}
|
|
106
126
|
const encodedMessage = new TextEncoder().encode(message);
|
|
107
|
-
const signature = yield
|
|
127
|
+
const signature = yield fn(encodedMessage);
|
|
108
128
|
return {
|
|
109
129
|
signature: bs58.encode(signature)
|
|
110
130
|
};
|
|
111
131
|
} catch (e) {
|
|
112
132
|
console.error(e);
|
|
113
|
-
if (e.message.includes("User rejected the request")) {
|
|
133
|
+
if ((_c = e == null ? void 0 : e.message) == null ? void 0 : _c.includes("User rejected the request")) {
|
|
114
134
|
throw new Error("Signature request rejected");
|
|
115
135
|
}
|
|
116
|
-
console.error("Solana signature error:", e.message);
|
|
117
|
-
throw new Error(
|
|
136
|
+
console.error("Solana signature error:", e == null ? void 0 : e.message);
|
|
137
|
+
throw new Error(`Solana signMessage failed: ${(_d = e == null ? void 0 : e.message) != null ? _d : "unknown"}`);
|
|
118
138
|
}
|
|
119
139
|
}),
|
|
120
140
|
watchDisconnection: (callback) => {
|
|
@@ -171,12 +191,6 @@ function SolanaExternalWalletProvider({
|
|
|
171
191
|
});
|
|
172
192
|
initializeConfig();
|
|
173
193
|
}, [para.isSetup]);
|
|
174
|
-
useEffect(() => {
|
|
175
|
-
solanaSignMessageRef.current = solanaSignMessage;
|
|
176
|
-
}, [solanaSignMessage]);
|
|
177
|
-
useEffect(() => {
|
|
178
|
-
solanaAddressRef.current = solanaAddress == null ? void 0 : solanaAddress.toString();
|
|
179
|
-
}, [solanaAddress]);
|
|
180
194
|
const signMessage = (_0) => __async(this, [_0], function* ({ message }) {
|
|
181
195
|
var _a, _b, _c, _d;
|
|
182
196
|
try {
|
|
@@ -287,7 +301,11 @@ function SolanaExternalWalletProvider({
|
|
|
287
301
|
if (isAndroid() && (adapter == null ? void 0 : adapter.name) === "Mobile Wallet Adapter") {
|
|
288
302
|
return;
|
|
289
303
|
}
|
|
290
|
-
|
|
304
|
+
if (adapter && (wallet == null ? void 0 : wallet.adapter) && wallet.adapter.name !== adapter.name) {
|
|
305
|
+
yield disconnect();
|
|
306
|
+
} else if ((wallet == null ? void 0 : wallet.adapter) && !wallet.adapter.connected && wallet.adapter.publicKey) {
|
|
307
|
+
yield disconnect();
|
|
308
|
+
}
|
|
291
309
|
let address;
|
|
292
310
|
let error;
|
|
293
311
|
let authState;
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/solana-wallet-connectors",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.26.0",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@getpara/react-common": "2.
|
|
6
|
-
"@getpara/web-sdk": "2.
|
|
5
|
+
"@getpara/react-common": "2.26.0",
|
|
6
|
+
"@getpara/web-sdk": "2.26.0",
|
|
7
7
|
"bs58": "^6.0.0"
|
|
8
8
|
},
|
|
9
9
|
"devDependencies": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"dist",
|
|
24
24
|
"package.json"
|
|
25
25
|
],
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "02eb43f55b1c5f8bed6685940b6344551610f42a",
|
|
27
27
|
"main": "dist/index.js",
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"@farcaster/mini-app-solana": "^1.0.5",
|