@movebridge/react 0.0.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/LICENSE +0 -0
- package/dist/index.d.mts +446 -0
- package/dist/index.d.ts +446 -0
- package/dist/index.js +738 -0
- package/dist/index.mjs +703 -0
- package/package.json +62 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,738 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
AddressDisplay: () => AddressDisplay,
|
|
24
|
+
MovementContext: () => MovementContext,
|
|
25
|
+
MovementProvider: () => MovementProvider,
|
|
26
|
+
NetworkSwitcher: () => NetworkSwitcher,
|
|
27
|
+
WalletButton: () => WalletButton,
|
|
28
|
+
WalletModal: () => WalletModal,
|
|
29
|
+
useBalance: () => useBalance,
|
|
30
|
+
useContract: () => useContract,
|
|
31
|
+
useMovement: () => useMovement,
|
|
32
|
+
useMovementContext: () => useMovementContext,
|
|
33
|
+
useTransaction: () => useTransaction,
|
|
34
|
+
useWaitForTransaction: () => useWaitForTransaction
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
|
37
|
+
|
|
38
|
+
// src/context.tsx
|
|
39
|
+
var import_react = require("react");
|
|
40
|
+
var import_core = require("@movebridge/core");
|
|
41
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
42
|
+
var MovementContext = (0, import_react.createContext)(null);
|
|
43
|
+
function MovementProvider({
|
|
44
|
+
network,
|
|
45
|
+
autoConnect = false,
|
|
46
|
+
onError,
|
|
47
|
+
children
|
|
48
|
+
}) {
|
|
49
|
+
const [movement, setMovement] = (0, import_react.useState)(null);
|
|
50
|
+
const [walletState, setWalletState] = (0, import_react.useState)({
|
|
51
|
+
connected: false,
|
|
52
|
+
address: null,
|
|
53
|
+
publicKey: null
|
|
54
|
+
});
|
|
55
|
+
const [connecting, setConnecting] = (0, import_react.useState)(false);
|
|
56
|
+
const [wallets, setWallets] = (0, import_react.useState)([]);
|
|
57
|
+
const [currentWallet, setCurrentWallet] = (0, import_react.useState)(null);
|
|
58
|
+
(0, import_react.useEffect)(() => {
|
|
59
|
+
const sdk = new import_core.Movement({
|
|
60
|
+
network,
|
|
61
|
+
autoConnect
|
|
62
|
+
});
|
|
63
|
+
setMovement(sdk);
|
|
64
|
+
const detected = sdk.wallet.detectWallets();
|
|
65
|
+
setWallets(detected);
|
|
66
|
+
const handleConnect = (address) => {
|
|
67
|
+
setWalletState((prev) => ({
|
|
68
|
+
...prev,
|
|
69
|
+
connected: true,
|
|
70
|
+
address
|
|
71
|
+
}));
|
|
72
|
+
setConnecting(false);
|
|
73
|
+
};
|
|
74
|
+
const handleDisconnect = () => {
|
|
75
|
+
setWalletState({
|
|
76
|
+
connected: false,
|
|
77
|
+
address: null,
|
|
78
|
+
publicKey: null
|
|
79
|
+
});
|
|
80
|
+
setCurrentWallet(null);
|
|
81
|
+
};
|
|
82
|
+
const handleAccountChanged = (newAddress) => {
|
|
83
|
+
setWalletState((prev) => ({
|
|
84
|
+
...prev,
|
|
85
|
+
address: newAddress
|
|
86
|
+
}));
|
|
87
|
+
};
|
|
88
|
+
sdk.wallet.on("connect", handleConnect);
|
|
89
|
+
sdk.wallet.on("disconnect", handleDisconnect);
|
|
90
|
+
sdk.wallet.on("accountChanged", handleAccountChanged);
|
|
91
|
+
const state = sdk.wallet.getState();
|
|
92
|
+
if (state.connected) {
|
|
93
|
+
setWalletState(state);
|
|
94
|
+
setCurrentWallet(sdk.wallet.getWallet());
|
|
95
|
+
}
|
|
96
|
+
return () => {
|
|
97
|
+
sdk.wallet.off("connect", handleConnect);
|
|
98
|
+
sdk.wallet.off("disconnect", handleDisconnect);
|
|
99
|
+
sdk.wallet.off("accountChanged", handleAccountChanged);
|
|
100
|
+
sdk.events.unsubscribeAll();
|
|
101
|
+
};
|
|
102
|
+
}, [network, autoConnect]);
|
|
103
|
+
const connect = (0, import_react.useCallback)(
|
|
104
|
+
async (wallet) => {
|
|
105
|
+
if (!movement) return;
|
|
106
|
+
setConnecting(true);
|
|
107
|
+
try {
|
|
108
|
+
await movement.wallet.connect(wallet);
|
|
109
|
+
setCurrentWallet(wallet);
|
|
110
|
+
} catch (error) {
|
|
111
|
+
setConnecting(false);
|
|
112
|
+
if (error instanceof import_core.MovementError && onError) {
|
|
113
|
+
onError(error);
|
|
114
|
+
}
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
[movement, onError]
|
|
119
|
+
);
|
|
120
|
+
const disconnect = (0, import_react.useCallback)(async () => {
|
|
121
|
+
if (!movement) return;
|
|
122
|
+
try {
|
|
123
|
+
await movement.wallet.disconnect();
|
|
124
|
+
} catch (error) {
|
|
125
|
+
if (error instanceof import_core.MovementError && onError) {
|
|
126
|
+
onError(error);
|
|
127
|
+
}
|
|
128
|
+
throw error;
|
|
129
|
+
}
|
|
130
|
+
}, [movement, onError]);
|
|
131
|
+
const value = {
|
|
132
|
+
movement,
|
|
133
|
+
network,
|
|
134
|
+
address: walletState.address,
|
|
135
|
+
connected: walletState.connected,
|
|
136
|
+
connecting,
|
|
137
|
+
wallets,
|
|
138
|
+
wallet: currentWallet,
|
|
139
|
+
connect,
|
|
140
|
+
disconnect,
|
|
141
|
+
...onError && { onError }
|
|
142
|
+
};
|
|
143
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MovementContext.Provider, { value, children });
|
|
144
|
+
}
|
|
145
|
+
function useMovementContext() {
|
|
146
|
+
const context = (0, import_react.useContext)(MovementContext);
|
|
147
|
+
if (!context) {
|
|
148
|
+
throw new Error("useMovementContext must be used within a MovementProvider");
|
|
149
|
+
}
|
|
150
|
+
return context;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// src/hooks/useMovement.ts
|
|
154
|
+
function useMovement() {
|
|
155
|
+
const { movement, network, address, connected, connecting, connect, disconnect, wallets, wallet } = useMovementContext();
|
|
156
|
+
return {
|
|
157
|
+
movement,
|
|
158
|
+
network,
|
|
159
|
+
address,
|
|
160
|
+
connected,
|
|
161
|
+
connecting,
|
|
162
|
+
connect,
|
|
163
|
+
disconnect,
|
|
164
|
+
wallets,
|
|
165
|
+
wallet
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// src/hooks/useBalance.ts
|
|
170
|
+
var import_react2 = require("react");
|
|
171
|
+
function useBalance(address) {
|
|
172
|
+
const { movement, address: connectedAddress, onError } = useMovementContext();
|
|
173
|
+
const [balance, setBalance] = (0, import_react2.useState)(null);
|
|
174
|
+
const [loading, setLoading] = (0, import_react2.useState)(false);
|
|
175
|
+
const [error, setError] = (0, import_react2.useState)(null);
|
|
176
|
+
const targetAddress = address ?? connectedAddress;
|
|
177
|
+
const fetchBalance = (0, import_react2.useCallback)(async () => {
|
|
178
|
+
if (!movement || !targetAddress) {
|
|
179
|
+
setBalance(null);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
setLoading(true);
|
|
183
|
+
setError(null);
|
|
184
|
+
try {
|
|
185
|
+
const result = await movement.getAccountBalance(targetAddress);
|
|
186
|
+
setBalance(result);
|
|
187
|
+
} catch (err) {
|
|
188
|
+
const movementError = err;
|
|
189
|
+
setError(movementError);
|
|
190
|
+
setBalance(null);
|
|
191
|
+
if (onError) {
|
|
192
|
+
onError(movementError);
|
|
193
|
+
}
|
|
194
|
+
} finally {
|
|
195
|
+
setLoading(false);
|
|
196
|
+
}
|
|
197
|
+
}, [movement, targetAddress, onError]);
|
|
198
|
+
(0, import_react2.useEffect)(() => {
|
|
199
|
+
let cancelled = false;
|
|
200
|
+
const doFetch = async () => {
|
|
201
|
+
if (!movement || !targetAddress) {
|
|
202
|
+
setBalance(null);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
setLoading(true);
|
|
206
|
+
setError(null);
|
|
207
|
+
try {
|
|
208
|
+
const result = await movement.getAccountBalance(targetAddress);
|
|
209
|
+
if (!cancelled) {
|
|
210
|
+
setBalance(result);
|
|
211
|
+
}
|
|
212
|
+
} catch (err) {
|
|
213
|
+
if (!cancelled) {
|
|
214
|
+
const movementError = err;
|
|
215
|
+
setError(movementError);
|
|
216
|
+
setBalance(null);
|
|
217
|
+
if (onError) {
|
|
218
|
+
onError(movementError);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
} finally {
|
|
222
|
+
if (!cancelled) {
|
|
223
|
+
setLoading(false);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
doFetch();
|
|
228
|
+
return () => {
|
|
229
|
+
cancelled = true;
|
|
230
|
+
};
|
|
231
|
+
}, [movement, targetAddress, onError]);
|
|
232
|
+
return {
|
|
233
|
+
balance,
|
|
234
|
+
loading,
|
|
235
|
+
error,
|
|
236
|
+
refetch: fetchBalance
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// src/hooks/useContract.ts
|
|
241
|
+
var import_react3 = require("react");
|
|
242
|
+
function useContract(options) {
|
|
243
|
+
const { movement, onError } = useMovementContext();
|
|
244
|
+
const [data, setData] = (0, import_react3.useState)(null);
|
|
245
|
+
const [loading, setLoading] = (0, import_react3.useState)(false);
|
|
246
|
+
const [error, setError] = (0, import_react3.useState)(null);
|
|
247
|
+
const contract = (0, import_react3.useMemo)(() => {
|
|
248
|
+
if (!movement) return null;
|
|
249
|
+
return movement.contract(options);
|
|
250
|
+
}, [movement, options.address, options.module]);
|
|
251
|
+
const read = (0, import_react3.useCallback)(
|
|
252
|
+
async (functionName, args, typeArgs = []) => {
|
|
253
|
+
if (!contract) {
|
|
254
|
+
throw new Error("Contract not initialized");
|
|
255
|
+
}
|
|
256
|
+
setLoading(true);
|
|
257
|
+
setError(null);
|
|
258
|
+
try {
|
|
259
|
+
const result = await contract.view(functionName, args, typeArgs);
|
|
260
|
+
setData(result);
|
|
261
|
+
return result;
|
|
262
|
+
} catch (err) {
|
|
263
|
+
const movementError = err;
|
|
264
|
+
setError(movementError);
|
|
265
|
+
if (onError) {
|
|
266
|
+
onError(movementError);
|
|
267
|
+
}
|
|
268
|
+
throw err;
|
|
269
|
+
} finally {
|
|
270
|
+
setLoading(false);
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
[contract, onError]
|
|
274
|
+
);
|
|
275
|
+
const write = (0, import_react3.useCallback)(
|
|
276
|
+
async (functionName, args, typeArgs = []) => {
|
|
277
|
+
if (!contract) {
|
|
278
|
+
throw new Error("Contract not initialized");
|
|
279
|
+
}
|
|
280
|
+
setLoading(true);
|
|
281
|
+
setError(null);
|
|
282
|
+
try {
|
|
283
|
+
const txHash = await contract.call(functionName, args, typeArgs);
|
|
284
|
+
setData(txHash);
|
|
285
|
+
return txHash;
|
|
286
|
+
} catch (err) {
|
|
287
|
+
const movementError = err;
|
|
288
|
+
setError(movementError);
|
|
289
|
+
if (onError) {
|
|
290
|
+
onError(movementError);
|
|
291
|
+
}
|
|
292
|
+
throw err;
|
|
293
|
+
} finally {
|
|
294
|
+
setLoading(false);
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
[contract, onError]
|
|
298
|
+
);
|
|
299
|
+
return {
|
|
300
|
+
data,
|
|
301
|
+
loading,
|
|
302
|
+
error,
|
|
303
|
+
read,
|
|
304
|
+
write,
|
|
305
|
+
contract
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// src/hooks/useTransaction.ts
|
|
310
|
+
var import_react4 = require("react");
|
|
311
|
+
function useTransaction() {
|
|
312
|
+
const { movement, onError } = useMovementContext();
|
|
313
|
+
const [data, setData] = (0, import_react4.useState)(null);
|
|
314
|
+
const [loading, setLoading] = (0, import_react4.useState)(false);
|
|
315
|
+
const [error, setError] = (0, import_react4.useState)(null);
|
|
316
|
+
const send = (0, import_react4.useCallback)(
|
|
317
|
+
async (options) => {
|
|
318
|
+
if (!movement) {
|
|
319
|
+
throw new Error("Movement SDK not initialized");
|
|
320
|
+
}
|
|
321
|
+
setLoading(true);
|
|
322
|
+
setError(null);
|
|
323
|
+
try {
|
|
324
|
+
const payload = await movement.transaction.build(options);
|
|
325
|
+
const hash = await movement.transaction.signAndSubmit(payload);
|
|
326
|
+
setData(hash);
|
|
327
|
+
return hash;
|
|
328
|
+
} catch (err) {
|
|
329
|
+
const movementError = err;
|
|
330
|
+
setError(movementError);
|
|
331
|
+
if (onError) {
|
|
332
|
+
onError(movementError);
|
|
333
|
+
}
|
|
334
|
+
throw err;
|
|
335
|
+
} finally {
|
|
336
|
+
setLoading(false);
|
|
337
|
+
}
|
|
338
|
+
},
|
|
339
|
+
[movement, onError]
|
|
340
|
+
);
|
|
341
|
+
const reset = (0, import_react4.useCallback)(() => {
|
|
342
|
+
setData(null);
|
|
343
|
+
setError(null);
|
|
344
|
+
setLoading(false);
|
|
345
|
+
}, []);
|
|
346
|
+
return {
|
|
347
|
+
send,
|
|
348
|
+
data,
|
|
349
|
+
loading,
|
|
350
|
+
error,
|
|
351
|
+
reset
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// src/hooks/useWaitForTransaction.ts
|
|
356
|
+
var import_react5 = require("react");
|
|
357
|
+
function useWaitForTransaction(hash, options) {
|
|
358
|
+
const { movement, onError } = useMovementContext();
|
|
359
|
+
const [data, setData] = (0, import_react5.useState)(null);
|
|
360
|
+
const [loading, setLoading] = (0, import_react5.useState)(false);
|
|
361
|
+
const [error, setError] = (0, import_react5.useState)(null);
|
|
362
|
+
(0, import_react5.useEffect)(() => {
|
|
363
|
+
if (!hash || !movement) {
|
|
364
|
+
setData(null);
|
|
365
|
+
setLoading(false);
|
|
366
|
+
setError(null);
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
let cancelled = false;
|
|
370
|
+
const waitForTx = async () => {
|
|
371
|
+
setLoading(true);
|
|
372
|
+
setError(null);
|
|
373
|
+
try {
|
|
374
|
+
const waitOptions = {};
|
|
375
|
+
if (options?.timeoutMs !== void 0) {
|
|
376
|
+
waitOptions.timeoutMs = options.timeoutMs;
|
|
377
|
+
}
|
|
378
|
+
if (options?.checkIntervalMs !== void 0) {
|
|
379
|
+
waitOptions.checkIntervalMs = options.checkIntervalMs;
|
|
380
|
+
}
|
|
381
|
+
const response = await movement.waitForTransaction(hash, waitOptions);
|
|
382
|
+
if (!cancelled) {
|
|
383
|
+
setData(response);
|
|
384
|
+
}
|
|
385
|
+
} catch (err) {
|
|
386
|
+
if (!cancelled) {
|
|
387
|
+
const movementError = err;
|
|
388
|
+
setError(movementError);
|
|
389
|
+
if (onError) {
|
|
390
|
+
onError(movementError);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
} finally {
|
|
394
|
+
if (!cancelled) {
|
|
395
|
+
setLoading(false);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
waitForTx();
|
|
400
|
+
return () => {
|
|
401
|
+
cancelled = true;
|
|
402
|
+
};
|
|
403
|
+
}, [hash, movement, options?.timeoutMs, options?.checkIntervalMs, onError]);
|
|
404
|
+
return {
|
|
405
|
+
data,
|
|
406
|
+
loading,
|
|
407
|
+
error
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// src/components/WalletButton.tsx
|
|
412
|
+
var import_react6 = require("react");
|
|
413
|
+
|
|
414
|
+
// src/components/WalletModal.tsx
|
|
415
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
416
|
+
var WALLET_INFO = {
|
|
417
|
+
petra: {
|
|
418
|
+
name: "Petra",
|
|
419
|
+
icon: "\u{1F98A}",
|
|
420
|
+
description: "Recommended for Movement"
|
|
421
|
+
},
|
|
422
|
+
pontem: {
|
|
423
|
+
name: "Pontem",
|
|
424
|
+
icon: "\u{1F309}",
|
|
425
|
+
description: "Multi-chain with Movement support"
|
|
426
|
+
},
|
|
427
|
+
nightly: {
|
|
428
|
+
name: "Nightly",
|
|
429
|
+
icon: "\u{1F319}",
|
|
430
|
+
description: "Movement & Aptos wallet"
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
function WalletModal({ open, onClose }) {
|
|
434
|
+
const { wallets, connect, connecting } = useMovement();
|
|
435
|
+
if (!open) return null;
|
|
436
|
+
const handleConnect = async (wallet) => {
|
|
437
|
+
try {
|
|
438
|
+
await connect(wallet);
|
|
439
|
+
onClose();
|
|
440
|
+
} catch {
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
const overlayStyles = {
|
|
444
|
+
position: "fixed",
|
|
445
|
+
top: 0,
|
|
446
|
+
left: 0,
|
|
447
|
+
right: 0,
|
|
448
|
+
bottom: 0,
|
|
449
|
+
backgroundColor: "rgba(0, 0, 0, 0.5)",
|
|
450
|
+
display: "flex",
|
|
451
|
+
alignItems: "center",
|
|
452
|
+
justifyContent: "center",
|
|
453
|
+
zIndex: 1e3
|
|
454
|
+
};
|
|
455
|
+
const modalStyles = {
|
|
456
|
+
backgroundColor: "white",
|
|
457
|
+
borderRadius: "12px",
|
|
458
|
+
padding: "24px",
|
|
459
|
+
minWidth: "320px",
|
|
460
|
+
maxWidth: "400px",
|
|
461
|
+
boxShadow: "0 20px 25px -5px rgba(0, 0, 0, 0.1)"
|
|
462
|
+
};
|
|
463
|
+
const headerStyles = {
|
|
464
|
+
display: "flex",
|
|
465
|
+
justifyContent: "space-between",
|
|
466
|
+
alignItems: "center",
|
|
467
|
+
marginBottom: "20px"
|
|
468
|
+
};
|
|
469
|
+
const titleStyles = {
|
|
470
|
+
fontSize: "18px",
|
|
471
|
+
fontWeight: 600,
|
|
472
|
+
margin: 0
|
|
473
|
+
};
|
|
474
|
+
const closeButtonStyles = {
|
|
475
|
+
background: "none",
|
|
476
|
+
border: "none",
|
|
477
|
+
fontSize: "24px",
|
|
478
|
+
cursor: "pointer",
|
|
479
|
+
padding: "4px",
|
|
480
|
+
lineHeight: 1
|
|
481
|
+
};
|
|
482
|
+
const walletButtonStyles = {
|
|
483
|
+
display: "flex",
|
|
484
|
+
alignItems: "center",
|
|
485
|
+
gap: "12px",
|
|
486
|
+
width: "100%",
|
|
487
|
+
padding: "12px 16px",
|
|
488
|
+
border: "1px solid #e5e7eb",
|
|
489
|
+
borderRadius: "8px",
|
|
490
|
+
backgroundColor: "white",
|
|
491
|
+
cursor: "pointer",
|
|
492
|
+
fontSize: "16px",
|
|
493
|
+
marginBottom: "8px",
|
|
494
|
+
transition: "all 0.2s ease"
|
|
495
|
+
};
|
|
496
|
+
const emptyStyles = {
|
|
497
|
+
textAlign: "center",
|
|
498
|
+
color: "#6b7280",
|
|
499
|
+
padding: "20px"
|
|
500
|
+
};
|
|
501
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: overlayStyles, onClick: onClose, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: modalStyles, onClick: (e) => e.stopPropagation(), children: [
|
|
502
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: headerStyles, children: [
|
|
503
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h2", { style: titleStyles, children: "Connect Wallet" }),
|
|
504
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { style: closeButtonStyles, onClick: onClose, children: "\xD7" })
|
|
505
|
+
] }),
|
|
506
|
+
wallets.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: emptyStyles, children: [
|
|
507
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { style: { marginBottom: "12px" }, children: "No wallets detected." }),
|
|
508
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("p", { style: { marginBottom: "16px" }, children: [
|
|
509
|
+
"Install a wallet that supports ",
|
|
510
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("strong", { children: "Movement Network" }),
|
|
511
|
+
":"
|
|
512
|
+
] }),
|
|
513
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: "8px" }, children: [
|
|
514
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
515
|
+
"a",
|
|
516
|
+
{
|
|
517
|
+
href: "https://petra.app/",
|
|
518
|
+
target: "_blank",
|
|
519
|
+
rel: "noopener noreferrer",
|
|
520
|
+
style: {
|
|
521
|
+
display: "inline-block",
|
|
522
|
+
padding: "8px 16px",
|
|
523
|
+
backgroundColor: "#4f46e5",
|
|
524
|
+
color: "white",
|
|
525
|
+
borderRadius: "6px",
|
|
526
|
+
textDecoration: "none",
|
|
527
|
+
fontSize: "14px"
|
|
528
|
+
},
|
|
529
|
+
children: "\u{1F98A} Get Petra (Recommended)"
|
|
530
|
+
}
|
|
531
|
+
),
|
|
532
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
533
|
+
"a",
|
|
534
|
+
{
|
|
535
|
+
href: "https://pontem.network/pontem-wallet",
|
|
536
|
+
target: "_blank",
|
|
537
|
+
rel: "noopener noreferrer",
|
|
538
|
+
style: {
|
|
539
|
+
display: "inline-block",
|
|
540
|
+
padding: "8px 16px",
|
|
541
|
+
backgroundColor: "#6366f1",
|
|
542
|
+
color: "white",
|
|
543
|
+
borderRadius: "6px",
|
|
544
|
+
textDecoration: "none",
|
|
545
|
+
fontSize: "14px"
|
|
546
|
+
},
|
|
547
|
+
children: "\u{1F309} Get Pontem"
|
|
548
|
+
}
|
|
549
|
+
)
|
|
550
|
+
] })
|
|
551
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { children: wallets.map((wallet) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
552
|
+
"button",
|
|
553
|
+
{
|
|
554
|
+
style: walletButtonStyles,
|
|
555
|
+
onClick: () => handleConnect(wallet),
|
|
556
|
+
disabled: connecting,
|
|
557
|
+
children: [
|
|
558
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: { fontSize: "24px" }, children: WALLET_INFO[wallet].icon }),
|
|
559
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: { textAlign: "left" }, children: [
|
|
560
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { children: WALLET_INFO[wallet].name }),
|
|
561
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: { fontSize: "12px", color: "#6b7280" }, children: WALLET_INFO[wallet].description })
|
|
562
|
+
] })
|
|
563
|
+
]
|
|
564
|
+
},
|
|
565
|
+
wallet
|
|
566
|
+
)) })
|
|
567
|
+
] }) });
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
// src/components/WalletButton.tsx
|
|
571
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
572
|
+
function truncateAddress(address) {
|
|
573
|
+
return `${address.slice(0, 6)}...${address.slice(-4)}`;
|
|
574
|
+
}
|
|
575
|
+
function WalletButton({ className = "", connectText = "Connect Wallet" }) {
|
|
576
|
+
const { address, connected, connecting, disconnect } = useMovement();
|
|
577
|
+
const [modalOpen, setModalOpen] = (0, import_react6.useState)(false);
|
|
578
|
+
const baseStyles = {
|
|
579
|
+
padding: "10px 20px",
|
|
580
|
+
borderRadius: "8px",
|
|
581
|
+
border: "none",
|
|
582
|
+
cursor: "pointer",
|
|
583
|
+
fontSize: "14px",
|
|
584
|
+
fontWeight: 500,
|
|
585
|
+
transition: "all 0.2s ease"
|
|
586
|
+
};
|
|
587
|
+
const connectedStyles = {
|
|
588
|
+
...baseStyles,
|
|
589
|
+
backgroundColor: "#f0f0f0",
|
|
590
|
+
color: "#333"
|
|
591
|
+
};
|
|
592
|
+
const disconnectedStyles = {
|
|
593
|
+
...baseStyles,
|
|
594
|
+
backgroundColor: "#6366f1",
|
|
595
|
+
color: "white"
|
|
596
|
+
};
|
|
597
|
+
if (connected && address) {
|
|
598
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
599
|
+
"button",
|
|
600
|
+
{
|
|
601
|
+
className,
|
|
602
|
+
style: connectedStyles,
|
|
603
|
+
onClick: disconnect,
|
|
604
|
+
title: "Click to disconnect",
|
|
605
|
+
children: truncateAddress(address)
|
|
606
|
+
}
|
|
607
|
+
);
|
|
608
|
+
}
|
|
609
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
610
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
611
|
+
"button",
|
|
612
|
+
{
|
|
613
|
+
className,
|
|
614
|
+
style: disconnectedStyles,
|
|
615
|
+
onClick: () => setModalOpen(true),
|
|
616
|
+
disabled: connecting,
|
|
617
|
+
children: connecting ? "Connecting..." : connectText
|
|
618
|
+
}
|
|
619
|
+
),
|
|
620
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(WalletModal, { open: modalOpen, onClose: () => setModalOpen(false) })
|
|
621
|
+
] });
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
// src/components/AddressDisplay.tsx
|
|
625
|
+
var import_react7 = require("react");
|
|
626
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
627
|
+
function truncateAddress2(address, startChars = 6, endChars = 4) {
|
|
628
|
+
if (address.length <= startChars + endChars + 3) {
|
|
629
|
+
return address;
|
|
630
|
+
}
|
|
631
|
+
return `${address.slice(0, startChars)}...${address.slice(-endChars)}`;
|
|
632
|
+
}
|
|
633
|
+
function AddressDisplay({
|
|
634
|
+
address,
|
|
635
|
+
truncate = true,
|
|
636
|
+
copyable = true,
|
|
637
|
+
className = ""
|
|
638
|
+
}) {
|
|
639
|
+
const [copied, setCopied] = (0, import_react7.useState)(false);
|
|
640
|
+
const handleCopy = (0, import_react7.useCallback)(async () => {
|
|
641
|
+
try {
|
|
642
|
+
await navigator.clipboard.writeText(address);
|
|
643
|
+
setCopied(true);
|
|
644
|
+
setTimeout(() => setCopied(false), 2e3);
|
|
645
|
+
} catch {
|
|
646
|
+
}
|
|
647
|
+
}, [address]);
|
|
648
|
+
const displayAddress = truncate ? truncateAddress2(address) : address;
|
|
649
|
+
const containerStyles = {
|
|
650
|
+
display: "inline-flex",
|
|
651
|
+
alignItems: "center",
|
|
652
|
+
gap: "8px",
|
|
653
|
+
fontFamily: "monospace",
|
|
654
|
+
fontSize: "14px"
|
|
655
|
+
};
|
|
656
|
+
const addressStyles = {
|
|
657
|
+
backgroundColor: "#f3f4f6",
|
|
658
|
+
padding: "4px 8px",
|
|
659
|
+
borderRadius: "4px"
|
|
660
|
+
};
|
|
661
|
+
const buttonStyles = {
|
|
662
|
+
background: "none",
|
|
663
|
+
border: "none",
|
|
664
|
+
cursor: "pointer",
|
|
665
|
+
padding: "4px",
|
|
666
|
+
fontSize: "14px",
|
|
667
|
+
color: copied ? "#10b981" : "#6b7280"
|
|
668
|
+
};
|
|
669
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className, style: containerStyles, title: address, children: [
|
|
670
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: addressStyles, children: displayAddress }),
|
|
671
|
+
copyable && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { style: buttonStyles, onClick: handleCopy, title: copied ? "Copied!" : "Copy address", children: copied ? "\u2713" : "\u{1F4CB}" })
|
|
672
|
+
] });
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
// src/components/NetworkSwitcher.tsx
|
|
676
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
677
|
+
var NETWORK_INFO = {
|
|
678
|
+
mainnet: { name: "Mainnet", color: "#10b981" },
|
|
679
|
+
testnet: { name: "Testnet", color: "#f59e0b" }
|
|
680
|
+
};
|
|
681
|
+
function NetworkSwitcher({ className = "", onNetworkChange }) {
|
|
682
|
+
const { network } = useMovementContext();
|
|
683
|
+
const containerStyles = {
|
|
684
|
+
display: "inline-flex",
|
|
685
|
+
alignItems: "center",
|
|
686
|
+
gap: "8px"
|
|
687
|
+
};
|
|
688
|
+
const indicatorStyles = {
|
|
689
|
+
width: "8px",
|
|
690
|
+
height: "8px",
|
|
691
|
+
borderRadius: "50%",
|
|
692
|
+
backgroundColor: NETWORK_INFO[network].color
|
|
693
|
+
};
|
|
694
|
+
const selectStyles = {
|
|
695
|
+
padding: "6px 12px",
|
|
696
|
+
borderRadius: "6px",
|
|
697
|
+
border: "1px solid #e5e7eb",
|
|
698
|
+
backgroundColor: "white",
|
|
699
|
+
fontSize: "14px",
|
|
700
|
+
cursor: onNetworkChange ? "pointer" : "default"
|
|
701
|
+
};
|
|
702
|
+
if (!onNetworkChange) {
|
|
703
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className, style: containerStyles, children: [
|
|
704
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: indicatorStyles }),
|
|
705
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: NETWORK_INFO[network].name })
|
|
706
|
+
] });
|
|
707
|
+
}
|
|
708
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className, style: containerStyles, children: [
|
|
709
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: indicatorStyles }),
|
|
710
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
711
|
+
"select",
|
|
712
|
+
{
|
|
713
|
+
style: selectStyles,
|
|
714
|
+
value: network,
|
|
715
|
+
onChange: (e) => onNetworkChange(e.target.value),
|
|
716
|
+
children: [
|
|
717
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "mainnet", children: "Mainnet" }),
|
|
718
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "testnet", children: "Testnet" })
|
|
719
|
+
]
|
|
720
|
+
}
|
|
721
|
+
)
|
|
722
|
+
] });
|
|
723
|
+
}
|
|
724
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
725
|
+
0 && (module.exports = {
|
|
726
|
+
AddressDisplay,
|
|
727
|
+
MovementContext,
|
|
728
|
+
MovementProvider,
|
|
729
|
+
NetworkSwitcher,
|
|
730
|
+
WalletButton,
|
|
731
|
+
WalletModal,
|
|
732
|
+
useBalance,
|
|
733
|
+
useContract,
|
|
734
|
+
useMovement,
|
|
735
|
+
useMovementContext,
|
|
736
|
+
useTransaction,
|
|
737
|
+
useWaitForTransaction
|
|
738
|
+
});
|