@zubari/sdk 0.1.10 → 0.1.12
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/{WalletManager-CkGhJZDo.d.ts → WalletManager-DLN81Bpl.d.ts} +39 -17
- package/dist/{WalletManager-UG6taF_0.d.mts → WalletManager-DWLhos10.d.mts} +39 -17
- package/dist/{index-DS2d6LVD.d.mts → index-BmBHZP3D.d.mts} +1 -1
- package/dist/{index-Dk_dYBbp.d.ts → index-C47lb49r.d.ts} +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +172 -99
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +172 -99
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +22 -3
- package/dist/react/index.d.ts +22 -3
- package/dist/react/index.js +172 -99
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +172 -99
- package/dist/react/index.mjs.map +1 -1
- package/dist/services/index.d.mts +8 -2
- package/dist/services/index.d.ts +8 -2
- package/dist/services/index.js +20 -4
- package/dist/services/index.js.map +1 -1
- package/dist/services/index.mjs +20 -4
- package/dist/services/index.mjs.map +1 -1
- package/dist/wallet/index.d.mts +2 -2
- package/dist/wallet/index.d.ts +2 -2
- package/dist/wallet/index.js +143 -99
- package/dist/wallet/index.js.map +1 -1
- package/dist/wallet/index.mjs +143 -99
- package/dist/wallet/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { N as NetworkType } from '../index-DhluuR9H.mjs';
|
|
2
|
-
import { b as WalletManagerConfig, a as WalletState, C as ChainBalance, M as MultiChainAddresses, W as WalletManager } from '../WalletManager-
|
|
3
|
-
export { S as SUPPORTED_CHAINS } from '../WalletManager-
|
|
2
|
+
import { b as WalletManagerConfig, a as WalletState, C as ChainBalance, M as MultiChainAddresses, W as WalletManager } from '../WalletManager-DWLhos10.mjs';
|
|
3
|
+
export { S as SUPPORTED_CHAINS } from '../WalletManager-DWLhos10.mjs';
|
|
4
4
|
import 'abitype';
|
|
5
5
|
import 'viem';
|
|
6
6
|
import 'ethers';
|
|
@@ -16,6 +16,23 @@ import '../SecureStorage-jO783AhC.mjs';
|
|
|
16
16
|
interface UseWalletManagerOptions extends WalletManagerConfig {
|
|
17
17
|
autoCheckWallet?: boolean;
|
|
18
18
|
}
|
|
19
|
+
/** Transaction result from sendTransaction */
|
|
20
|
+
interface SendTransactionResult {
|
|
21
|
+
success: boolean;
|
|
22
|
+
txHash?: string;
|
|
23
|
+
from?: string;
|
|
24
|
+
to?: string;
|
|
25
|
+
amount?: string;
|
|
26
|
+
chain?: NetworkType;
|
|
27
|
+
error?: string;
|
|
28
|
+
}
|
|
29
|
+
/** Fee estimation result */
|
|
30
|
+
interface FeeEstimateResult {
|
|
31
|
+
success: boolean;
|
|
32
|
+
fee?: string;
|
|
33
|
+
feeUsd?: number;
|
|
34
|
+
error?: string;
|
|
35
|
+
}
|
|
19
36
|
interface UseWalletManagerReturn {
|
|
20
37
|
state: WalletState;
|
|
21
38
|
isLoading: boolean;
|
|
@@ -36,6 +53,8 @@ interface UseWalletManagerReturn {
|
|
|
36
53
|
getAddressForChain: (chain: NetworkType) => string | null;
|
|
37
54
|
getAllAddresses: () => Partial<MultiChainAddresses>;
|
|
38
55
|
supportedChains: NetworkType[];
|
|
56
|
+
sendTransaction: (chain: NetworkType, to: string, amount: string, token?: string) => Promise<SendTransactionResult>;
|
|
57
|
+
estimateFee: (chain: NetworkType, to: string, amount: string, token?: string) => Promise<FeeEstimateResult>;
|
|
39
58
|
hasWallet: () => Promise<boolean>;
|
|
40
59
|
getSeed: () => string | null;
|
|
41
60
|
manager: WalletManager;
|
|
@@ -45,4 +64,4 @@ interface UseWalletManagerReturn {
|
|
|
45
64
|
*/
|
|
46
65
|
declare function useWalletManager(options?: UseWalletManagerOptions): UseWalletManagerReturn;
|
|
47
66
|
|
|
48
|
-
export { ChainBalance, MultiChainAddresses, type UseWalletManagerOptions, type UseWalletManagerReturn, WalletState, useWalletManager };
|
|
67
|
+
export { ChainBalance, type FeeEstimateResult, MultiChainAddresses, type SendTransactionResult, type UseWalletManagerOptions, type UseWalletManagerReturn, WalletState, useWalletManager };
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { N as NetworkType } from '../index-DhluuR9H.js';
|
|
2
|
-
import { b as WalletManagerConfig, a as WalletState, C as ChainBalance, M as MultiChainAddresses, W as WalletManager } from '../WalletManager-
|
|
3
|
-
export { S as SUPPORTED_CHAINS } from '../WalletManager-
|
|
2
|
+
import { b as WalletManagerConfig, a as WalletState, C as ChainBalance, M as MultiChainAddresses, W as WalletManager } from '../WalletManager-DLN81Bpl.js';
|
|
3
|
+
export { S as SUPPORTED_CHAINS } from '../WalletManager-DLN81Bpl.js';
|
|
4
4
|
import 'abitype';
|
|
5
5
|
import 'viem';
|
|
6
6
|
import 'ethers';
|
|
@@ -16,6 +16,23 @@ import '../SecureStorage-jO783AhC.js';
|
|
|
16
16
|
interface UseWalletManagerOptions extends WalletManagerConfig {
|
|
17
17
|
autoCheckWallet?: boolean;
|
|
18
18
|
}
|
|
19
|
+
/** Transaction result from sendTransaction */
|
|
20
|
+
interface SendTransactionResult {
|
|
21
|
+
success: boolean;
|
|
22
|
+
txHash?: string;
|
|
23
|
+
from?: string;
|
|
24
|
+
to?: string;
|
|
25
|
+
amount?: string;
|
|
26
|
+
chain?: NetworkType;
|
|
27
|
+
error?: string;
|
|
28
|
+
}
|
|
29
|
+
/** Fee estimation result */
|
|
30
|
+
interface FeeEstimateResult {
|
|
31
|
+
success: boolean;
|
|
32
|
+
fee?: string;
|
|
33
|
+
feeUsd?: number;
|
|
34
|
+
error?: string;
|
|
35
|
+
}
|
|
19
36
|
interface UseWalletManagerReturn {
|
|
20
37
|
state: WalletState;
|
|
21
38
|
isLoading: boolean;
|
|
@@ -36,6 +53,8 @@ interface UseWalletManagerReturn {
|
|
|
36
53
|
getAddressForChain: (chain: NetworkType) => string | null;
|
|
37
54
|
getAllAddresses: () => Partial<MultiChainAddresses>;
|
|
38
55
|
supportedChains: NetworkType[];
|
|
56
|
+
sendTransaction: (chain: NetworkType, to: string, amount: string, token?: string) => Promise<SendTransactionResult>;
|
|
57
|
+
estimateFee: (chain: NetworkType, to: string, amount: string, token?: string) => Promise<FeeEstimateResult>;
|
|
39
58
|
hasWallet: () => Promise<boolean>;
|
|
40
59
|
getSeed: () => string | null;
|
|
41
60
|
manager: WalletManager;
|
|
@@ -45,4 +64,4 @@ interface UseWalletManagerReturn {
|
|
|
45
64
|
*/
|
|
46
65
|
declare function useWalletManager(options?: UseWalletManagerOptions): UseWalletManagerReturn;
|
|
47
66
|
|
|
48
|
-
export { ChainBalance, MultiChainAddresses, type UseWalletManagerOptions, type UseWalletManagerReturn, WalletState, useWalletManager };
|
|
67
|
+
export { ChainBalance, type FeeEstimateResult, MultiChainAddresses, type SendTransactionResult, type UseWalletManagerOptions, type UseWalletManagerReturn, WalletState, useWalletManager };
|
package/dist/react/index.js
CHANGED
|
@@ -822,7 +822,10 @@ var ZubariWdkService = class {
|
|
|
822
822
|
return isValidSeed(seed);
|
|
823
823
|
}
|
|
824
824
|
/**
|
|
825
|
-
* Derive address for a specific chain
|
|
825
|
+
* Derive address for a specific chain using WDK API
|
|
826
|
+
*
|
|
827
|
+
* For Ethereum, falls back to local derivation if API fails.
|
|
828
|
+
* For other chains, WDK API is required - no placeholder fallback.
|
|
826
829
|
*/
|
|
827
830
|
async deriveAddress(seed, chain) {
|
|
828
831
|
await this.initialize();
|
|
@@ -838,6 +841,9 @@ var ZubariWdkService = class {
|
|
|
838
841
|
}
|
|
839
842
|
} catch (error) {
|
|
840
843
|
console.warn(`API address derivation failed for ${chain}:`, error);
|
|
844
|
+
if (chain === "ethereum") {
|
|
845
|
+
return this.deriveBrowserAddress(seed, chain);
|
|
846
|
+
}
|
|
841
847
|
}
|
|
842
848
|
if (this.useNativeWdk && this.nativeWdkService) {
|
|
843
849
|
try {
|
|
@@ -848,10 +854,18 @@ var ZubariWdkService = class {
|
|
|
848
854
|
console.warn(`Native WDK address derivation failed for ${chain}:`, error);
|
|
849
855
|
}
|
|
850
856
|
}
|
|
851
|
-
|
|
857
|
+
if (chain === "ethereum") {
|
|
858
|
+
return this.deriveBrowserAddress(seed, chain);
|
|
859
|
+
}
|
|
860
|
+
throw new Error(
|
|
861
|
+
`WDK API required for ${chain} address derivation. Ensure the backend is running.`
|
|
862
|
+
);
|
|
852
863
|
}
|
|
853
864
|
/**
|
|
854
|
-
* Derive addresses for all supported chains
|
|
865
|
+
* Derive addresses for all supported chains using WDK API
|
|
866
|
+
*
|
|
867
|
+
* Uses the backend WDK API for real cryptographically valid addresses.
|
|
868
|
+
* No placeholder fallback - WDK API is required for multi-chain addresses.
|
|
855
869
|
*/
|
|
856
870
|
async deriveAllAddresses(seed) {
|
|
857
871
|
await this.initialize();
|
|
@@ -879,7 +893,9 @@ var ZubariWdkService = class {
|
|
|
879
893
|
console.warn("Native WDK multi-chain derivation failed:", error);
|
|
880
894
|
}
|
|
881
895
|
}
|
|
882
|
-
|
|
896
|
+
throw new Error(
|
|
897
|
+
"WDK API required for multi-chain address derivation. Ensure the backend is running."
|
|
898
|
+
);
|
|
883
899
|
}
|
|
884
900
|
/**
|
|
885
901
|
* Get balances for all chains
|
|
@@ -1361,106 +1377,51 @@ var WalletManager = class _WalletManager {
|
|
|
1361
1377
|
* Uses the unified WDK service which:
|
|
1362
1378
|
* - In browser: Calls the backend API (which has Tether WDK)
|
|
1363
1379
|
* - In Node.js: Uses native WDK
|
|
1364
|
-
* - Falls back to browser-compatible derivation if needed
|
|
1365
|
-
*/
|
|
1366
|
-
static async deriveAddressForChainAsync(seed, chain, network = "testnet", apiUrl) {
|
|
1367
|
-
try {
|
|
1368
|
-
const wdkService = getZubariWdkService({ network, apiUrl });
|
|
1369
|
-
const result = await wdkService.deriveAddress(seed, chain);
|
|
1370
|
-
return result.address;
|
|
1371
|
-
} catch (error) {
|
|
1372
|
-
console.warn(`WDK service failed for ${chain}, using local derivation:`, error);
|
|
1373
|
-
}
|
|
1374
|
-
return _WalletManager.deriveAddressForChain(seed, chain);
|
|
1375
|
-
}
|
|
1376
|
-
/**
|
|
1377
|
-
* Format address for non-WDK chains (fallback)
|
|
1378
1380
|
*
|
|
1379
|
-
*
|
|
1380
|
-
* For real blockchain interaction, use the WDK API via deriveAddressForChainAsync().
|
|
1381
|
-
* These addresses should NOT be used for receiving funds without verification.
|
|
1381
|
+
* No fallback to placeholder addresses - WDK API is required for real addresses.
|
|
1382
1382
|
*/
|
|
1383
|
-
static
|
|
1383
|
+
static async deriveAddressForChainAsync(seed, chain, network = "testnet", apiUrl) {
|
|
1384
1384
|
if (chain === "ethereum") {
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
for (let i = 0; i < 38; i++) {
|
|
1393
|
-
const idx = parseInt(addressBytes.charAt(i % 40) || "0", 16) % btcChars.length;
|
|
1394
|
-
btcAddr += btcChars[idx];
|
|
1395
|
-
}
|
|
1396
|
-
return btcAddr;
|
|
1397
|
-
}
|
|
1398
|
-
case "ton": {
|
|
1399
|
-
const base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
1400
|
-
let tonAddr = "EQ";
|
|
1401
|
-
for (let i = 0; i < 46; i++) {
|
|
1402
|
-
const idx = parseInt(addressBytes.charAt(i % 40) || "0", 16) * 4 % base64Chars.length;
|
|
1403
|
-
tonAddr += base64Chars[idx];
|
|
1404
|
-
}
|
|
1405
|
-
return tonAddr;
|
|
1406
|
-
}
|
|
1407
|
-
case "tron": {
|
|
1408
|
-
const base58Chars = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
1409
|
-
let tronAddr = "T";
|
|
1410
|
-
for (let i = 0; i < 33; i++) {
|
|
1411
|
-
const idx = parseInt(addressBytes.charAt(i % 40) || "0", 16) * 3 % base58Chars.length;
|
|
1412
|
-
tronAddr += base58Chars[idx];
|
|
1413
|
-
}
|
|
1414
|
-
return tronAddr;
|
|
1415
|
-
}
|
|
1416
|
-
case "solana": {
|
|
1417
|
-
const base58Chars = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
1418
|
-
let solAddr = "";
|
|
1419
|
-
for (let i = 0; i < 44; i++) {
|
|
1420
|
-
const idx = parseInt(addressBytes.charAt(i % 40) || "0", 16) * 3 % base58Chars.length;
|
|
1421
|
-
solAddr += base58Chars[idx];
|
|
1422
|
-
}
|
|
1423
|
-
return solAddr;
|
|
1424
|
-
}
|
|
1425
|
-
case "spark": {
|
|
1426
|
-
const bech32Chars = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";
|
|
1427
|
-
let sparkAddr = "sp1q";
|
|
1428
|
-
for (let i = 0; i < 58; i++) {
|
|
1429
|
-
const idx = parseInt(addressBytes.charAt(i % 40) || "0", 16) % bech32Chars.length;
|
|
1430
|
-
sparkAddr += bech32Chars[idx];
|
|
1431
|
-
}
|
|
1432
|
-
return sparkAddr;
|
|
1385
|
+
try {
|
|
1386
|
+
const wdkService2 = getZubariWdkService({ network, apiUrl });
|
|
1387
|
+
const result2 = await wdkService2.deriveAddress(seed, chain);
|
|
1388
|
+
return result2.address;
|
|
1389
|
+
} catch (error) {
|
|
1390
|
+
console.warn("WDK service failed for Ethereum, using local derivation:", error);
|
|
1391
|
+
return _WalletManager.deriveAddressForChain(seed, "ethereum");
|
|
1433
1392
|
}
|
|
1434
|
-
default:
|
|
1435
|
-
return address;
|
|
1436
1393
|
}
|
|
1394
|
+
const wdkService = getZubariWdkService({ network, apiUrl });
|
|
1395
|
+
const result = await wdkService.deriveAddress(seed, chain);
|
|
1396
|
+
return result.address;
|
|
1437
1397
|
}
|
|
1438
1398
|
/**
|
|
1439
|
-
* Derive address for a specific chain (sync version
|
|
1440
|
-
*
|
|
1399
|
+
* Derive address for a specific chain (sync version)
|
|
1400
|
+
* Only supports Ethereum - for other chains use deriveAddressForChainAsync with WDK API
|
|
1441
1401
|
*
|
|
1442
|
-
*
|
|
1443
|
-
* deterministic but not cryptographically valid. Use WDK API for real addresses.
|
|
1402
|
+
* @throws Error for non-Ethereum chains - use WDK API instead
|
|
1444
1403
|
*/
|
|
1445
1404
|
static deriveAddressForChain(seed, chain) {
|
|
1446
|
-
const ethPath = DERIVATION_PATHS["ethereum"];
|
|
1447
|
-
const ethNode = ethers.HDNodeWallet.fromPhrase(seed, void 0, `${ethPath}/0`);
|
|
1448
1405
|
if (chain === "ethereum") {
|
|
1406
|
+
const ethPath = DERIVATION_PATHS["ethereum"];
|
|
1407
|
+
const ethNode = ethers.HDNodeWallet.fromPhrase(seed, void 0, `${ethPath}/0`);
|
|
1449
1408
|
return ethNode.address;
|
|
1450
1409
|
}
|
|
1451
|
-
|
|
1410
|
+
throw new Error(
|
|
1411
|
+
`Sync derivation not supported for ${chain}. Use deriveAddressForChainAsync() with WDK API.`
|
|
1412
|
+
);
|
|
1452
1413
|
}
|
|
1453
1414
|
/**
|
|
1454
1415
|
* Derive addresses for all enabled chains (sync version)
|
|
1416
|
+
* Only derives Ethereum address synchronously - use deriveAllAddressesAsync for all chains
|
|
1455
1417
|
*/
|
|
1456
1418
|
deriveAllAddresses() {
|
|
1457
1419
|
if (!this.currentSeed) {
|
|
1458
1420
|
throw new Error("Wallet is locked");
|
|
1459
1421
|
}
|
|
1460
|
-
const addresses = {
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
}
|
|
1422
|
+
const addresses = {
|
|
1423
|
+
ethereum: _WalletManager.deriveAddressForChain(this.currentSeed, "ethereum")
|
|
1424
|
+
};
|
|
1464
1425
|
this.derivedAddresses = addresses;
|
|
1465
1426
|
return addresses;
|
|
1466
1427
|
}
|
|
@@ -1521,11 +1482,11 @@ var WalletManager = class _WalletManager {
|
|
|
1521
1482
|
}
|
|
1522
1483
|
/**
|
|
1523
1484
|
* Derive addresses for all enabled chains using Tether WDK
|
|
1524
|
-
* The unified WDK service handles all fallback strategies automatically:
|
|
1525
|
-
* - Browser: API backend -> Browser derivation
|
|
1526
|
-
* - Node.js: Native WDK -> API backend -> Browser derivation
|
|
1527
1485
|
*
|
|
1528
|
-
*
|
|
1486
|
+
* Uses the WDK API backend for real cryptographically valid addresses.
|
|
1487
|
+
* First tries to load from storage to avoid losing previously derived addresses.
|
|
1488
|
+
*
|
|
1489
|
+
* @throws Error if WDK API is unavailable and no cached addresses exist
|
|
1529
1490
|
*/
|
|
1530
1491
|
async deriveAllAddressesAsync() {
|
|
1531
1492
|
if (!this.currentSeed) {
|
|
@@ -1542,26 +1503,21 @@ var WalletManager = class _WalletManager {
|
|
|
1542
1503
|
console.log("Stored addresses do not match current seed, re-deriving...");
|
|
1543
1504
|
}
|
|
1544
1505
|
}
|
|
1545
|
-
|
|
1546
|
-
return await this.deriveAllAddressesWithWdk();
|
|
1547
|
-
} catch (error) {
|
|
1548
|
-
console.error("All derivation strategies failed:", error);
|
|
1549
|
-
const ethAddress = _WalletManager.deriveAddress(this.currentSeed);
|
|
1550
|
-
this.derivedAddresses = { ethereum: ethAddress };
|
|
1551
|
-
return this.derivedAddresses;
|
|
1552
|
-
}
|
|
1506
|
+
return await this.deriveAllAddressesWithWdk();
|
|
1553
1507
|
}
|
|
1554
1508
|
/**
|
|
1555
1509
|
* Get address for a specific chain
|
|
1510
|
+
* Returns cached address or null - use deriveAllAddressesAsync to derive addresses
|
|
1556
1511
|
*/
|
|
1557
1512
|
getAddressForChain(chain) {
|
|
1558
|
-
if (
|
|
1559
|
-
return this.derivedAddresses[chain]
|
|
1513
|
+
if (this.derivedAddresses[chain]) {
|
|
1514
|
+
return this.derivedAddresses[chain];
|
|
1560
1515
|
}
|
|
1561
|
-
if (
|
|
1516
|
+
if (chain === "ethereum" && this.currentSeed) {
|
|
1562
1517
|
this.derivedAddresses[chain] = _WalletManager.deriveAddressForChain(this.currentSeed, chain);
|
|
1518
|
+
return this.derivedAddresses[chain];
|
|
1563
1519
|
}
|
|
1564
|
-
return
|
|
1520
|
+
return null;
|
|
1565
1521
|
}
|
|
1566
1522
|
/**
|
|
1567
1523
|
* Get all derived addresses
|
|
@@ -1783,6 +1739,94 @@ var WalletManager = class _WalletManager {
|
|
|
1783
1739
|
selectedChain: this.selectedChain
|
|
1784
1740
|
};
|
|
1785
1741
|
}
|
|
1742
|
+
/**
|
|
1743
|
+
* Send a transaction using Tether WDK
|
|
1744
|
+
* Supports native tokens and USDT on all chains
|
|
1745
|
+
*
|
|
1746
|
+
* @param chain - Target blockchain (ethereum, bitcoin, ton, tron, solana, spark)
|
|
1747
|
+
* @param to - Recipient address
|
|
1748
|
+
* @param amount - Amount to send (in human-readable format)
|
|
1749
|
+
* @param token - Optional token symbol (e.g., 'USDT' for stablecoins)
|
|
1750
|
+
* @returns Transaction result with hash and status
|
|
1751
|
+
*/
|
|
1752
|
+
async sendTransaction(chain, to, amount, token) {
|
|
1753
|
+
if (!this.currentSeed) {
|
|
1754
|
+
return { success: false, error: "Wallet is locked" };
|
|
1755
|
+
}
|
|
1756
|
+
const fromAddress = this.getAddressForChain(chain);
|
|
1757
|
+
if (!fromAddress) {
|
|
1758
|
+
return { success: false, error: `No address for chain ${chain}` };
|
|
1759
|
+
}
|
|
1760
|
+
try {
|
|
1761
|
+
const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/send`, {
|
|
1762
|
+
method: "POST",
|
|
1763
|
+
headers: { "Content-Type": "application/json" },
|
|
1764
|
+
body: JSON.stringify({
|
|
1765
|
+
seed: this.currentSeed,
|
|
1766
|
+
chain,
|
|
1767
|
+
to,
|
|
1768
|
+
amount,
|
|
1769
|
+
token,
|
|
1770
|
+
network: this.config.network
|
|
1771
|
+
})
|
|
1772
|
+
});
|
|
1773
|
+
if (response.ok) {
|
|
1774
|
+
const data = await response.json();
|
|
1775
|
+
console.log(`Transaction sent on ${chain}:`, data);
|
|
1776
|
+
return {
|
|
1777
|
+
success: data.success,
|
|
1778
|
+
txHash: data.txHash,
|
|
1779
|
+
from: fromAddress,
|
|
1780
|
+
to,
|
|
1781
|
+
amount,
|
|
1782
|
+
chain
|
|
1783
|
+
};
|
|
1784
|
+
}
|
|
1785
|
+
const errorData = await response.json().catch(() => ({}));
|
|
1786
|
+
return {
|
|
1787
|
+
success: false,
|
|
1788
|
+
error: errorData.error || `HTTP ${response.status}`
|
|
1789
|
+
};
|
|
1790
|
+
} catch (error) {
|
|
1791
|
+
console.error(`Transaction failed on ${chain}:`, error);
|
|
1792
|
+
return {
|
|
1793
|
+
success: false,
|
|
1794
|
+
error: error instanceof Error ? error.message : "Transaction failed"
|
|
1795
|
+
};
|
|
1796
|
+
}
|
|
1797
|
+
}
|
|
1798
|
+
/**
|
|
1799
|
+
* Estimate transaction fee using Tether WDK
|
|
1800
|
+
*/
|
|
1801
|
+
async estimateFee(chain, to, amount, token) {
|
|
1802
|
+
try {
|
|
1803
|
+
const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/estimate-fee`, {
|
|
1804
|
+
method: "POST",
|
|
1805
|
+
headers: { "Content-Type": "application/json" },
|
|
1806
|
+
body: JSON.stringify({
|
|
1807
|
+
chain,
|
|
1808
|
+
to,
|
|
1809
|
+
amount,
|
|
1810
|
+
token,
|
|
1811
|
+
network: this.config.network
|
|
1812
|
+
})
|
|
1813
|
+
});
|
|
1814
|
+
if (response.ok) {
|
|
1815
|
+
const data = await response.json();
|
|
1816
|
+
return {
|
|
1817
|
+
success: true,
|
|
1818
|
+
fee: data.fee,
|
|
1819
|
+
feeUsd: data.feeUsd
|
|
1820
|
+
};
|
|
1821
|
+
}
|
|
1822
|
+
return { success: false, error: "Failed to estimate fee" };
|
|
1823
|
+
} catch (error) {
|
|
1824
|
+
return {
|
|
1825
|
+
success: false,
|
|
1826
|
+
error: error instanceof Error ? error.message : "Fee estimation failed"
|
|
1827
|
+
};
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1786
1830
|
};
|
|
1787
1831
|
|
|
1788
1832
|
// src/react/useWalletManager.ts
|
|
@@ -1972,6 +2016,32 @@ function useWalletManager(options = {}) {
|
|
|
1972
2016
|
);
|
|
1973
2017
|
const hasWallet = react.useCallback(() => manager.hasWallet(), [manager]);
|
|
1974
2018
|
const getSeed = react.useCallback(() => manager.getSeed(), [manager]);
|
|
2019
|
+
const sendTransaction = react.useCallback(
|
|
2020
|
+
async (chain, to, amount, token) => {
|
|
2021
|
+
setIsLoading(true);
|
|
2022
|
+
try {
|
|
2023
|
+
const result = await manager.sendTransaction(chain, to, amount, token);
|
|
2024
|
+
if (result.success) {
|
|
2025
|
+
try {
|
|
2026
|
+
const balances = await manager.fetchAllBalances();
|
|
2027
|
+
setChainBalances(balances);
|
|
2028
|
+
} catch (err) {
|
|
2029
|
+
console.warn("Failed to refresh balances after transaction:", err);
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
2032
|
+
return result;
|
|
2033
|
+
} finally {
|
|
2034
|
+
setIsLoading(false);
|
|
2035
|
+
}
|
|
2036
|
+
},
|
|
2037
|
+
[manager]
|
|
2038
|
+
);
|
|
2039
|
+
const estimateFee = react.useCallback(
|
|
2040
|
+
async (chain, to, amount, token) => {
|
|
2041
|
+
return manager.estimateFee(chain, to, amount, token);
|
|
2042
|
+
},
|
|
2043
|
+
[manager]
|
|
2044
|
+
);
|
|
1975
2045
|
return {
|
|
1976
2046
|
state,
|
|
1977
2047
|
isLoading,
|
|
@@ -1990,6 +2060,9 @@ function useWalletManager(options = {}) {
|
|
|
1990
2060
|
getAddressForChain,
|
|
1991
2061
|
getAllAddresses,
|
|
1992
2062
|
supportedChains: SUPPORTED_CHAINS,
|
|
2063
|
+
// Transaction Actions (Powered by Tether WDK)
|
|
2064
|
+
sendTransaction,
|
|
2065
|
+
estimateFee,
|
|
1993
2066
|
// Utilities
|
|
1994
2067
|
hasWallet,
|
|
1995
2068
|
getSeed,
|