@getpara/solana-wallet-connectors 1.5.0 → 1.5.1
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.js +70 -30
- package/dist/index.js.br +0 -0
- package/dist/index.js.gz +0 -0
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,4 +1,40 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __spreadValues = (a, b) => {
|
|
8
|
+
for (var prop in b || (b = {}))
|
|
9
|
+
if (__hasOwnProp.call(b, prop))
|
|
10
|
+
__defNormalProp(a, prop, b[prop]);
|
|
11
|
+
if (__getOwnPropSymbols)
|
|
12
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
13
|
+
if (__propIsEnum.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
15
|
+
}
|
|
16
|
+
return a;
|
|
17
|
+
};
|
|
18
|
+
var __async = (__this, __arguments, generator) => {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
var fulfilled = (value) => {
|
|
21
|
+
try {
|
|
22
|
+
step(generator.next(value));
|
|
23
|
+
} catch (e) {
|
|
24
|
+
reject(e);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var rejected = (value) => {
|
|
28
|
+
try {
|
|
29
|
+
step(generator.throw(value));
|
|
30
|
+
} catch (e) {
|
|
31
|
+
reject(e);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
35
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
36
|
+
});
|
|
37
|
+
};
|
|
2
38
|
|
|
3
39
|
// src/providers/SolanaExternalWalletContext.tsx
|
|
4
40
|
import { createContext as createContext2, useEffect as useEffect2, useMemo as useMemo2 } from "react";
|
|
@@ -85,60 +121,62 @@ function SolanaExternalWalletProvider({ children, para, onSwitchWallet }) {
|
|
|
85
121
|
connecting
|
|
86
122
|
} = useWallet();
|
|
87
123
|
const { wallets: walletFns } = useParaSolana();
|
|
88
|
-
const reset =
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
};
|
|
92
|
-
const login =
|
|
124
|
+
const reset = () => __async(this, null, function* () {
|
|
125
|
+
yield _disconnect();
|
|
126
|
+
yield para.logout();
|
|
127
|
+
});
|
|
128
|
+
const login = (address, providerName) => __async(this, null, function* () {
|
|
93
129
|
try {
|
|
94
|
-
|
|
130
|
+
yield para.externalWalletLogin({ address, type: WalletType.SOLANA, provider: providerName });
|
|
95
131
|
} catch (err) {
|
|
96
|
-
|
|
132
|
+
yield reset();
|
|
97
133
|
throw "Error logging you in. Please try again.";
|
|
98
134
|
}
|
|
99
|
-
};
|
|
100
|
-
const switchWallet =
|
|
135
|
+
});
|
|
136
|
+
const switchWallet = (address) => __async(this, null, function* () {
|
|
137
|
+
var _a;
|
|
101
138
|
let error;
|
|
102
139
|
if (!address) {
|
|
103
|
-
|
|
140
|
+
yield para.logout();
|
|
104
141
|
} else {
|
|
105
142
|
try {
|
|
106
|
-
|
|
143
|
+
yield login(address, (_a = wallet == null ? void 0 : wallet.adapter) == null ? void 0 : _a.name);
|
|
107
144
|
} catch (err) {
|
|
108
145
|
error = err;
|
|
109
146
|
}
|
|
110
147
|
}
|
|
111
148
|
onSwitchWallet({ address, error });
|
|
112
|
-
};
|
|
149
|
+
});
|
|
113
150
|
useEffect2(() => {
|
|
114
|
-
|
|
151
|
+
var _a;
|
|
152
|
+
const storedExternalWallet = para.externalWallets[(_a = solanaAddress == null ? void 0 : solanaAddress.toString()) != null ? _a : ""];
|
|
115
153
|
if (!!solanaAddress && !storedExternalWallet) {
|
|
116
154
|
reset();
|
|
117
155
|
}
|
|
118
156
|
}, []);
|
|
119
157
|
useEffect2(() => {
|
|
120
158
|
const storedExternalWallet = Object.values(para.externalWallets || {})[0];
|
|
121
|
-
if (!connecting && storedExternalWallet
|
|
122
|
-
switchWallet(solanaAddress
|
|
159
|
+
if (!connecting && (storedExternalWallet == null ? void 0 : storedExternalWallet.type) === WalletType.SOLANA && (storedExternalWallet == null ? void 0 : storedExternalWallet.address) !== (solanaAddress == null ? void 0 : solanaAddress.toString())) {
|
|
160
|
+
switchWallet(solanaAddress == null ? void 0 : solanaAddress.toString());
|
|
123
161
|
}
|
|
124
162
|
}, [solanaAddress, connecting]);
|
|
125
|
-
const connect =
|
|
126
|
-
|
|
163
|
+
const connect = (adapter) => __async(this, null, function* () {
|
|
164
|
+
yield _disconnect();
|
|
127
165
|
if (!adapter) {
|
|
128
166
|
return { address: void 0, error: "Adapter not found." };
|
|
129
167
|
}
|
|
130
168
|
selectWallet(adapter.name);
|
|
131
|
-
|
|
169
|
+
yield new Promise((resolve) => setTimeout(resolve, 100));
|
|
132
170
|
let address;
|
|
133
171
|
let error;
|
|
134
172
|
try {
|
|
135
|
-
|
|
173
|
+
yield adapter.connect();
|
|
136
174
|
address = adapter.publicKey.toString();
|
|
137
175
|
if (address) {
|
|
138
176
|
try {
|
|
139
|
-
|
|
177
|
+
yield login(address, adapter.name);
|
|
140
178
|
} catch (err) {
|
|
141
|
-
|
|
179
|
+
yield _disconnect();
|
|
142
180
|
address = void 0;
|
|
143
181
|
error = err;
|
|
144
182
|
}
|
|
@@ -158,24 +196,26 @@ function SolanaExternalWalletProvider({ children, para, onSwitchWallet }) {
|
|
|
158
196
|
}
|
|
159
197
|
}
|
|
160
198
|
return { address, error };
|
|
199
|
+
});
|
|
200
|
+
const getAdapter = (name) => {
|
|
201
|
+
var _a;
|
|
202
|
+
return (_a = adapters.find((a) => a.adapter.name === "Mobile Wallet Adapter" ? a : a.adapter.name === name ? a : false)) == null ? void 0 : _a.adapter;
|
|
161
203
|
};
|
|
162
|
-
const getAdapter = (name) => adapters.find((a) => a.adapter.name === "Mobile Wallet Adapter" ? a : a.adapter.name === name ? a : false)?.adapter;
|
|
163
204
|
const wallets = walletFns.map((walletFn) => {
|
|
164
205
|
const metaData = walletFn();
|
|
165
206
|
const adapter = getAdapter(metaData.name);
|
|
166
|
-
return {
|
|
207
|
+
return __spreadValues({
|
|
167
208
|
connect: () => connect(adapter),
|
|
168
209
|
connectMobile: () => connect(adapter),
|
|
169
210
|
getQrUri: () => "",
|
|
170
211
|
type: WalletType.SOLANA,
|
|
171
|
-
installed: adapter && (adapter
|
|
172
|
-
|
|
173
|
-
|
|
212
|
+
installed: adapter && ((adapter == null ? void 0 : adapter.readyState) === WalletReadyState.Installed || (adapter == null ? void 0 : adapter.readyState) === WalletReadyState.Loadable)
|
|
213
|
+
}, metaData);
|
|
214
|
+
});
|
|
215
|
+
const disconnect = () => __async(this, null, function* () {
|
|
216
|
+
yield _disconnect();
|
|
217
|
+
typeof window !== void 0 && (window == null ? void 0 : window.location.reload());
|
|
174
218
|
});
|
|
175
|
-
const disconnect = async () => {
|
|
176
|
-
await _disconnect();
|
|
177
|
-
typeof window !== void 0 && window?.location.reload();
|
|
178
|
-
};
|
|
179
219
|
return /* @__PURE__ */ jsx2(SolanaExternalWalletContext.Provider, { value: useMemo2(() => ({ wallets, disconnect }), [wallets, disconnect]), children });
|
|
180
220
|
}
|
|
181
221
|
|
package/dist/index.js.br
CHANGED
|
Binary file
|
package/dist/index.js.gz
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/solana-wallet-connectors",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"./connectors": "./dist/wallets/connectors/index.js"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@getpara/react-sdk": "1.5.
|
|
12
|
+
"@getpara/react-sdk": "1.5.1"
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
15
15
|
"build": "rm -rf dist && yarn typegen && node ./scripts/build.mjs",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"dist",
|
|
38
38
|
"package.json"
|
|
39
39
|
],
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "f77e0f5e162a1672219b01dbf7c06a3baadd2f35"
|
|
41
41
|
}
|