@talken/talkenkit 2.4.16 → 2.4.17
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/abcWallet-54KUGWUZ.js +192 -0
- package/dist/abcWallet-KZHOADBJ.js +192 -0
- package/dist/abcWallet-NZAVB4PI.js +190 -0
- package/dist/chunk-5X3ROW3U.js +8777 -0
- package/dist/chunk-DKA3NVFM.js +8497 -0
- package/dist/chunk-QNZ5HSPM.js +8339 -0
- package/dist/chunk-VE53ZNZV.js +331 -0
- package/dist/components/ConfirmationModal/ApproveSection.css.d.ts +16 -0
- package/dist/components/ConfirmationModal/ApproveSection.d.ts +8 -0
- package/dist/components/ConfirmationModal/NFTPlaceholder.css.d.ts +7 -0
- package/dist/components/ConfirmationModal/NFTPlaceholder.d.ts +8 -0
- package/dist/components/ConfirmationModal/NftApprovalSection.css.d.ts +10 -0
- package/dist/components/ConfirmationModal/NftApprovalSection.d.ts +7 -0
- package/dist/components/ConfirmationModal/SignConfirmationModal.css.d.ts +35 -0
- package/dist/components/ConfirmationModal/SignConfirmationModal.d.ts +17 -0
- package/dist/components/ConfirmationModal/SwapSection.css.d.ts +17 -0
- package/dist/components/ConfirmationModal/SwapSection.d.ts +7 -0
- package/dist/components/ConfirmationModal/TransactionConfirmationModal.css.d.ts +49 -0
- package/dist/components/ConfirmationModal/TransactionConfirmationModal.d.ts +12 -0
- package/dist/components/ConfirmationModal/TransferSection.css.d.ts +17 -0
- package/dist/components/ConfirmationModal/TransferSection.d.ts +7 -0
- package/dist/components/ConfirmationModal/commonStyles.css.d.ts +37 -0
- package/dist/components/ConfirmationModal/constants.d.ts +16 -0
- package/dist/components/ConfirmationModal/index.d.ts +9 -0
- package/dist/components/ConfirmationModal/modalTheme.css.d.ts +20 -0
- package/dist/components/ConfirmationModal/transactionUIRegistry.d.ts +134 -0
- package/dist/components/ConfirmationModal/utils.d.ts +37 -0
- package/dist/components/ConnectOptions/AbcWaasAuth/AbcWaasAuthSections.css.d.ts +1 -0
- package/dist/components/ConnectOptions/AbcWaasAuth/AbcWaasAuthSections.d.ts +1 -1
- package/dist/components/ConnectOptions/AbcWaasAuth/hooks/useAbcWaasAuth.d.ts +2 -25
- package/dist/components/ConnectOptions/AbcWaasAuth/hooks/useAbcWaasSocial.d.ts +1 -47
- package/dist/components/ConnectOptions/PinAuth/hooks/useWalletGeneration.d.ts +4 -21
- package/dist/components/GasFeeModal/GasFeeEditModal.css.d.ts +32 -0
- package/dist/components/GasFeeModal/GasFeeEditModal.d.ts +21 -0
- package/dist/components/GasFeeModal/index.d.ts +3 -0
- package/dist/components/GasFeeModal/modalTheme.css.d.ts +19 -0
- package/dist/components/Icons/Close2.d.ts +7 -0
- package/dist/components/Icons/Copy2.d.ts +4 -0
- package/dist/components/Icons/Dropdown2.d.ts +4 -0
- package/dist/components/Icons/Edit.d.ts +4 -0
- package/dist/components/Icons/InfoCircle.d.ts +4 -0
- package/dist/components/Icons/Kakao.d.ts +2 -0
- package/dist/components/Icons/Minus.d.ts +4 -0
- package/dist/components/Icons/Plus.d.ts +4 -0
- package/dist/components/Icons/SettingsGear.d.ts +4 -0
- package/dist/components/Icons/SpeedHigh.d.ts +4 -0
- package/dist/components/Icons/SpeedLow.d.ts +4 -0
- package/dist/components/Icons/SpeedMedium.d.ts +4 -0
- package/dist/components/RainbowKitProvider/InternalPinProvider.d.ts +7 -9
- package/dist/components/RainbowKitProvider/RainbowKitProvider.d.ts +7 -1
- package/dist/components/Toast/Toast.css.d.ts +2 -0
- package/dist/components/Toast/Toast.d.ts +6 -0
- package/dist/components/Toast/index.d.ts +4 -0
- package/dist/components/Toast/useToast.d.ts +10 -0
- package/dist/config/networks.d.ts +10 -0
- package/dist/css/sprinkles.css.d.ts +1 -1
- package/dist/hooks/useSolanaWallet.d.ts +5 -23
- package/dist/hooks/useTronWallet.d.ts +63 -0
- package/dist/index.css +1903 -236
- package/dist/index.d.ts +8 -3
- package/dist/index.js +7970 -4015
- package/dist/klipWallet-RD5Y4UEK.js +8 -0
- package/dist/providers/SignConfirmationProvider/SignConfirmationProvider.d.ts +22 -0
- package/dist/providers/SignConfirmationProvider/index.d.ts +6 -0
- package/dist/providers/SignConfirmationProvider/requestParsers.d.ts +24 -0
- package/dist/providers/SignConfirmationProvider/types.d.ts +91 -0
- package/dist/providers/SignConfirmationProvider/useApiClient.d.ts +15 -0
- package/dist/providers/SignConfirmationProvider/useTransactionResolver.d.ts +18 -0
- package/dist/secure-AEBFSVWE.js +8 -0
- package/dist/services/AbcAgenticWalletService.d.ts +111 -0
- package/dist/services/AbcAuthService.d.ts +26 -20
- package/dist/types/index.d.ts +3 -0
- package/dist/types/token.d.ts +82 -0
- package/dist/utils/abi/abiDecoder.d.ts +144 -0
- package/dist/utils/apiClientFactory.d.ts +21 -0
- package/dist/utils/blockies.d.ts +12 -0
- package/dist/utils/tokenMapper.d.ts +10 -0
- package/dist/wallets/walletConnectors/abcWallet/abcApi.d.ts +4 -1
- package/dist/wallets/walletConnectors/abcWallet/abcApi.js +7 -7
- package/dist/wallets/walletConnectors/abcWallet/abcBitcoinConnector.js +5 -5
- package/dist/wallets/walletConnectors/abcWallet/abcBitcoinProvider.d.ts +6 -8
- package/dist/wallets/walletConnectors/abcWallet/abcBitcoinProvider.js +1 -1
- package/dist/wallets/walletConnectors/abcWallet/abcConnector.js +9 -9
- package/dist/wallets/walletConnectors/abcWallet/abcProvider.d.ts +17 -6
- package/dist/wallets/walletConnectors/abcWallet/abcProvider.js +5 -4
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaProvider.d.ts +11 -34
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaProvider.js +1 -1
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaWalletAdapter.d.ts +3 -11
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaWalletAdapter.js +17 -80
- package/dist/wallets/walletConnectors/abcWallet/abcTronProvider.d.ts +112 -0
- package/dist/wallets/walletConnectors/abcWallet/abcTronProvider.js +11 -0
- package/dist/wallets/walletConnectors/abcWallet/abcWallet.d.ts +2 -0
- package/dist/wallets/walletConnectors/abcWallet/abcWallet.js +11 -10
- package/dist/wallets/walletConnectors/abcWallet/api/AuthApi.d.ts +9 -11
- package/dist/wallets/walletConnectors/abcWallet/api/AuthApi.js +6 -6
- package/dist/wallets/walletConnectors/abcWallet/api/BaseApiClient.d.ts +1 -1
- package/dist/wallets/walletConnectors/abcWallet/api/BaseApiClient.js +5 -5
- package/dist/wallets/walletConnectors/abcWallet/api/BitcoinApi.js +6 -6
- package/dist/wallets/walletConnectors/abcWallet/api/GasApi.d.ts +45 -0
- package/dist/wallets/walletConnectors/abcWallet/api/GasApi.js +12 -0
- package/dist/wallets/walletConnectors/abcWallet/api/SigningApi.js +7 -7
- package/dist/wallets/walletConnectors/abcWallet/api/SolanaApi.d.ts +9 -1
- package/dist/wallets/walletConnectors/abcWallet/api/SolanaApi.js +7 -7
- package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiClient.d.ts +333 -0
- package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiClient.js +11 -0
- package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiSingleton.d.ts +18 -0
- package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiSingleton.js +14 -0
- package/dist/wallets/walletConnectors/abcWallet/api/TransactionApi.d.ts +2 -2
- package/dist/wallets/walletConnectors/abcWallet/api/TransactionApi.js +7 -7
- package/dist/wallets/walletConnectors/abcWallet/api/TronApi.d.ts +102 -0
- package/dist/wallets/walletConnectors/abcWallet/api/TronApi.js +12 -0
- package/dist/wallets/walletConnectors/abcWallet/api/WalletApi.d.ts +4 -2
- package/dist/wallets/walletConnectors/abcWallet/api/WalletApi.js +7 -7
- package/dist/wallets/walletConnectors/abcWallet/api/WalletscanApi.d.ts +60 -0
- package/dist/wallets/walletConnectors/abcWallet/api/WalletscanApi.js +12 -0
- package/dist/wallets/walletConnectors/abcWallet/api/index.d.ts +24 -0
- package/dist/wallets/walletConnectors/abcWallet/api/index.js +35 -17
- package/dist/wallets/walletConnectors/abcWallet/constants.d.ts +39 -1
- package/dist/wallets/walletConnectors/abcWallet/constants.js +5 -1
- package/dist/wallets/walletConnectors/abcWallet/googleAuth.d.ts +6 -0
- package/dist/wallets/walletConnectors/abcWallet/googleAuth.js +37 -1
- package/dist/wallets/walletConnectors/abcWallet/index.d.ts +5 -3
- package/dist/wallets/walletConnectors/abcWallet/index.js +44 -31
- package/dist/wallets/walletConnectors/abcWallet/kakaoAuth.d.ts +27 -0
- package/dist/wallets/walletConnectors/abcWallet/kakaoAuth.js +290 -0
- package/dist/wallets/walletConnectors/abcWallet/networkConfig.d.ts +39 -3
- package/dist/wallets/walletConnectors/abcWallet/networkConfig.js +11 -3
- package/dist/wallets/walletConnectors/abcWallet/secure.js +2 -2
- package/dist/wallets/walletConnectors/abcWallet/sessionUtils.js +1 -1
- package/dist/wallets/walletConnectors/abcWallet/types.d.ts +369 -7
- package/dist/wallets/walletConnectors/abcWallet/types.js +5 -3
- package/dist/wallets/walletConnectors/abcWallet/utils.js +3 -3
- package/dist/wallets/walletConnectors/abcWallet/walletGeneration.d.ts +10 -19
- package/dist/wallets/walletConnectors/abcWallet/walletGeneration.js +2 -2
- package/dist/wallets/walletConnectors/berasigWallet/berasigWallet.js +2 -2
- package/dist/wallets/walletConnectors/bifrostWallet/bifrostWallet.js +2 -2
- package/dist/wallets/walletConnectors/binanceWallet/binanceWallet.js +2 -2
- package/dist/wallets/walletConnectors/bitgetWallet/bitgetWallet.js +2 -2
- package/dist/wallets/walletConnectors/bybitWallet/bybitWallet.js +2 -2
- package/dist/wallets/walletConnectors/chunk-25V3FW3O.js +282 -0
- package/dist/wallets/walletConnectors/chunk-27346T3J.js +134 -0
- package/dist/wallets/walletConnectors/chunk-5CNLMOB2.js +75 -0
- package/dist/wallets/walletConnectors/chunk-5K45TCAM.js +333 -0
- package/dist/wallets/walletConnectors/chunk-5VDSMZC4.js +286 -0
- package/dist/wallets/walletConnectors/chunk-5W7RBMPH.js +351 -0
- package/dist/wallets/walletConnectors/chunk-5XORKEWE.js +326 -0
- package/dist/wallets/walletConnectors/chunk-63WBO52A.js +77 -0
- package/dist/wallets/walletConnectors/chunk-7IRF225N.js +75 -0
- package/dist/wallets/walletConnectors/chunk-7QHCSJDN.js +726 -0
- package/dist/wallets/walletConnectors/chunk-A27H6PEU.js +739 -0
- package/dist/wallets/walletConnectors/chunk-A4WR3CFN.js +130 -0
- package/dist/wallets/walletConnectors/chunk-A6FUNQWF.js +572 -0
- package/dist/wallets/walletConnectors/chunk-AF4OCS7N.js +46 -0
- package/dist/wallets/walletConnectors/chunk-AFWBXEEC.js +66 -0
- package/dist/wallets/walletConnectors/chunk-AUGP2LJR.js +182 -0
- package/dist/wallets/walletConnectors/chunk-AWLDVQXC.js +317 -0
- package/dist/wallets/walletConnectors/chunk-BLEKTKBN.js +479 -0
- package/dist/wallets/walletConnectors/chunk-BVL6G5HI.js +1757 -0
- package/dist/wallets/walletConnectors/chunk-CMTGEHDI.js +485 -0
- package/dist/wallets/walletConnectors/chunk-D5EFTEOM.js +56 -0
- package/dist/wallets/walletConnectors/chunk-DM5NLSWD.js +346 -0
- package/dist/wallets/walletConnectors/chunk-EBGI4D2T.js +69 -0
- package/dist/wallets/walletConnectors/chunk-EEH2HMFG.js +47 -0
- package/dist/wallets/walletConnectors/chunk-F5JWDBKK.js +47 -0
- package/dist/wallets/walletConnectors/chunk-FN67MIIH.js +75 -0
- package/dist/wallets/walletConnectors/chunk-FWYVBX5F.js +75 -0
- package/dist/wallets/walletConnectors/chunk-GH6ZDY4K.js +58 -0
- package/dist/wallets/walletConnectors/chunk-GIJZMIBD.js +63 -0
- package/dist/wallets/walletConnectors/chunk-GO6OLTNF.js +479 -0
- package/dist/wallets/walletConnectors/chunk-HKXBK3NY.js +75 -0
- package/dist/wallets/walletConnectors/chunk-HMD2WWFQ.js +75 -0
- package/dist/wallets/walletConnectors/chunk-HO5Z2CTL.js +280 -0
- package/dist/wallets/walletConnectors/chunk-I3GFVK5O.js +151 -0
- package/dist/wallets/walletConnectors/chunk-IUHZ5ZCE.js +121 -0
- package/dist/wallets/walletConnectors/chunk-JODNZWWG.js +330 -0
- package/dist/wallets/walletConnectors/chunk-JTST3KMW.js +75 -0
- package/dist/wallets/walletConnectors/chunk-KH2L3ONV.js +1599 -0
- package/dist/wallets/walletConnectors/chunk-LHV22375.js +182 -0
- package/dist/wallets/walletConnectors/chunk-LZZE462U.js +315 -0
- package/dist/wallets/walletConnectors/chunk-MGCRUAHX.js +276 -0
- package/dist/wallets/walletConnectors/chunk-MURSKRMJ.js +63 -0
- package/dist/wallets/walletConnectors/chunk-NG7PSAPX.js +115 -0
- package/dist/wallets/walletConnectors/chunk-NHP6D6AH.js +204 -0
- package/dist/wallets/walletConnectors/chunk-O4AU63LK.js +181 -0
- package/dist/wallets/walletConnectors/chunk-OBS74J5N.js +221 -0
- package/dist/wallets/walletConnectors/chunk-ON4U54WO.js +115 -0
- package/dist/wallets/walletConnectors/chunk-PPYBE5TV.js +276 -0
- package/dist/wallets/walletConnectors/chunk-PWWSAM4G.js +309 -0
- package/dist/wallets/walletConnectors/chunk-QB5GDLRU.js +330 -0
- package/dist/wallets/walletConnectors/chunk-QMLG7MAP.js +107 -0
- package/dist/wallets/walletConnectors/chunk-RGIB7FFH.js +47 -0
- package/dist/wallets/walletConnectors/chunk-SHJBMDP4.js +278 -0
- package/dist/wallets/walletConnectors/chunk-SOBJYYIX.js +484 -0
- package/dist/wallets/walletConnectors/chunk-T66U3ADD.js +58 -0
- package/dist/wallets/walletConnectors/chunk-THCKLFSJ.js +75 -0
- package/dist/wallets/walletConnectors/chunk-TS466TDR.js +286 -0
- package/dist/wallets/walletConnectors/chunk-UJGFYQEV.js +459 -0
- package/dist/wallets/walletConnectors/chunk-UXNEBBUV.js +224 -0
- package/dist/wallets/walletConnectors/chunk-VRCNFVPM.js +276 -0
- package/dist/wallets/walletConnectors/chunk-WODNUC65.js +333 -0
- package/dist/wallets/walletConnectors/chunk-X6A2FSHK.js +484 -0
- package/dist/wallets/walletConnectors/chunk-XVRNEES5.js +1541 -0
- package/dist/wallets/walletConnectors/chunk-XWVM2Y5A.js +306 -0
- package/dist/wallets/walletConnectors/chunk-XXG7ABSJ.js +328 -0
- package/dist/wallets/walletConnectors/chunk-YJH4BHSB.js +254 -0
- package/dist/wallets/walletConnectors/chunk-YRDNIP2H.js +90 -0
- package/dist/wallets/walletConnectors/chunk-YTPAWPCA.js +156 -0
- package/dist/wallets/walletConnectors/chunk-ZCSHD7UG.js +562 -0
- package/dist/wallets/walletConnectors/chunk-ZZCZ3RJU.js +272 -0
- package/dist/wallets/walletConnectors/clvWallet/clvWallet.js +2 -2
- package/dist/wallets/walletConnectors/coin98Wallet/coin98Wallet.js +2 -2
- package/dist/wallets/walletConnectors/coreWallet/coreWallet.js +2 -2
- package/dist/wallets/walletConnectors/foxWallet/foxWallet.js +2 -2
- package/dist/wallets/walletConnectors/frontierWallet/frontierWallet.js +2 -2
- package/dist/wallets/walletConnectors/gateWallet/gateWallet.js +2 -2
- package/dist/wallets/walletConnectors/index.js +57 -56
- package/dist/wallets/walletConnectors/iopayWallet/iopayWallet.js +2 -2
- package/dist/wallets/walletConnectors/kaiaWallet/kaiaWallet.js +2 -2
- package/dist/wallets/walletConnectors/kaikasWallet/kaikasWallet.js +2 -2
- package/dist/wallets/walletConnectors/klipWallet/klipWallet.d.ts +3 -0
- package/dist/wallets/walletConnectors/klipWallet/klipWallet.js +8 -0
- package/dist/wallets/walletConnectors/klipWallet-PPTYYB5G.js +7 -0
- package/dist/wallets/walletConnectors/metaMaskWallet/metaMaskWallet.js +2 -2
- package/dist/wallets/walletConnectors/okxWallet/okxWallet.js +2 -2
- package/dist/wallets/walletConnectors/rainbowWallet/rainbowWallet.js +2 -2
- package/dist/wallets/walletConnectors/roninWallet/roninWallet.js +2 -2
- package/dist/wallets/walletConnectors/safepalWallet/safepalWallet.js +2 -2
- package/dist/wallets/walletConnectors/subWallet/subWallet.js +2 -2
- package/dist/wallets/walletConnectors/tokenPocketWallet/tokenPocketWallet.js +2 -2
- package/dist/wallets/walletConnectors/trustWallet/trustWallet.js +2 -2
- package/dist/wallets/walletConnectors/zealWallet/zealWallet.js +2 -2
- package/dist/wallets/walletConnectors/zerionWallet/zerionWallet.js +2 -2
- package/package.json +2 -1
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/wallets/walletConnectors/abcWallet/abcBitcoinProvider.ts
|
|
4
|
+
import { getTalkenApiClient } from "@talken/talkenkit";
|
|
5
|
+
var EventEmitter = class {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.events = /* @__PURE__ */ new Map();
|
|
8
|
+
}
|
|
9
|
+
on(event, listener) {
|
|
10
|
+
if (!this.events.has(event)) {
|
|
11
|
+
this.events.set(event, []);
|
|
12
|
+
}
|
|
13
|
+
this.events.get(event).push(listener);
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
off(event, listener) {
|
|
17
|
+
const listeners = this.events.get(event);
|
|
18
|
+
if (listeners) {
|
|
19
|
+
const index = listeners.indexOf(listener);
|
|
20
|
+
if (index !== -1) {
|
|
21
|
+
listeners.splice(index, 1);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
removeListener(event, listener) {
|
|
27
|
+
return this.off(event, listener);
|
|
28
|
+
}
|
|
29
|
+
emit(event, ...args) {
|
|
30
|
+
const listeners = this.events.get(event);
|
|
31
|
+
if (listeners) {
|
|
32
|
+
for (const listener of listeners) {
|
|
33
|
+
listener(...args);
|
|
34
|
+
}
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
removeAllListeners(event) {
|
|
40
|
+
if (event) {
|
|
41
|
+
this.events.delete(event);
|
|
42
|
+
} else {
|
|
43
|
+
this.events.clear();
|
|
44
|
+
}
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var BitcoinErrorCode = {
|
|
49
|
+
USER_REJECTED: 4001,
|
|
50
|
+
UNAUTHORIZED: 4100,
|
|
51
|
+
UNSUPPORTED_METHOD: 4200,
|
|
52
|
+
DISCONNECTED: 4900,
|
|
53
|
+
INVALID_PARAMS: -32602,
|
|
54
|
+
INTERNAL_ERROR: -32603,
|
|
55
|
+
INSUFFICIENT_FUNDS: 5001,
|
|
56
|
+
UTXO_NOT_FOUND: 5002
|
|
57
|
+
};
|
|
58
|
+
var BitcoinProviderError = class extends Error {
|
|
59
|
+
constructor(code, message, data) {
|
|
60
|
+
super(message);
|
|
61
|
+
this.code = code;
|
|
62
|
+
this.data = data;
|
|
63
|
+
this.name = "BitcoinProviderError";
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var BITCOIN_NETWORKS = {
|
|
67
|
+
mainnet: {
|
|
68
|
+
name: "Bitcoin Mainnet",
|
|
69
|
+
type: "bitcoin",
|
|
70
|
+
explorer: "https://blockstream.info"
|
|
71
|
+
},
|
|
72
|
+
testnet: {
|
|
73
|
+
name: "Bitcoin Testnet",
|
|
74
|
+
type: "bitcoin_testnet",
|
|
75
|
+
explorer: "https://blockstream.info/testnet"
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
var AbcBitcoinProvider = class extends EventEmitter {
|
|
79
|
+
// 1 minute
|
|
80
|
+
constructor(client) {
|
|
81
|
+
super();
|
|
82
|
+
this.wallet = null;
|
|
83
|
+
this.network = BITCOIN_NETWORKS.testnet;
|
|
84
|
+
this.connected = false;
|
|
85
|
+
this.utxoCache = /* @__PURE__ */ new Map();
|
|
86
|
+
this.cacheExpiry = /* @__PURE__ */ new Map();
|
|
87
|
+
this.CACHE_TTL = 6e4;
|
|
88
|
+
this.client = client;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Set wallet information
|
|
92
|
+
*/
|
|
93
|
+
setWallet(wallet) {
|
|
94
|
+
const previousAddress = this.wallet?.address;
|
|
95
|
+
this.wallet = wallet;
|
|
96
|
+
this.connected = true;
|
|
97
|
+
if (wallet.network === "bitcoin") {
|
|
98
|
+
this.network = BITCOIN_NETWORKS.mainnet;
|
|
99
|
+
} else {
|
|
100
|
+
this.network = BITCOIN_NETWORKS.testnet;
|
|
101
|
+
}
|
|
102
|
+
if (previousAddress !== wallet.address) {
|
|
103
|
+
this.emit("accountsChanged", [wallet.address]);
|
|
104
|
+
this.clearUtxoCache();
|
|
105
|
+
}
|
|
106
|
+
this.emit("connect", {
|
|
107
|
+
address: wallet.address,
|
|
108
|
+
network: this.network.type
|
|
109
|
+
});
|
|
110
|
+
console.log(
|
|
111
|
+
"[BitcoinProvider] \u2705 Wallet connected:",
|
|
112
|
+
`${wallet.address.substring(0, 6)}...${wallet.address.substring(wallet.address.length - 6)}`
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Clear wallet (disconnect)
|
|
117
|
+
*/
|
|
118
|
+
clearWallet() {
|
|
119
|
+
this.wallet = null;
|
|
120
|
+
this.connected = false;
|
|
121
|
+
this.clearUtxoCache();
|
|
122
|
+
this.emit("disconnect");
|
|
123
|
+
this.emit("accountsChanged", []);
|
|
124
|
+
console.log("[BitcoinProvider] \u{1F50C} Wallet disconnected");
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Set TalkenApiClient for backend-proxied transaction flow
|
|
128
|
+
* When set, sendTransaction will use a single API call instead of multi-step WaaS
|
|
129
|
+
*/
|
|
130
|
+
setTalkenApi(talkenApi) {
|
|
131
|
+
this.talkenApi = talkenApi;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Set network
|
|
135
|
+
*/
|
|
136
|
+
setNetwork(networkKey) {
|
|
137
|
+
const newNetwork = BITCOIN_NETWORKS[networkKey];
|
|
138
|
+
if (!newNetwork) {
|
|
139
|
+
throw new BitcoinProviderError(
|
|
140
|
+
BitcoinErrorCode.INVALID_PARAMS,
|
|
141
|
+
`Unknown network: ${networkKey}`
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
const previousType = this.network.type;
|
|
145
|
+
this.network = newNetwork;
|
|
146
|
+
if (previousType !== newNetwork.type) {
|
|
147
|
+
this.emit("networkChanged", newNetwork.type);
|
|
148
|
+
this.clearUtxoCache();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Get current network
|
|
153
|
+
*/
|
|
154
|
+
getNetwork() {
|
|
155
|
+
return this.network;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Check if connected
|
|
159
|
+
*/
|
|
160
|
+
isConnected() {
|
|
161
|
+
return this.connected && this.wallet !== null;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Get Bitcoin address
|
|
165
|
+
*/
|
|
166
|
+
async getAddress() {
|
|
167
|
+
if (!this.wallet) {
|
|
168
|
+
throw new BitcoinProviderError(
|
|
169
|
+
BitcoinErrorCode.DISCONNECTED,
|
|
170
|
+
"Wallet not connected"
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
return this.wallet.address;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Get compressed public key (33 bytes)
|
|
177
|
+
*/
|
|
178
|
+
async getPublicKey() {
|
|
179
|
+
if (!this.wallet) {
|
|
180
|
+
throw new BitcoinProviderError(
|
|
181
|
+
BitcoinErrorCode.DISCONNECTED,
|
|
182
|
+
"Wallet not connected"
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
return this.wallet.publicKey;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Get address type (bech32, p2pkh, etc.)
|
|
189
|
+
*/
|
|
190
|
+
getAddressType() {
|
|
191
|
+
if (!this.wallet) {
|
|
192
|
+
throw new BitcoinProviderError(
|
|
193
|
+
BitcoinErrorCode.DISCONNECTED,
|
|
194
|
+
"Wallet not connected"
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
return this.wallet.addressType;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Clear UTXO cache
|
|
201
|
+
*/
|
|
202
|
+
clearUtxoCache() {
|
|
203
|
+
this.utxoCache.clear();
|
|
204
|
+
this.cacheExpiry.clear();
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Check if cache is valid
|
|
208
|
+
*/
|
|
209
|
+
isCacheValid(address) {
|
|
210
|
+
const expiry = this.cacheExpiry.get(address);
|
|
211
|
+
if (!expiry)
|
|
212
|
+
return false;
|
|
213
|
+
return Date.now() < expiry;
|
|
214
|
+
}
|
|
215
|
+
normalizeUtxos(rawUtxos) {
|
|
216
|
+
return rawUtxos.map((u) => ({
|
|
217
|
+
txid: String(u?.txid ?? u?.tx_hash ?? ""),
|
|
218
|
+
vout: Number(u?.vout ?? u?.output_index ?? 0),
|
|
219
|
+
value: Number(u?.value ?? u?.satoshis ?? 0),
|
|
220
|
+
scriptPubKey: String(
|
|
221
|
+
u?.scriptPubKey ?? u?.script_pub_key ?? u?.script ?? ""
|
|
222
|
+
),
|
|
223
|
+
confirmations: Number(u?.confirmations ?? 0)
|
|
224
|
+
})).filter(
|
|
225
|
+
(u) => Boolean(u.txid) && Number.isFinite(u.vout) && Number.isFinite(u.value) && Number.isFinite(u.confirmations)
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Get UTXOs for address (with caching)
|
|
230
|
+
*/
|
|
231
|
+
async getUtxos(forceRefresh = false) {
|
|
232
|
+
if (!this.wallet) {
|
|
233
|
+
throw new BitcoinProviderError(
|
|
234
|
+
BitcoinErrorCode.DISCONNECTED,
|
|
235
|
+
"Wallet not connected"
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
const address = this.wallet.address;
|
|
239
|
+
if (!forceRefresh && this.isCacheValid(address)) {
|
|
240
|
+
const cached = this.utxoCache.get(address);
|
|
241
|
+
if (cached) {
|
|
242
|
+
console.log(
|
|
243
|
+
`[BitcoinProvider] \u{1F4E6} Using cached UTXOs (${cached.length} items)`
|
|
244
|
+
);
|
|
245
|
+
return cached;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
try {
|
|
249
|
+
console.log("[BitcoinProvider] \u{1F50D} Fetching UTXOs from network...");
|
|
250
|
+
const api = this.talkenApi || getTalkenApiClient();
|
|
251
|
+
const result = await api.bitcoin.getUtxos(this.network.type, address);
|
|
252
|
+
const utxos = this.normalizeUtxos(result.utxos || []);
|
|
253
|
+
this.utxoCache.set(address, utxos);
|
|
254
|
+
this.cacheExpiry.set(address, Date.now() + this.CACHE_TTL);
|
|
255
|
+
console.log(`[BitcoinProvider] \u2705 Fetched ${utxos.length} UTXOs`);
|
|
256
|
+
return utxos;
|
|
257
|
+
} catch (error) {
|
|
258
|
+
console.error(
|
|
259
|
+
"[BitcoinProvider] \u274C Failed to fetch UTXOs:",
|
|
260
|
+
error.message
|
|
261
|
+
);
|
|
262
|
+
throw new BitcoinProviderError(
|
|
263
|
+
BitcoinErrorCode.INTERNAL_ERROR,
|
|
264
|
+
"Failed to fetch UTXOs",
|
|
265
|
+
error
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Get total balance (sum of all UTXOs)
|
|
271
|
+
* Returns balance in satoshis
|
|
272
|
+
*/
|
|
273
|
+
async getBalance(forceRefresh = false) {
|
|
274
|
+
const utxos = await this.getUtxos(forceRefresh);
|
|
275
|
+
const balance = utxos.reduce((sum, utxo) => sum + utxo.value, 0);
|
|
276
|
+
console.log(
|
|
277
|
+
`[BitcoinProvider] \u{1F4B0} Balance: ${balance} satoshis (${balance / 1e8} BTC)`
|
|
278
|
+
);
|
|
279
|
+
return balance;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Estimate transaction fee
|
|
283
|
+
* Returns fee rate in satoshis per byte
|
|
284
|
+
*/
|
|
285
|
+
async estimateFee(targetBlocks = 6) {
|
|
286
|
+
try {
|
|
287
|
+
const api = this.talkenApi || getTalkenApiClient();
|
|
288
|
+
const result = await api.bitcoin.getFeeRate(
|
|
289
|
+
this.network.type,
|
|
290
|
+
targetBlocks
|
|
291
|
+
);
|
|
292
|
+
const feeRate = Number(result.feeRate);
|
|
293
|
+
if (!Number.isFinite(feeRate) || feeRate <= 0) {
|
|
294
|
+
throw new Error("Invalid fee rate");
|
|
295
|
+
}
|
|
296
|
+
console.log(`[BitcoinProvider] \u26FD Fee rate: ${feeRate} sat/byte`);
|
|
297
|
+
return feeRate;
|
|
298
|
+
} catch (_error) {
|
|
299
|
+
console.error("[BitcoinProvider] \u26A0\uFE0F Fee estimation failed, using default");
|
|
300
|
+
return 1;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Sign Bitcoin message (BIP-322)
|
|
305
|
+
* NOTE: Currently not supported - Bitcoin uses v2 API which doesn't have message signing endpoint
|
|
306
|
+
* Only transaction signing is supported via PSBT
|
|
307
|
+
*
|
|
308
|
+
* @param _message - Message to sign (string) - unused, always throws error
|
|
309
|
+
* @returns Signature in base64 format
|
|
310
|
+
*/
|
|
311
|
+
async signMessage(_message) {
|
|
312
|
+
console.log("[BitcoinProvider] \u26A0\uFE0F Bitcoin message signing requested");
|
|
313
|
+
throw new BitcoinProviderError(
|
|
314
|
+
BitcoinErrorCode.UNSUPPORTED_METHOD,
|
|
315
|
+
"Bitcoin message signing is not supported. Bitcoin uses v2 API which only supports transaction signing (PSBT). Use signTransaction() instead."
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* High-level transaction sending (like Solana pattern)
|
|
320
|
+
* Creates, signs, and broadcasts transaction
|
|
321
|
+
*
|
|
322
|
+
* @param params - Transaction parameters
|
|
323
|
+
* @param params.toAddress - Recipient Bitcoin address
|
|
324
|
+
* @param params.amount - Amount in BTC (will be converted to satoshis)
|
|
325
|
+
* @returns Transaction hash
|
|
326
|
+
*/
|
|
327
|
+
async sendTransaction(params) {
|
|
328
|
+
if (!this.wallet) {
|
|
329
|
+
throw new BitcoinProviderError(
|
|
330
|
+
BitcoinErrorCode.DISCONNECTED,
|
|
331
|
+
"Wallet not connected"
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
try {
|
|
335
|
+
console.log("[BitcoinProvider] \u{1F4B8} Starting high-level transaction...");
|
|
336
|
+
const pinHash = localStorage.getItem("talkenkit_abc_pin_hash");
|
|
337
|
+
if (!pinHash) {
|
|
338
|
+
throw new BitcoinProviderError(
|
|
339
|
+
BitcoinErrorCode.INTERNAL_ERROR,
|
|
340
|
+
"PIN hash not found. Please login again."
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
const satoshis = Math.floor(params.amount * 1e8);
|
|
344
|
+
const api = this.talkenApi || getTalkenApiClient();
|
|
345
|
+
const result = await api.bitcoin.sendTransaction({
|
|
346
|
+
toAddress: params.toAddress,
|
|
347
|
+
amountSats: satoshis.toString(),
|
|
348
|
+
pin: pinHash
|
|
349
|
+
});
|
|
350
|
+
console.log(
|
|
351
|
+
"[BitcoinProvider] \u2705 BTC transaction complete via TalkenApiClient:",
|
|
352
|
+
result.txHash
|
|
353
|
+
);
|
|
354
|
+
this.emit("transactionBroadcasted", {
|
|
355
|
+
txHash: result.txHash,
|
|
356
|
+
explorerUrl: `${this.network.explorer}/tx/${result.txHash}`
|
|
357
|
+
});
|
|
358
|
+
this.clearUtxoCache();
|
|
359
|
+
return result.txHash;
|
|
360
|
+
} catch (error) {
|
|
361
|
+
if (error.message?.includes("cancelled") || error.message?.includes("rejected")) {
|
|
362
|
+
console.log("[BitcoinProvider] \u2139\uFE0F User cancelled transaction");
|
|
363
|
+
throw new BitcoinProviderError(
|
|
364
|
+
BitcoinErrorCode.USER_REJECTED,
|
|
365
|
+
"User rejected transaction",
|
|
366
|
+
error
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
console.error("[BitcoinProvider] \u274C Transaction failed:", error.message);
|
|
370
|
+
if (error.message?.includes("insufficient")) {
|
|
371
|
+
throw new BitcoinProviderError(
|
|
372
|
+
BitcoinErrorCode.INSUFFICIENT_FUNDS,
|
|
373
|
+
"Insufficient BTC balance",
|
|
374
|
+
error
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
this.emit("error", error);
|
|
378
|
+
throw new BitcoinProviderError(
|
|
379
|
+
BitcoinErrorCode.INTERNAL_ERROR,
|
|
380
|
+
"Failed to send transaction",
|
|
381
|
+
error
|
|
382
|
+
);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Broadcast signed transaction to network
|
|
387
|
+
*
|
|
388
|
+
* @param rawTransaction - Raw transaction in hex format
|
|
389
|
+
* @param psbt - Optional finalized PSBT
|
|
390
|
+
* @returns Transaction hash
|
|
391
|
+
*/
|
|
392
|
+
async broadcastTransaction(rawTransaction, psbt) {
|
|
393
|
+
if (!this.wallet) {
|
|
394
|
+
throw new BitcoinProviderError(
|
|
395
|
+
BitcoinErrorCode.DISCONNECTED,
|
|
396
|
+
"Wallet not connected"
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
try {
|
|
400
|
+
console.log("[BitcoinProvider] \u{1F4E1} Broadcasting transaction...");
|
|
401
|
+
if (psbt) {
|
|
402
|
+
console.log(
|
|
403
|
+
"[BitcoinProvider] \u2139\uFE0F PSBT argument provided; raw tx broadcast uses rawTransaction only via talken-api"
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
const api = this.talkenApi || getTalkenApiClient();
|
|
407
|
+
const result = await api.bitcoin.broadcastRawTransaction({
|
|
408
|
+
network: this.network.type,
|
|
409
|
+
rawTransaction
|
|
410
|
+
});
|
|
411
|
+
console.log(
|
|
412
|
+
"[BitcoinProvider] \u2705 Transaction broadcasted:",
|
|
413
|
+
result.txHash
|
|
414
|
+
);
|
|
415
|
+
this.emit("transactionBroadcasted", {
|
|
416
|
+
txHash: result.txHash,
|
|
417
|
+
explorerUrl: `${this.network.explorer}/tx/${result.txHash}`
|
|
418
|
+
});
|
|
419
|
+
this.clearUtxoCache();
|
|
420
|
+
return result.txHash;
|
|
421
|
+
} catch (error) {
|
|
422
|
+
console.error(
|
|
423
|
+
"[BitcoinProvider] \u274C Transaction broadcast failed:",
|
|
424
|
+
error.message
|
|
425
|
+
);
|
|
426
|
+
this.emit("error", error);
|
|
427
|
+
throw new BitcoinProviderError(
|
|
428
|
+
BitcoinErrorCode.INTERNAL_ERROR,
|
|
429
|
+
"Failed to broadcast transaction",
|
|
430
|
+
error
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Get wallet info
|
|
436
|
+
*/
|
|
437
|
+
getWalletInfo() {
|
|
438
|
+
if (!this.wallet)
|
|
439
|
+
return null;
|
|
440
|
+
return {
|
|
441
|
+
address: this.wallet.address,
|
|
442
|
+
publicKey: this.wallet.publicKey,
|
|
443
|
+
addressType: this.wallet.addressType,
|
|
444
|
+
network: this.network.type
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Refresh UTXO cache
|
|
449
|
+
*/
|
|
450
|
+
async refreshUtxos() {
|
|
451
|
+
return this.getUtxos(true);
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
export {
|
|
456
|
+
BitcoinProviderError,
|
|
457
|
+
BITCOIN_NETWORKS,
|
|
458
|
+
AbcBitcoinProvider
|
|
459
|
+
};
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
BaseApiClient
|
|
4
|
+
} from "./chunk-XWVM2Y5A.js";
|
|
5
|
+
import {
|
|
6
|
+
ABC_ENDPOINTS
|
|
7
|
+
} from "./chunk-OBS74J5N.js";
|
|
8
|
+
|
|
9
|
+
// src/wallets/walletConnectors/abcWallet/api/WalletscanApi.ts
|
|
10
|
+
var WalletscanApi = class extends BaseApiClient {
|
|
11
|
+
/**
|
|
12
|
+
* Get token metadata from Walletscan API
|
|
13
|
+
* GET /wapi/v2/walletscan/token/{contractAddress}?networks=xxx&minimalInfo=false
|
|
14
|
+
*
|
|
15
|
+
* @param params - Contract address and networks
|
|
16
|
+
* @returns Token metadata or null if not found/failed
|
|
17
|
+
*/
|
|
18
|
+
async getContractToken(params) {
|
|
19
|
+
try {
|
|
20
|
+
const url = `${ABC_ENDPOINTS.WALLETSCAN_TOKEN}/${params.contractAddress}`;
|
|
21
|
+
const queryParams = new URLSearchParams({
|
|
22
|
+
networks: params.networks
|
|
23
|
+
});
|
|
24
|
+
if (params.minimalInfo !== void 0) {
|
|
25
|
+
queryParams.set("minimalInfo", String(params.minimalInfo));
|
|
26
|
+
}
|
|
27
|
+
const response = await this.request(
|
|
28
|
+
`${url}?${queryParams.toString()}`,
|
|
29
|
+
{
|
|
30
|
+
method: "GET",
|
|
31
|
+
skipAuth: false
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
if (response.status === "success") {
|
|
35
|
+
const tokenData = response.data ?? response.result;
|
|
36
|
+
if (Array.isArray(tokenData) && tokenData.length > 0) {
|
|
37
|
+
return tokenData[0];
|
|
38
|
+
}
|
|
39
|
+
if (tokenData && !Array.isArray(tokenData)) {
|
|
40
|
+
return tokenData;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (Array.isArray(response) && response.length > 0) {
|
|
44
|
+
return response[0];
|
|
45
|
+
}
|
|
46
|
+
if (response.symbol) {
|
|
47
|
+
return response;
|
|
48
|
+
}
|
|
49
|
+
console.warn(
|
|
50
|
+
"[WalletscanApi] No token metadata in response:",
|
|
51
|
+
params.contractAddress
|
|
52
|
+
);
|
|
53
|
+
return null;
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.warn(
|
|
56
|
+
"[WalletscanApi] Failed to fetch token metadata:",
|
|
57
|
+
params.contractAddress,
|
|
58
|
+
error
|
|
59
|
+
);
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get token metadata with timeout
|
|
65
|
+
*
|
|
66
|
+
* @param params - Contract address and networks
|
|
67
|
+
* @param timeoutMs - Timeout in milliseconds (default: 3000)
|
|
68
|
+
* @returns Token metadata or null if timeout/failed
|
|
69
|
+
*/
|
|
70
|
+
async getContractTokenWithTimeout(params, timeoutMs = 3e3) {
|
|
71
|
+
try {
|
|
72
|
+
const result = await Promise.race([
|
|
73
|
+
this.getContractToken(params),
|
|
74
|
+
new Promise(
|
|
75
|
+
(resolve) => setTimeout(() => resolve(null), timeoutMs)
|
|
76
|
+
)
|
|
77
|
+
]);
|
|
78
|
+
return result;
|
|
79
|
+
} catch (_error) {
|
|
80
|
+
console.warn(
|
|
81
|
+
"[WalletscanApi] Token metadata request timed out:",
|
|
82
|
+
params.contractAddress
|
|
83
|
+
);
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get native coin info for a wallet address
|
|
89
|
+
* GET /wapi/v2/walletscan/natives?walletAddress=xxx&networks=xxx
|
|
90
|
+
*
|
|
91
|
+
* @param params - Wallet address and networks
|
|
92
|
+
* @returns Array of native coins or empty array if failed
|
|
93
|
+
*/
|
|
94
|
+
async getNativeToken(params) {
|
|
95
|
+
try {
|
|
96
|
+
const queryParams = new URLSearchParams({
|
|
97
|
+
walletAddress: params.walletAddress,
|
|
98
|
+
networks: params.networks
|
|
99
|
+
});
|
|
100
|
+
if (params.minimalInfo !== void 0) {
|
|
101
|
+
queryParams.set("minimalInfo", String(params.minimalInfo));
|
|
102
|
+
}
|
|
103
|
+
const response = await this.request(
|
|
104
|
+
`${ABC_ENDPOINTS.WALLETSCAN_NATIVES}?${queryParams.toString()}`,
|
|
105
|
+
{
|
|
106
|
+
method: "GET",
|
|
107
|
+
skipAuth: false
|
|
108
|
+
}
|
|
109
|
+
);
|
|
110
|
+
if (response.status === "success") {
|
|
111
|
+
const tokenData = response.data ?? response.result;
|
|
112
|
+
if (Array.isArray(tokenData)) {
|
|
113
|
+
return tokenData;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (Array.isArray(response)) {
|
|
117
|
+
return response;
|
|
118
|
+
}
|
|
119
|
+
return [];
|
|
120
|
+
} catch (error) {
|
|
121
|
+
console.warn("[WalletscanApi] Failed to fetch native coins:", error);
|
|
122
|
+
return [];
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Get native coin info with timeout
|
|
127
|
+
*
|
|
128
|
+
* @param params - Wallet address and networks
|
|
129
|
+
* @param timeoutMs - Timeout in milliseconds (default: 3000)
|
|
130
|
+
* @returns First native coin or null if timeout/failed
|
|
131
|
+
*/
|
|
132
|
+
async getNativeTokenWithTimeout(params, timeoutMs = 3e3) {
|
|
133
|
+
try {
|
|
134
|
+
const natives = await Promise.race([
|
|
135
|
+
this.getNativeToken(params),
|
|
136
|
+
new Promise(
|
|
137
|
+
(resolve) => setTimeout(() => resolve([]), timeoutMs)
|
|
138
|
+
)
|
|
139
|
+
]);
|
|
140
|
+
return natives.length > 0 ? natives[0] : null;
|
|
141
|
+
} catch (_error) {
|
|
142
|
+
console.warn("[WalletscanApi] Native coin request timed out");
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Get NFT metadata from Walletscan API
|
|
148
|
+
* GET /wapi/v2/walletscan/nfts/{contractAddress}?walletAddress=xxx&networks=xxx
|
|
149
|
+
*
|
|
150
|
+
* @param params - Contract address, wallet address, and networks
|
|
151
|
+
* @returns Array of NFT metadata or empty array if failed
|
|
152
|
+
*/
|
|
153
|
+
async getNFT(params) {
|
|
154
|
+
try {
|
|
155
|
+
const url = `${ABC_ENDPOINTS.WALLETSCAN_NFTS}/${params.contractAddress}`;
|
|
156
|
+
const queryParams = new URLSearchParams({
|
|
157
|
+
walletAddress: params.walletAddress,
|
|
158
|
+
networks: params.networks
|
|
159
|
+
});
|
|
160
|
+
if (params.minimalInfo !== void 0) {
|
|
161
|
+
queryParams.set("minimalInfo", String(params.minimalInfo));
|
|
162
|
+
}
|
|
163
|
+
const response = await this.request(
|
|
164
|
+
`${url}?${queryParams.toString()}`,
|
|
165
|
+
{
|
|
166
|
+
method: "GET",
|
|
167
|
+
skipAuth: false
|
|
168
|
+
}
|
|
169
|
+
);
|
|
170
|
+
if (response.status === "success") {
|
|
171
|
+
const nftData = response.data ?? response.result;
|
|
172
|
+
if (Array.isArray(nftData)) {
|
|
173
|
+
return nftData;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (Array.isArray(response)) {
|
|
177
|
+
return response;
|
|
178
|
+
}
|
|
179
|
+
if (response.contractAddress) {
|
|
180
|
+
return [response];
|
|
181
|
+
}
|
|
182
|
+
console.warn(
|
|
183
|
+
"[WalletscanApi] No NFT metadata in response:",
|
|
184
|
+
params.contractAddress
|
|
185
|
+
);
|
|
186
|
+
return [];
|
|
187
|
+
} catch (error) {
|
|
188
|
+
console.warn(
|
|
189
|
+
"[WalletscanApi] Failed to fetch NFT metadata:",
|
|
190
|
+
params.contractAddress,
|
|
191
|
+
error
|
|
192
|
+
);
|
|
193
|
+
return [];
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Get NFT metadata with timeout
|
|
198
|
+
*
|
|
199
|
+
* @param params - Contract address, wallet address, and networks
|
|
200
|
+
* @param timeoutMs - Timeout in milliseconds (default: 3000)
|
|
201
|
+
* @returns First NFT or null if timeout/failed/empty
|
|
202
|
+
*/
|
|
203
|
+
async getNFTWithTimeout(params, timeoutMs = 3e3) {
|
|
204
|
+
try {
|
|
205
|
+
const nfts = await Promise.race([
|
|
206
|
+
this.getNFT(params),
|
|
207
|
+
new Promise(
|
|
208
|
+
(resolve) => setTimeout(() => resolve([]), timeoutMs)
|
|
209
|
+
)
|
|
210
|
+
]);
|
|
211
|
+
return nfts.length > 0 ? nfts[0] : null;
|
|
212
|
+
} catch (_error) {
|
|
213
|
+
console.warn(
|
|
214
|
+
"[WalletscanApi] NFT metadata request timed out:",
|
|
215
|
+
params.contractAddress
|
|
216
|
+
);
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
export {
|
|
223
|
+
WalletscanApi
|
|
224
|
+
};
|