@diviswap/sdk 1.7.27 → 1.8.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 +1 -1
- package/README.md +73 -82
- package/bin/create-diviswap-app.js +5 -5
- package/dist/cli/index.js +438 -185
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +302 -178
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +302 -178
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +2 -2
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.js +260 -183
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +260 -183
- package/dist/react/index.mjs.map +1 -1
- package/dist/{wallet-DZymADRo.d.mts → wallet-Ca1U51kT.d.mts} +1 -1
- package/dist/{wallet-DZymADRo.d.ts → wallet-Ca1U51kT.d.ts} +1 -1
- package/package.json +98 -97
- package/src/cli/templates/index.ts +86 -54
- package/src/cli/templates/shared/client.ts +65 -65
package/dist/react/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
|
-
import { U as User, T as Transaction, P as Payee, D as Diviswap, d as Address, e as CreateAddressRequest, g as ChainName, l as WalletTrackingConfig, W as WalletConnection, k as EthereumWallet, i as WalletTracker } from '../wallet-
|
|
2
|
+
import { U as User, T as Transaction, P as Payee, D as Diviswap, d as Address, e as CreateAddressRequest, g as ChainName, l as WalletTrackingConfig, W as WalletConnection, k as EthereumWallet, i as WalletTracker } from '../wallet-Ca1U51kT.mjs';
|
|
3
3
|
|
|
4
4
|
interface DiviswapContextValue {
|
|
5
5
|
user: User | null;
|
|
@@ -33,7 +33,7 @@ interface DiviswapFarcasterProviderProps {
|
|
|
33
33
|
/** Where to store the session token: 'memory' for Farcaster mini apps, 'localStorage' for regular web apps */
|
|
34
34
|
tokenStorage?: 'memory' | 'localStorage';
|
|
35
35
|
}
|
|
36
|
-
declare function DiviswapFarcasterProvider({ children, tokenStorage }: DiviswapFarcasterProviderProps): React.JSX.Element;
|
|
36
|
+
declare function DiviswapFarcasterProvider({ children, tokenStorage, }: DiviswapFarcasterProviderProps): React.JSX.Element;
|
|
37
37
|
/** @deprecated Use DiviswapFarcasterProvider instead */
|
|
38
38
|
declare const LiberExFarcasterProvider: typeof DiviswapFarcasterProvider;
|
|
39
39
|
/** @deprecated Use DiviswapFarcasterProviderProps instead */
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
|
-
import { U as User, T as Transaction, P as Payee, D as Diviswap, d as Address, e as CreateAddressRequest, g as ChainName, l as WalletTrackingConfig, W as WalletConnection, k as EthereumWallet, i as WalletTracker } from '../wallet-
|
|
2
|
+
import { U as User, T as Transaction, P as Payee, D as Diviswap, d as Address, e as CreateAddressRequest, g as ChainName, l as WalletTrackingConfig, W as WalletConnection, k as EthereumWallet, i as WalletTracker } from '../wallet-Ca1U51kT.js';
|
|
3
3
|
|
|
4
4
|
interface DiviswapContextValue {
|
|
5
5
|
user: User | null;
|
|
@@ -33,7 +33,7 @@ interface DiviswapFarcasterProviderProps {
|
|
|
33
33
|
/** Where to store the session token: 'memory' for Farcaster mini apps, 'localStorage' for regular web apps */
|
|
34
34
|
tokenStorage?: 'memory' | 'localStorage';
|
|
35
35
|
}
|
|
36
|
-
declare function DiviswapFarcasterProvider({ children, tokenStorage }: DiviswapFarcasterProviderProps): React.JSX.Element;
|
|
36
|
+
declare function DiviswapFarcasterProvider({ children, tokenStorage, }: DiviswapFarcasterProviderProps): React.JSX.Element;
|
|
37
37
|
/** @deprecated Use DiviswapFarcasterProvider instead */
|
|
38
38
|
declare const LiberExFarcasterProvider: typeof DiviswapFarcasterProvider;
|
|
39
39
|
/** @deprecated Use DiviswapFarcasterProviderProps instead */
|
package/dist/react/index.js
CHANGED
|
@@ -8,9 +8,7 @@ var React__default = /*#__PURE__*/_interopDefault(React);
|
|
|
8
8
|
|
|
9
9
|
// src/react/provider.tsx
|
|
10
10
|
var DiviswapContext = React.createContext(null);
|
|
11
|
-
function DiviswapProvider({
|
|
12
|
-
children
|
|
13
|
-
}) {
|
|
11
|
+
function DiviswapProvider({ children }) {
|
|
14
12
|
const [user, setUser] = React.useState(null);
|
|
15
13
|
const [loading, setLoading] = React.useState(false);
|
|
16
14
|
const [error, setError] = React.useState(null);
|
|
@@ -100,7 +98,10 @@ function DiviswapProvider({
|
|
|
100
98
|
return response.json();
|
|
101
99
|
};
|
|
102
100
|
const getTransactions = async (filters) => {
|
|
103
|
-
const params = new URLSearchParams({
|
|
101
|
+
const params = new URLSearchParams({
|
|
102
|
+
resource: "transactions",
|
|
103
|
+
...filters
|
|
104
|
+
});
|
|
104
105
|
const response = await fetch(`/api/diviswap?${params}`);
|
|
105
106
|
if (!response.ok) {
|
|
106
107
|
throw new Error("Failed to fetch transactions");
|
|
@@ -216,8 +217,10 @@ function DiviswapFarcasterProvider({
|
|
|
216
217
|
};
|
|
217
218
|
const checkSession = async (token) => {
|
|
218
219
|
try {
|
|
219
|
-
const headers = token ? {
|
|
220
|
-
const response = await fetch("/api/diviswap?resource=session", {
|
|
220
|
+
const headers = token ? { Authorization: `Bearer ${token}` } : {};
|
|
221
|
+
const response = await fetch("/api/diviswap?resource=session", {
|
|
222
|
+
headers
|
|
223
|
+
});
|
|
221
224
|
if (response.ok) {
|
|
222
225
|
const userData = await response.json();
|
|
223
226
|
if (userData) {
|
|
@@ -299,7 +302,11 @@ function DiviswapFarcasterProvider({
|
|
|
299
302
|
const response = await fetch("/api/diviswap", {
|
|
300
303
|
method: "POST",
|
|
301
304
|
headers: getAuthHeaders(),
|
|
302
|
-
body: JSON.stringify({
|
|
305
|
+
body: JSON.stringify({
|
|
306
|
+
action: "createTransaction",
|
|
307
|
+
sessionToken,
|
|
308
|
+
...data
|
|
309
|
+
})
|
|
303
310
|
});
|
|
304
311
|
if (!response.ok) {
|
|
305
312
|
throw new Error("Transaction creation failed");
|
|
@@ -313,7 +320,7 @@ function DiviswapFarcasterProvider({
|
|
|
313
320
|
...filters
|
|
314
321
|
});
|
|
315
322
|
const response = await fetch(`/api/diviswap?${params}`, {
|
|
316
|
-
headers: sessionToken ? {
|
|
323
|
+
headers: sessionToken ? { Authorization: `Bearer ${sessionToken}` } : {}
|
|
317
324
|
});
|
|
318
325
|
if (!response.ok) {
|
|
319
326
|
throw new Error("Failed to fetch transactions");
|
|
@@ -324,7 +331,11 @@ function DiviswapFarcasterProvider({
|
|
|
324
331
|
const response = await fetch("/api/diviswap", {
|
|
325
332
|
method: "POST",
|
|
326
333
|
headers: getAuthHeaders(),
|
|
327
|
-
body: JSON.stringify({
|
|
334
|
+
body: JSON.stringify({
|
|
335
|
+
action: "createPayee",
|
|
336
|
+
sessionToken,
|
|
337
|
+
...data
|
|
338
|
+
})
|
|
328
339
|
});
|
|
329
340
|
if (!response.ok) {
|
|
330
341
|
throw new Error("Payee creation failed");
|
|
@@ -337,7 +348,7 @@ function DiviswapFarcasterProvider({
|
|
|
337
348
|
params.append("sessionToken", sessionToken);
|
|
338
349
|
}
|
|
339
350
|
const response = await fetch(`/api/diviswap?${params}`, {
|
|
340
|
-
headers: sessionToken ? {
|
|
351
|
+
headers: sessionToken ? { Authorization: `Bearer ${sessionToken}` } : {}
|
|
341
352
|
});
|
|
342
353
|
if (!response.ok) {
|
|
343
354
|
throw new Error("Failed to fetch payees");
|
|
@@ -352,7 +363,7 @@ function DiviswapFarcasterProvider({
|
|
|
352
363
|
});
|
|
353
364
|
const response = await fetch(`/api/diviswap?${params}`, {
|
|
354
365
|
method: "DELETE",
|
|
355
|
-
headers: sessionToken ? {
|
|
366
|
+
headers: sessionToken ? { Authorization: `Bearer ${sessionToken}` } : {}
|
|
356
367
|
});
|
|
357
368
|
if (!response.ok) {
|
|
358
369
|
throw new Error("Failed to delete payee");
|
|
@@ -362,7 +373,11 @@ function DiviswapFarcasterProvider({
|
|
|
362
373
|
const response = await fetch("/api/diviswap", {
|
|
363
374
|
method: "POST",
|
|
364
375
|
headers: getAuthHeaders(),
|
|
365
|
-
body: JSON.stringify({
|
|
376
|
+
body: JSON.stringify({
|
|
377
|
+
action: "calculateFees",
|
|
378
|
+
sessionToken,
|
|
379
|
+
amount
|
|
380
|
+
})
|
|
366
381
|
});
|
|
367
382
|
if (!response.ok) {
|
|
368
383
|
throw new Error("Fee calculation failed");
|
|
@@ -416,32 +431,38 @@ function useTransactions() {
|
|
|
416
431
|
const { createTransaction, getTransactions, error } = useDiviswap();
|
|
417
432
|
const [transactions, setTransactions] = React.useState([]);
|
|
418
433
|
const [loading, setLoading] = React.useState(false);
|
|
419
|
-
const fetchTransactions = React.useCallback(
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
434
|
+
const fetchTransactions = React.useCallback(
|
|
435
|
+
async (filters) => {
|
|
436
|
+
setLoading(true);
|
|
437
|
+
try {
|
|
438
|
+
const data = await getTransactions(filters);
|
|
439
|
+
setTransactions(data);
|
|
440
|
+
return data;
|
|
441
|
+
} catch (err) {
|
|
442
|
+
console.error("Failed to fetch transactions:", err);
|
|
443
|
+
throw err;
|
|
444
|
+
} finally {
|
|
445
|
+
setLoading(false);
|
|
446
|
+
}
|
|
447
|
+
},
|
|
448
|
+
[getTransactions]
|
|
449
|
+
);
|
|
450
|
+
const create = React.useCallback(
|
|
451
|
+
async (data) => {
|
|
452
|
+
setLoading(true);
|
|
453
|
+
try {
|
|
454
|
+
const transaction = await createTransaction(data);
|
|
455
|
+
await fetchTransactions();
|
|
456
|
+
return transaction;
|
|
457
|
+
} catch (err) {
|
|
458
|
+
console.error("Failed to create transaction:", err);
|
|
459
|
+
throw err;
|
|
460
|
+
} finally {
|
|
461
|
+
setLoading(false);
|
|
462
|
+
}
|
|
463
|
+
},
|
|
464
|
+
[createTransaction, fetchTransactions]
|
|
465
|
+
);
|
|
445
466
|
return {
|
|
446
467
|
transactions,
|
|
447
468
|
loading,
|
|
@@ -468,31 +489,37 @@ function usePayees() {
|
|
|
468
489
|
setLoading(false);
|
|
469
490
|
}
|
|
470
491
|
}, [getPayees]);
|
|
471
|
-
const create = React.useCallback(
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
492
|
+
const create = React.useCallback(
|
|
493
|
+
async (data) => {
|
|
494
|
+
setLoading(true);
|
|
495
|
+
try {
|
|
496
|
+
const payee = await createPayee(data);
|
|
497
|
+
await fetchPayees();
|
|
498
|
+
return payee;
|
|
499
|
+
} catch (err) {
|
|
500
|
+
console.error("Failed to create payee:", err);
|
|
501
|
+
throw err;
|
|
502
|
+
} finally {
|
|
503
|
+
setLoading(false);
|
|
504
|
+
}
|
|
505
|
+
},
|
|
506
|
+
[createPayee, fetchPayees]
|
|
507
|
+
);
|
|
508
|
+
const remove = React.useCallback(
|
|
509
|
+
async (id) => {
|
|
510
|
+
setLoading(true);
|
|
511
|
+
try {
|
|
512
|
+
await deletePayee(id);
|
|
513
|
+
await fetchPayees();
|
|
514
|
+
} catch (err) {
|
|
515
|
+
console.error("Failed to delete payee:", err);
|
|
516
|
+
throw err;
|
|
517
|
+
} finally {
|
|
518
|
+
setLoading(false);
|
|
519
|
+
}
|
|
520
|
+
},
|
|
521
|
+
[deletePayee, fetchPayees]
|
|
522
|
+
);
|
|
496
523
|
React.useEffect(() => {
|
|
497
524
|
fetchPayees();
|
|
498
525
|
}, [fetchPayees]);
|
|
@@ -515,8 +542,10 @@ function useKYCStatus(options) {
|
|
|
515
542
|
setLoading(true);
|
|
516
543
|
setError(null);
|
|
517
544
|
const params = new URLSearchParams({ resource: "kycStatus" });
|
|
518
|
-
if (options?.customerId)
|
|
519
|
-
|
|
545
|
+
if (options?.customerId)
|
|
546
|
+
params.set("customerId", options.customerId);
|
|
547
|
+
if (options?.customerEmail)
|
|
548
|
+
params.set("customerEmail", options.customerEmail);
|
|
520
549
|
const response = await fetch(`/api/diviswap?${params}`);
|
|
521
550
|
if (!response.ok) {
|
|
522
551
|
throw new Error("Failed to fetch KYC status");
|
|
@@ -601,10 +630,13 @@ function useDashboard(options) {
|
|
|
601
630
|
const finalTransactions = txData.filter(
|
|
602
631
|
(tx) => tx.tx_type === "BANK_WITHDRAWAL" || tx.tx_type === "BANK_DEPOSIT"
|
|
603
632
|
);
|
|
604
|
-
const totalVolume = finalTransactions.reduce(
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
633
|
+
const totalVolume = finalTransactions.reduce(
|
|
634
|
+
(sum, tx) => {
|
|
635
|
+
const amount = tx.transaction_details?.amount || 0;
|
|
636
|
+
return sum + amount;
|
|
637
|
+
},
|
|
638
|
+
0
|
|
639
|
+
);
|
|
608
640
|
const pendingTransactions = finalTransactions.filter(
|
|
609
641
|
(tx) => tx.status === "INITIATED" || tx.status === "PROCESSING" || tx.status === "pending" || tx.status === "processing"
|
|
610
642
|
).length;
|
|
@@ -634,7 +666,10 @@ function useDashboard(options) {
|
|
|
634
666
|
0
|
|
635
667
|
);
|
|
636
668
|
return {
|
|
637
|
-
date: new Date(date).toLocaleDateString("en-US", {
|
|
669
|
+
date: new Date(date).toLocaleDateString("en-US", {
|
|
670
|
+
month: "short",
|
|
671
|
+
day: "numeric"
|
|
672
|
+
}),
|
|
638
673
|
volume,
|
|
639
674
|
// Amount is already in dollars
|
|
640
675
|
transactions: dayTransactions.length
|
|
@@ -846,7 +881,9 @@ var _WalletTracker = class _WalletTracker {
|
|
|
846
881
|
* Get chain name from chain ID
|
|
847
882
|
*/
|
|
848
883
|
getChainName(chainId) {
|
|
849
|
-
const builtInChain = Object.entries(CHAIN_IDS).find(
|
|
884
|
+
const builtInChain = Object.entries(CHAIN_IDS).find(
|
|
885
|
+
([_, id]) => id === chainId
|
|
886
|
+
)?.[0];
|
|
850
887
|
if (builtInChain) return builtInChain;
|
|
851
888
|
return this.config.customChains?.[chainId];
|
|
852
889
|
}
|
|
@@ -899,69 +936,90 @@ function useAddresses(diviswap) {
|
|
|
899
936
|
const result = await diviswap.addresses.list();
|
|
900
937
|
setAddresses(result);
|
|
901
938
|
} catch (err) {
|
|
902
|
-
setError(
|
|
939
|
+
setError(
|
|
940
|
+
err instanceof Error ? err : new Error("Failed to fetch addresses")
|
|
941
|
+
);
|
|
903
942
|
} finally {
|
|
904
943
|
setLoading(false);
|
|
905
944
|
}
|
|
906
945
|
}, [diviswap]);
|
|
907
|
-
const createAddress = React.useCallback(
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
));
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
946
|
+
const createAddress = React.useCallback(
|
|
947
|
+
async (data) => {
|
|
948
|
+
if (!diviswap) throw new Error("Diviswap instance not provided");
|
|
949
|
+
setLoading(true);
|
|
950
|
+
setError(null);
|
|
951
|
+
try {
|
|
952
|
+
const newAddress = await diviswap.addresses.create(data);
|
|
953
|
+
setAddresses((prev) => [...prev, newAddress]);
|
|
954
|
+
return newAddress;
|
|
955
|
+
} catch (err) {
|
|
956
|
+
const error2 = err instanceof Error ? err : new Error("Failed to create address");
|
|
957
|
+
setError(error2);
|
|
958
|
+
throw error2;
|
|
959
|
+
} finally {
|
|
960
|
+
setLoading(false);
|
|
961
|
+
}
|
|
962
|
+
},
|
|
963
|
+
[diviswap]
|
|
964
|
+
);
|
|
965
|
+
const setDefaultAddress = React.useCallback(
|
|
966
|
+
async (data) => {
|
|
967
|
+
if (!diviswap) throw new Error("Diviswap instance not provided");
|
|
968
|
+
setLoading(true);
|
|
969
|
+
setError(null);
|
|
970
|
+
try {
|
|
971
|
+
await diviswap.addresses.setDefault(data);
|
|
972
|
+
await fetchAddresses();
|
|
973
|
+
} catch (err) {
|
|
974
|
+
const error2 = err instanceof Error ? err : new Error("Failed to set default address");
|
|
975
|
+
setError(error2);
|
|
976
|
+
throw error2;
|
|
977
|
+
} finally {
|
|
978
|
+
setLoading(false);
|
|
979
|
+
}
|
|
980
|
+
},
|
|
981
|
+
[diviswap, fetchAddresses]
|
|
982
|
+
);
|
|
983
|
+
const deleteAddress = React.useCallback(
|
|
984
|
+
async (data) => {
|
|
985
|
+
if (!diviswap) throw new Error("Diviswap instance not provided");
|
|
986
|
+
setLoading(true);
|
|
987
|
+
setError(null);
|
|
988
|
+
try {
|
|
989
|
+
await diviswap.addresses.delete(data);
|
|
990
|
+
setAddresses(
|
|
991
|
+
(prev) => prev.filter(
|
|
992
|
+
(addr) => !(addr.chain_id === data.chain_id && addr.address.toLowerCase() === data.address.toLowerCase())
|
|
993
|
+
)
|
|
994
|
+
);
|
|
995
|
+
} catch (err) {
|
|
996
|
+
const error2 = err instanceof Error ? err : new Error("Failed to delete address");
|
|
997
|
+
setError(error2);
|
|
998
|
+
throw error2;
|
|
999
|
+
} finally {
|
|
1000
|
+
setLoading(false);
|
|
1001
|
+
}
|
|
1002
|
+
},
|
|
1003
|
+
[diviswap]
|
|
1004
|
+
);
|
|
1005
|
+
const getByChain = React.useCallback(
|
|
1006
|
+
(chainIdOrName) => {
|
|
1007
|
+
if (!diviswap) return [];
|
|
1008
|
+
const chainId = typeof chainIdOrName === "string" ? diviswap.addresses.getChainId(chainIdOrName) : chainIdOrName;
|
|
1009
|
+
return addresses.filter((addr) => addr.chain_id === chainId);
|
|
1010
|
+
},
|
|
1011
|
+
[addresses, diviswap]
|
|
1012
|
+
);
|
|
1013
|
+
const getDefault = React.useCallback(
|
|
1014
|
+
(chainIdOrName) => {
|
|
1015
|
+
if (!diviswap) return null;
|
|
1016
|
+
const chainId = typeof chainIdOrName === "string" ? diviswap.addresses.getChainId(chainIdOrName) : chainIdOrName;
|
|
1017
|
+
return addresses.find(
|
|
1018
|
+
(addr) => addr.chain_id === chainId && addr.is_default
|
|
1019
|
+
) || null;
|
|
1020
|
+
},
|
|
1021
|
+
[addresses, diviswap]
|
|
1022
|
+
);
|
|
965
1023
|
React.useEffect(() => {
|
|
966
1024
|
if (diviswap) {
|
|
967
1025
|
fetchAddresses();
|
|
@@ -984,49 +1042,62 @@ function useWalletConnection(diviswap, config) {
|
|
|
984
1042
|
const [isConnecting, setIsConnecting] = React.useState(false);
|
|
985
1043
|
const [isTracking, setIsTracking] = React.useState(false);
|
|
986
1044
|
const [error, setError] = React.useState(null);
|
|
987
|
-
const connect = React.useCallback(
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1045
|
+
const connect = React.useCallback(
|
|
1046
|
+
async (wallet) => {
|
|
1047
|
+
if (!diviswap) throw new Error("Diviswap instance not provided");
|
|
1048
|
+
setIsConnecting(true);
|
|
1049
|
+
setError(null);
|
|
1050
|
+
try {
|
|
1051
|
+
const result = await connectWallet(diviswap, wallet, config);
|
|
1052
|
+
setConnections(result);
|
|
1053
|
+
return result;
|
|
1054
|
+
} catch (err) {
|
|
1055
|
+
const error2 = err instanceof Error ? err : new Error("Failed to connect wallet");
|
|
1056
|
+
setError(error2);
|
|
1057
|
+
throw error2;
|
|
1058
|
+
} finally {
|
|
1059
|
+
setIsConnecting(false);
|
|
1060
|
+
}
|
|
1061
|
+
},
|
|
1062
|
+
[diviswap, config]
|
|
1063
|
+
);
|
|
1064
|
+
const trackCurrent = React.useCallback(
|
|
1065
|
+
async (wallet) => {
|
|
1066
|
+
if (!diviswap) throw new Error("Diviswap instance not provided");
|
|
1067
|
+
setIsTracking(true);
|
|
1068
|
+
setError(null);
|
|
1069
|
+
try {
|
|
1070
|
+
const result = await trackCurrentWallet(
|
|
1071
|
+
diviswap,
|
|
1072
|
+
wallet,
|
|
1073
|
+
config
|
|
1074
|
+
);
|
|
1075
|
+
setConnections(result);
|
|
1076
|
+
return result;
|
|
1077
|
+
} catch (err) {
|
|
1078
|
+
const error2 = err instanceof Error ? err : new Error("Failed to track current wallet");
|
|
1079
|
+
setError(error2);
|
|
1080
|
+
throw error2;
|
|
1081
|
+
} finally {
|
|
1082
|
+
setIsTracking(false);
|
|
1083
|
+
}
|
|
1084
|
+
},
|
|
1085
|
+
[diviswap, config]
|
|
1086
|
+
);
|
|
1087
|
+
const setupTracking = React.useCallback(
|
|
1088
|
+
(wallet) => {
|
|
1089
|
+
if (!diviswap) throw new Error("Diviswap instance not provided");
|
|
1090
|
+
try {
|
|
1091
|
+
const tracker = setupWalletTracking(diviswap, wallet, config);
|
|
1092
|
+
return tracker;
|
|
1093
|
+
} catch (err) {
|
|
1094
|
+
const error2 = err instanceof Error ? err : new Error("Failed to setup wallet tracking");
|
|
1095
|
+
setError(error2);
|
|
1096
|
+
throw error2;
|
|
1097
|
+
}
|
|
1098
|
+
},
|
|
1099
|
+
[diviswap, config]
|
|
1100
|
+
);
|
|
1030
1101
|
return {
|
|
1031
1102
|
connections,
|
|
1032
1103
|
isConnecting,
|
|
@@ -1040,16 +1111,22 @@ function useWalletConnection(diviswap, config) {
|
|
|
1040
1111
|
function useWalletAddresses(diviswap, config) {
|
|
1041
1112
|
const addressHook = useAddresses(diviswap);
|
|
1042
1113
|
const walletHook = useWalletConnection(diviswap, config);
|
|
1043
|
-
const connectAndTrack = React.useCallback(
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1114
|
+
const connectAndTrack = React.useCallback(
|
|
1115
|
+
async (wallet) => {
|
|
1116
|
+
const connections = await walletHook.connect(wallet);
|
|
1117
|
+
await addressHook.fetchAddresses();
|
|
1118
|
+
return connections;
|
|
1119
|
+
},
|
|
1120
|
+
[walletHook.connect, addressHook.fetchAddresses]
|
|
1121
|
+
);
|
|
1122
|
+
const trackCurrentAndRefresh = React.useCallback(
|
|
1123
|
+
async (wallet) => {
|
|
1124
|
+
const connections = await walletHook.trackCurrent(wallet);
|
|
1125
|
+
await addressHook.fetchAddresses();
|
|
1126
|
+
return connections;
|
|
1127
|
+
},
|
|
1128
|
+
[walletHook.trackCurrent, addressHook.fetchAddresses]
|
|
1129
|
+
);
|
|
1053
1130
|
return {
|
|
1054
1131
|
// Address management
|
|
1055
1132
|
...addressHook,
|