@moon-x/react-sdk 0.11.0 → 0.12.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.
- package/README.md +4 -2
- package/dist/{base-wallet-CzJLpndu.d.mts → base-wallet-SjY7osPg.d.mts} +1 -1
- package/dist/{base-wallet-CzJLpndu.d.ts → base-wallet-SjY7osPg.d.ts} +1 -1
- package/dist/chunk-E7BPHFN5.mjs +484 -0
- package/dist/chunk-JHLZS7ZT.js +702 -0
- package/dist/{ethereum-Eg3cJKce.d.ts → ethereum-B0bChy5v.d.ts} +1 -1
- package/dist/{ethereum-lovLlqC2.d.mts → ethereum-DIGoC1pP.d.mts} +1 -1
- package/dist/index.d.mts +171 -6
- package/dist/index.d.ts +171 -6
- package/dist/index.js +12820 -16009
- package/dist/index.mjs +9677 -12394
- package/dist/{solana-C9rN8lxH.d.ts → solana-D2QJgky5.d.ts} +1 -1
- package/dist/{solana-BVrNImZ1.d.mts → solana-nqJKbWX0.d.mts} +1 -1
- package/dist/tron-KzJqr-zA.d.mts +77 -0
- package/dist/tron-KzJqr-zA.d.ts +77 -0
- package/dist/wallets/ethereum.d.mts +2 -2
- package/dist/wallets/ethereum.d.ts +2 -2
- package/dist/wallets/solana.d.mts +2 -2
- package/dist/wallets/solana.d.ts +2 -2
- package/dist/wallets/tron.d.mts +2 -0
- package/dist/wallets/tron.d.ts +2 -0
- package/dist/wallets/tron.js +15 -0
- package/dist/wallets/tron.mjs +4 -0
- package/package.json +10 -6
package/README.md
CHANGED
|
@@ -93,7 +93,7 @@ function SignDemo() {
|
|
|
93
93
|
| `walletChainType` | `"ethereum" \| "solana" \| "ethereum-or-solana"` | Which wallet type to create at signup. |
|
|
94
94
|
| `chains` | `ChainConfigItem[]` | Unified RPC / chain config for **both** EVM and Solana. Each element is a bare viem `Chain` (use its built-in RPC), an `{ chain, rpcUrl?, wsUrl? }` EVM entry (to override the RPC), or a `{ id, rpcUrl, wsUrl? }` Solana entry. Common viem chains are re-exported by this package. See `docs/rpc-configuration.md`. |
|
|
95
95
|
| `defaultChain` | `string \| number` | Which configured chain is the default. Referenced by alias, CAIP-2 id, or numeric chainId — e.g. `"eth:base"`, `"eip155:8453"`, `8453`, `"solana:mainnet"`. Defaults to the first entry in `chains`. |
|
|
96
|
-
| `walletConnect.projectId` | `string` | WalletConnect v2 project ID
|
|
96
|
+
| `walletConnect.projectId` | `string` | WalletConnect v2 project ID. When set, the connect-wallet modal offers a **WalletConnect (EVM)** option (QR) so mobile / non-injected wallets can connect using the configured/default EVM chain. |
|
|
97
97
|
| `emailConfig`, `passkeyEnrollConfig`, `signMessageConfig`, `signTransactionConfig`, `sendTransactionConfig`, `exportKeyConfig` | various | Per-flow UI overrides — titles, button text, etc. |
|
|
98
98
|
| `security` | `Record<string, never>` | Reserved for future per-app security knobs. The previously-configurable `assertionCacheTtlMs` was removed in Phase 4 of the presence-token gating work — every sensitive op now does a fresh WebAuthn ceremony and mints scope-bound single-use JWTs via the iframe's internal orchestrator, so there is no parent-side cache left to configure. See [Security](#security) below. |
|
|
99
99
|
|
|
@@ -125,7 +125,9 @@ function SignDemo() {
|
|
|
125
125
|
| `useWallets()` | `{ wallets, loading }` — both Ethereum and Solana, fetched once on mount. |
|
|
126
126
|
| `useCreateWallet()` | Mint a new MPC wallet. Pass `{ walletType: "ethereum" \| "solana" }`. |
|
|
127
127
|
| `useImportKey()` | Two-mode: headless if you pass a key, modal-driven if you don't. |
|
|
128
|
-
| `useConnectWallet()` |
|
|
128
|
+
| `useConnectWallet()` | Prebuilt **connect-wallet modal**. Connects an external wallet client-side: injected EVM (EIP-6963), Solana (Wallet Standard), and EVM WalletConnect (QR, when `walletConnect.projectId` is set). Connect-only — `mode` defaults to `"connect"`; `"signIn"`/`"link"` (SIWE/SIWS authentication) are **not implemented yet** and reject rather than silently succeed. |
|
|
129
|
+
| `useExternalWallets({ chain? })` | **Headless** external-wallet connection: `{ wallets, connect, disconnect, connected, status, refresh }`. Covers injected EVM + Solana Wallet Standard. For WalletConnect, use the modal or the standalone `connectWalletConnect()`. |
|
|
130
|
+
| `useConnectedExternalWallets()` | The external wallets connected this session (shared app-wide) for a picker / account switcher; each exposes `signMessage`. |
|
|
129
131
|
| `useAttachOAuth()` / `useDetachOAuth()` | Link / unlink an OAuth provider on an existing user. |
|
|
130
132
|
|
|
131
133
|
### Per-chain signing — `/ethereum` and `/solana` subpaths
|
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
3
|
+
try {
|
|
4
|
+
var info = gen[key](arg);
|
|
5
|
+
var value = info.value;
|
|
6
|
+
} catch (error) {
|
|
7
|
+
reject(error);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
if (info.done) {
|
|
11
|
+
resolve(value);
|
|
12
|
+
} else {
|
|
13
|
+
Promise.resolve(value).then(_next, _throw);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function _async_to_generator(fn) {
|
|
17
|
+
return function() {
|
|
18
|
+
var self = this, args = arguments;
|
|
19
|
+
return new Promise(function(resolve, reject) {
|
|
20
|
+
var gen = fn.apply(self, args);
|
|
21
|
+
function _next(value) {
|
|
22
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
23
|
+
}
|
|
24
|
+
function _throw(err) {
|
|
25
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
26
|
+
}
|
|
27
|
+
_next(undefined);
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function _instanceof(left, right) {
|
|
32
|
+
"@swc/helpers - instanceof";
|
|
33
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
34
|
+
return !!right[Symbol.hasInstance](left);
|
|
35
|
+
} else {
|
|
36
|
+
return left instanceof right;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function _ts_generator(thisArg, body) {
|
|
40
|
+
var f, y, t, _ = {
|
|
41
|
+
label: 0,
|
|
42
|
+
sent: function() {
|
|
43
|
+
if (t[0] & 1) throw t[1];
|
|
44
|
+
return t[1];
|
|
45
|
+
},
|
|
46
|
+
trys: [],
|
|
47
|
+
ops: []
|
|
48
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
49
|
+
return d(g, "next", {
|
|
50
|
+
value: verb(0)
|
|
51
|
+
}), d(g, "throw", {
|
|
52
|
+
value: verb(1)
|
|
53
|
+
}), d(g, "return", {
|
|
54
|
+
value: verb(2)
|
|
55
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
56
|
+
value: function() {
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
}), g;
|
|
60
|
+
function verb(n) {
|
|
61
|
+
return function(v) {
|
|
62
|
+
return step([
|
|
63
|
+
n,
|
|
64
|
+
v
|
|
65
|
+
]);
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function step(op) {
|
|
69
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
70
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
71
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
72
|
+
if (y = 0, t) op = [
|
|
73
|
+
op[0] & 2,
|
|
74
|
+
t.value
|
|
75
|
+
];
|
|
76
|
+
switch(op[0]){
|
|
77
|
+
case 0:
|
|
78
|
+
case 1:
|
|
79
|
+
t = op;
|
|
80
|
+
break;
|
|
81
|
+
case 4:
|
|
82
|
+
_.label++;
|
|
83
|
+
return {
|
|
84
|
+
value: op[1],
|
|
85
|
+
done: false
|
|
86
|
+
};
|
|
87
|
+
case 5:
|
|
88
|
+
_.label++;
|
|
89
|
+
y = op[1];
|
|
90
|
+
op = [
|
|
91
|
+
0
|
|
92
|
+
];
|
|
93
|
+
continue;
|
|
94
|
+
case 7:
|
|
95
|
+
op = _.ops.pop();
|
|
96
|
+
_.trys.pop();
|
|
97
|
+
continue;
|
|
98
|
+
default:
|
|
99
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
100
|
+
_ = 0;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
104
|
+
_.label = op[1];
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
108
|
+
_.label = t[1];
|
|
109
|
+
t = op;
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
if (t && _.label < t[2]) {
|
|
113
|
+
_.label = t[2];
|
|
114
|
+
_.ops.push(op);
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
if (t[2]) _.ops.pop();
|
|
118
|
+
_.trys.pop();
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
op = body.call(thisArg, _);
|
|
122
|
+
} catch (e) {
|
|
123
|
+
op = [
|
|
124
|
+
6,
|
|
125
|
+
e
|
|
126
|
+
];
|
|
127
|
+
y = 0;
|
|
128
|
+
} finally{
|
|
129
|
+
f = t = 0;
|
|
130
|
+
}
|
|
131
|
+
if (op[0] & 5) throw op[1];
|
|
132
|
+
return {
|
|
133
|
+
value: op[0] ? op[1] : void 0,
|
|
134
|
+
done: true
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
import { __export, dispatchSignOp, shouldShowWalletUI, useAuthSDK } from "./chunk-PCEN5CH6.mjs";
|
|
139
|
+
// src/wallets/tron.ts
|
|
140
|
+
var tron_exports = {};
|
|
141
|
+
__export(tron_exports, {
|
|
142
|
+
useCreateWallet: function useCreateWallet1() {
|
|
143
|
+
return useCreateWallet;
|
|
144
|
+
},
|
|
145
|
+
useExportKey: function useExportKey1() {
|
|
146
|
+
return useExportKey;
|
|
147
|
+
},
|
|
148
|
+
useGetBalance: function useGetBalance1() {
|
|
149
|
+
return useGetBalance;
|
|
150
|
+
},
|
|
151
|
+
useImportKey: function useImportKey1() {
|
|
152
|
+
return useImportKey;
|
|
153
|
+
},
|
|
154
|
+
useSendTransaction: function useSendTransaction1() {
|
|
155
|
+
return useSendTransaction;
|
|
156
|
+
},
|
|
157
|
+
useSignMessage: function useSignMessage1() {
|
|
158
|
+
return useSignMessage;
|
|
159
|
+
},
|
|
160
|
+
useSignTransaction: function useSignTransaction1() {
|
|
161
|
+
return useSignTransaction;
|
|
162
|
+
},
|
|
163
|
+
useWallets: function useWallets1() {
|
|
164
|
+
return useWallets;
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
import { useGetBalance as useSharedTronGetBalance, useSendTransaction as useSharedTronSendTransaction, useSignMessage as useSharedTronSignMessage, useSignTransaction as useSharedTronSignTransaction } from "@moon-x/core/react/tron";
|
|
168
|
+
import { resolveRpcUrl, resolveTronChainEntry } from "@moon-x/core/lib";
|
|
169
|
+
import { useCreateWallet as useSharedCreateWallet, useImportKey as useSharedImportKey, useWallets as useSharedWallets } from "@moon-x/core/react";
|
|
170
|
+
var useCreateWallet = function useCreateWallet(callbacks) {
|
|
171
|
+
var createWallet = useSharedCreateWallet().createWallet;
|
|
172
|
+
return {
|
|
173
|
+
createWallet: function createWallet1(options) {
|
|
174
|
+
return _async_to_generator(function() {
|
|
175
|
+
var _callbacks_onSuccess, response, error, _callbacks_onError, errorObj;
|
|
176
|
+
return _ts_generator(this, function(_state) {
|
|
177
|
+
switch(_state.label){
|
|
178
|
+
case 0:
|
|
179
|
+
_state.trys.push([
|
|
180
|
+
0,
|
|
181
|
+
2,
|
|
182
|
+
,
|
|
183
|
+
3
|
|
184
|
+
]);
|
|
185
|
+
return [
|
|
186
|
+
4,
|
|
187
|
+
createWallet("tron", options)
|
|
188
|
+
];
|
|
189
|
+
case 1:
|
|
190
|
+
response = _state.sent();
|
|
191
|
+
callbacks === null || callbacks === void 0 ? void 0 : (_callbacks_onSuccess = callbacks.onSuccess) === null || _callbacks_onSuccess === void 0 ? void 0 : _callbacks_onSuccess.call(callbacks, response);
|
|
192
|
+
return [
|
|
193
|
+
2,
|
|
194
|
+
response
|
|
195
|
+
];
|
|
196
|
+
case 2:
|
|
197
|
+
error = _state.sent();
|
|
198
|
+
errorObj = _instanceof(error, Error) ? error : new Error("Unknown error");
|
|
199
|
+
callbacks === null || callbacks === void 0 ? void 0 : (_callbacks_onError = callbacks.onError) === null || _callbacks_onError === void 0 ? void 0 : _callbacks_onError.call(callbacks, errorObj);
|
|
200
|
+
throw errorObj;
|
|
201
|
+
case 3:
|
|
202
|
+
return [
|
|
203
|
+
2
|
|
204
|
+
];
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
})();
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
var useWallets = function useWallets() {
|
|
212
|
+
var _r_error;
|
|
213
|
+
var r = useSharedWallets("tron");
|
|
214
|
+
return {
|
|
215
|
+
wallets: r.wallets,
|
|
216
|
+
loading: r.loading,
|
|
217
|
+
error: (_r_error = r.error) !== null && _r_error !== void 0 ? _r_error : void 0,
|
|
218
|
+
refetch: r.refetch
|
|
219
|
+
};
|
|
220
|
+
};
|
|
221
|
+
var useSignMessage = function useSignMessage() {
|
|
222
|
+
var coreSDK = useAuthSDK();
|
|
223
|
+
var shared = useSharedTronSignMessage();
|
|
224
|
+
return {
|
|
225
|
+
signMessage: function signMessage(params) {
|
|
226
|
+
return _async_to_generator(function() {
|
|
227
|
+
var _params_options, _coreSDK_config_signMessageConfig, _coreSDK_config, showWalletUI, error;
|
|
228
|
+
return _ts_generator(this, function(_state) {
|
|
229
|
+
switch(_state.label){
|
|
230
|
+
case 0:
|
|
231
|
+
_state.trys.push([
|
|
232
|
+
0,
|
|
233
|
+
2,
|
|
234
|
+
,
|
|
235
|
+
3
|
|
236
|
+
]);
|
|
237
|
+
showWalletUI = shouldShowWalletUI((_params_options = params.options) === null || _params_options === void 0 ? void 0 : _params_options.uiOptions, (_coreSDK_config = coreSDK.config) === null || _coreSDK_config === void 0 ? void 0 : (_coreSDK_config_signMessageConfig = _coreSDK_config.signMessageConfig) === null || _coreSDK_config_signMessageConfig === void 0 ? void 0 : _coreSDK_config_signMessageConfig.uiConfig);
|
|
238
|
+
return [
|
|
239
|
+
4,
|
|
240
|
+
dispatchSignOp({
|
|
241
|
+
params: params,
|
|
242
|
+
showWalletUI: showWalletUI,
|
|
243
|
+
headless: shared.signMessage,
|
|
244
|
+
withUI: coreSDK.signTronMessageWithUI
|
|
245
|
+
})
|
|
246
|
+
];
|
|
247
|
+
case 1:
|
|
248
|
+
return [
|
|
249
|
+
2,
|
|
250
|
+
_state.sent()
|
|
251
|
+
];
|
|
252
|
+
case 2:
|
|
253
|
+
error = _state.sent();
|
|
254
|
+
throw new Error("Sign message failed: ".concat(_instanceof(error, Error) ? error.message : "Unknown error"));
|
|
255
|
+
case 3:
|
|
256
|
+
return [
|
|
257
|
+
2
|
|
258
|
+
];
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
})();
|
|
262
|
+
},
|
|
263
|
+
loading: false,
|
|
264
|
+
error: void 0
|
|
265
|
+
};
|
|
266
|
+
};
|
|
267
|
+
var useSignTransaction = function useSignTransaction() {
|
|
268
|
+
var coreSDK = useAuthSDK();
|
|
269
|
+
var shared = useSharedTronSignTransaction();
|
|
270
|
+
return {
|
|
271
|
+
signTransaction: function signTransaction(params) {
|
|
272
|
+
return _async_to_generator(function() {
|
|
273
|
+
var _params_options, _coreSDK_config_signTransactionConfig, _coreSDK_config, showWalletUI, error;
|
|
274
|
+
return _ts_generator(this, function(_state) {
|
|
275
|
+
switch(_state.label){
|
|
276
|
+
case 0:
|
|
277
|
+
_state.trys.push([
|
|
278
|
+
0,
|
|
279
|
+
2,
|
|
280
|
+
,
|
|
281
|
+
3
|
|
282
|
+
]);
|
|
283
|
+
showWalletUI = shouldShowWalletUI((_params_options = params.options) === null || _params_options === void 0 ? void 0 : _params_options.uiOptions, (_coreSDK_config = coreSDK.config) === null || _coreSDK_config === void 0 ? void 0 : (_coreSDK_config_signTransactionConfig = _coreSDK_config.signTransactionConfig) === null || _coreSDK_config_signTransactionConfig === void 0 ? void 0 : _coreSDK_config_signTransactionConfig.uiConfig);
|
|
284
|
+
return [
|
|
285
|
+
4,
|
|
286
|
+
dispatchSignOp({
|
|
287
|
+
params: params,
|
|
288
|
+
showWalletUI: showWalletUI,
|
|
289
|
+
headless: shared.signTransaction,
|
|
290
|
+
withUI: coreSDK.signTronTransactionWithUI
|
|
291
|
+
})
|
|
292
|
+
];
|
|
293
|
+
case 1:
|
|
294
|
+
return [
|
|
295
|
+
2,
|
|
296
|
+
_state.sent()
|
|
297
|
+
];
|
|
298
|
+
case 2:
|
|
299
|
+
error = _state.sent();
|
|
300
|
+
throw new Error("Sign transaction failed: ".concat(_instanceof(error, Error) ? error.message : "Unknown error"));
|
|
301
|
+
case 3:
|
|
302
|
+
return [
|
|
303
|
+
2
|
|
304
|
+
];
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
})();
|
|
308
|
+
},
|
|
309
|
+
loading: false,
|
|
310
|
+
error: void 0
|
|
311
|
+
};
|
|
312
|
+
};
|
|
313
|
+
var useSendTransaction = function useSendTransaction() {
|
|
314
|
+
var coreSDK = useAuthSDK();
|
|
315
|
+
var shared = useSharedTronSendTransaction();
|
|
316
|
+
return {
|
|
317
|
+
// Sign + broadcast via the configured fullnode. With showWalletUI the
|
|
318
|
+
// sign-transaction modal previews the decoded signed bytes and the
|
|
319
|
+
// broadcast happens after the user confirms.
|
|
320
|
+
sendTransaction: function sendTransaction(params) {
|
|
321
|
+
return _async_to_generator(function() {
|
|
322
|
+
var _params_rpcUrl, _coreSDK_config, _coreSDK_config1, _params_options, _coreSDK_config_sendTransactionConfig, _coreSDK_config2, entry, rpcUrl, _params_chain, showWalletUI, error;
|
|
323
|
+
return _ts_generator(this, function(_state) {
|
|
324
|
+
switch(_state.label){
|
|
325
|
+
case 0:
|
|
326
|
+
_state.trys.push([
|
|
327
|
+
0,
|
|
328
|
+
2,
|
|
329
|
+
,
|
|
330
|
+
3
|
|
331
|
+
]);
|
|
332
|
+
entry = resolveTronChainEntry((_coreSDK_config = coreSDK.config) === null || _coreSDK_config === void 0 ? void 0 : _coreSDK_config.chains, params.chain, (_coreSDK_config1 = coreSDK.config) === null || _coreSDK_config1 === void 0 ? void 0 : _coreSDK_config1.defaultChain);
|
|
333
|
+
rpcUrl = (_params_rpcUrl = params.rpcUrl) !== null && _params_rpcUrl !== void 0 ? _params_rpcUrl : entry ? resolveRpcUrl(entry) : void 0;
|
|
334
|
+
if (!rpcUrl) {
|
|
335
|
+
;
|
|
336
|
+
throw new Error('No fullnode URL for chain "'.concat((_params_chain = params.chain) !== null && _params_chain !== void 0 ? _params_chain : "tron", '". Add a tron entry to `chains` in MoonXProvider config, or pass an `rpcUrl`.'));
|
|
337
|
+
}
|
|
338
|
+
showWalletUI = shouldShowWalletUI((_params_options = params.options) === null || _params_options === void 0 ? void 0 : _params_options.uiOptions, (_coreSDK_config2 = coreSDK.config) === null || _coreSDK_config2 === void 0 ? void 0 : (_coreSDK_config_sendTransactionConfig = _coreSDK_config2.sendTransactionConfig) === null || _coreSDK_config_sendTransactionConfig === void 0 ? void 0 : _coreSDK_config_sendTransactionConfig.uiConfig);
|
|
339
|
+
return [
|
|
340
|
+
4,
|
|
341
|
+
dispatchSignOp({
|
|
342
|
+
params: {
|
|
343
|
+
transaction: params.transaction,
|
|
344
|
+
wallet: params.wallet,
|
|
345
|
+
rpcUrl: rpcUrl,
|
|
346
|
+
options: params.options
|
|
347
|
+
},
|
|
348
|
+
showWalletUI: showWalletUI,
|
|
349
|
+
headless: shared.sendTransaction,
|
|
350
|
+
withUI: coreSDK.sendTronTransactionWithUI
|
|
351
|
+
})
|
|
352
|
+
];
|
|
353
|
+
case 1:
|
|
354
|
+
return [
|
|
355
|
+
2,
|
|
356
|
+
_state.sent()
|
|
357
|
+
];
|
|
358
|
+
case 2:
|
|
359
|
+
error = _state.sent();
|
|
360
|
+
throw new Error("Send transaction failed: ".concat(_instanceof(error, Error) ? error.message : "Unknown error"));
|
|
361
|
+
case 3:
|
|
362
|
+
return [
|
|
363
|
+
2
|
|
364
|
+
];
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
})();
|
|
368
|
+
},
|
|
369
|
+
loading: false,
|
|
370
|
+
error: void 0
|
|
371
|
+
};
|
|
372
|
+
};
|
|
373
|
+
var useGetBalance = function useGetBalance() {
|
|
374
|
+
var coreSDK = useAuthSDK();
|
|
375
|
+
var shared = useSharedTronGetBalance();
|
|
376
|
+
return {
|
|
377
|
+
getBalance: function getBalance(params) {
|
|
378
|
+
return _async_to_generator(function() {
|
|
379
|
+
var _params_rpcUrl, _coreSDK_config, _coreSDK_config1, entry, rpcUrl, _params_chain, error;
|
|
380
|
+
return _ts_generator(this, function(_state) {
|
|
381
|
+
switch(_state.label){
|
|
382
|
+
case 0:
|
|
383
|
+
_state.trys.push([
|
|
384
|
+
0,
|
|
385
|
+
2,
|
|
386
|
+
,
|
|
387
|
+
3
|
|
388
|
+
]);
|
|
389
|
+
entry = resolveTronChainEntry((_coreSDK_config = coreSDK.config) === null || _coreSDK_config === void 0 ? void 0 : _coreSDK_config.chains, params.chain, (_coreSDK_config1 = coreSDK.config) === null || _coreSDK_config1 === void 0 ? void 0 : _coreSDK_config1.defaultChain);
|
|
390
|
+
rpcUrl = (_params_rpcUrl = params.rpcUrl) !== null && _params_rpcUrl !== void 0 ? _params_rpcUrl : entry ? resolveRpcUrl(entry) : void 0;
|
|
391
|
+
if (!rpcUrl) {
|
|
392
|
+
;
|
|
393
|
+
throw new Error('No fullnode URL for chain "'.concat((_params_chain = params.chain) !== null && _params_chain !== void 0 ? _params_chain : "tron", '". Add a tron entry to `chains` in MoonXProvider config, or pass an `rpcUrl`.'));
|
|
394
|
+
}
|
|
395
|
+
return [
|
|
396
|
+
4,
|
|
397
|
+
shared.getBalance({
|
|
398
|
+
wallet: params.wallet,
|
|
399
|
+
rpcUrl: rpcUrl
|
|
400
|
+
})
|
|
401
|
+
];
|
|
402
|
+
case 1:
|
|
403
|
+
return [
|
|
404
|
+
2,
|
|
405
|
+
_state.sent()
|
|
406
|
+
];
|
|
407
|
+
case 2:
|
|
408
|
+
error = _state.sent();
|
|
409
|
+
throw new Error("Get balance failed: ".concat(_instanceof(error, Error) ? error.message : "Unknown error"));
|
|
410
|
+
case 3:
|
|
411
|
+
return [
|
|
412
|
+
2
|
|
413
|
+
];
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
})();
|
|
417
|
+
},
|
|
418
|
+
loading: false,
|
|
419
|
+
error: void 0
|
|
420
|
+
};
|
|
421
|
+
};
|
|
422
|
+
var useExportKey = function useExportKey() {
|
|
423
|
+
var coreSDK = useAuthSDK();
|
|
424
|
+
return {
|
|
425
|
+
exportKey: function exportKey(param) {
|
|
426
|
+
var wallet = param.wallet;
|
|
427
|
+
return _async_to_generator(function() {
|
|
428
|
+
return _ts_generator(this, function(_state) {
|
|
429
|
+
return [
|
|
430
|
+
2,
|
|
431
|
+
coreSDK.exportKey(wallet)
|
|
432
|
+
];
|
|
433
|
+
});
|
|
434
|
+
})();
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
};
|
|
438
|
+
var useImportKey = function useImportKey() {
|
|
439
|
+
var _useSharedImportKey = useSharedImportKey(), sharedImportKey = _useSharedImportKey.importKey;
|
|
440
|
+
var coreSDK = useAuthSDK();
|
|
441
|
+
return {
|
|
442
|
+
// Same two-mode contract as the ethereum/solana hooks: pass `key`
|
|
443
|
+
// for headless (delegates to the shared hook), omit it for the
|
|
444
|
+
// SDK's ImportWallet modal. Both branches return
|
|
445
|
+
// `{ wallet: PublicWallet }`; unwrap so consumers can read
|
|
446
|
+
// `wallet.public_address` directly.
|
|
447
|
+
importKey: function importKey(params) {
|
|
448
|
+
return _async_to_generator(function() {
|
|
449
|
+
var result2, result;
|
|
450
|
+
return _ts_generator(this, function(_state) {
|
|
451
|
+
switch(_state.label){
|
|
452
|
+
case 0:
|
|
453
|
+
if (!((params === null || params === void 0 ? void 0 : params.key) !== void 0)) return [
|
|
454
|
+
3,
|
|
455
|
+
2
|
|
456
|
+
];
|
|
457
|
+
return [
|
|
458
|
+
4,
|
|
459
|
+
sharedImportKey("tron", params.key)
|
|
460
|
+
];
|
|
461
|
+
case 1:
|
|
462
|
+
result2 = _state.sent();
|
|
463
|
+
return [
|
|
464
|
+
2,
|
|
465
|
+
result2.wallet
|
|
466
|
+
];
|
|
467
|
+
case 2:
|
|
468
|
+
return [
|
|
469
|
+
4,
|
|
470
|
+
coreSDK.importKey("tron", void 0)
|
|
471
|
+
];
|
|
472
|
+
case 3:
|
|
473
|
+
result = _state.sent();
|
|
474
|
+
return [
|
|
475
|
+
2,
|
|
476
|
+
result.wallet
|
|
477
|
+
];
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
})();
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
};
|
|
484
|
+
export { useCreateWallet, useWallets, useSignMessage, useSignTransaction, useSendTransaction, useGetBalance, useExportKey, useImportKey, tron_exports };
|