@ecency/wallets 1.4.7 → 1.4.9
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/browser/index.d.ts +24 -8
- package/dist/browser/index.js +113 -75
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +113 -75
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +113 -75
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/node/index.mjs
CHANGED
|
@@ -202,55 +202,67 @@ var cacheGet = (key) => {
|
|
|
202
202
|
const v = cache.get(key);
|
|
203
203
|
return v === undefinedValue ? void 0 : v;
|
|
204
204
|
};
|
|
205
|
-
|
|
205
|
+
var CURRENCY_TO_TOKEN_MAP = {
|
|
206
|
+
["BTC" /* BTC */]: "btc",
|
|
207
|
+
["ETH" /* ETH */]: "eth",
|
|
208
|
+
["SOL" /* SOL */]: "sol",
|
|
209
|
+
["TON" /* TON */]: "ton",
|
|
210
|
+
["TRX" /* TRON */]: "trx",
|
|
211
|
+
["APT" /* APT */]: "apt",
|
|
212
|
+
["BNB" /* BNB */]: "bnb",
|
|
213
|
+
HBD: "hbd",
|
|
214
|
+
HIVE: "hive"
|
|
215
|
+
};
|
|
216
|
+
var MARKET_DATA_CACHE_KEY = "market-data/latest";
|
|
217
|
+
var normalizeCurrencyToToken = (currency) => {
|
|
218
|
+
const upperCased = currency.toUpperCase();
|
|
219
|
+
return CURRENCY_TO_TOKEN_MAP[upperCased] ?? currency.toLowerCase();
|
|
220
|
+
};
|
|
221
|
+
function getTokenPriceQueryOptions(currency) {
|
|
206
222
|
return queryOptions({
|
|
207
|
-
queryKey: ["ecency-wallets", "
|
|
223
|
+
queryKey: ["ecency-wallets", "market-data", currency],
|
|
208
224
|
queryFn: async () => {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
break;
|
|
214
|
-
case "ETH" /* ETH */:
|
|
215
|
-
curr = "ethereum";
|
|
216
|
-
break;
|
|
217
|
-
case "SOL" /* SOL */:
|
|
218
|
-
curr = "solana";
|
|
219
|
-
break;
|
|
220
|
-
case "TON" /* TON */:
|
|
221
|
-
curr = "ton";
|
|
222
|
-
break;
|
|
223
|
-
case "TRX" /* TRON */:
|
|
224
|
-
curr = "tron";
|
|
225
|
-
break;
|
|
226
|
-
case "APT" /* APT */:
|
|
227
|
-
curr = "aptos";
|
|
228
|
-
break;
|
|
229
|
-
case "BNB" /* BNB */:
|
|
230
|
-
curr = "binancecoin";
|
|
231
|
-
break;
|
|
232
|
-
case "TON" /* TON */:
|
|
233
|
-
curr = "the-open-network";
|
|
234
|
-
break;
|
|
235
|
-
default:
|
|
236
|
-
curr = currency;
|
|
225
|
+
if (!currency) {
|
|
226
|
+
throw new Error(
|
|
227
|
+
"[SDK][Wallets][MarketData] \u2013 currency wasn`t provided"
|
|
228
|
+
);
|
|
237
229
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
}
|
|
230
|
+
if (!CONFIG.privateApiHost) {
|
|
231
|
+
throw new Error(
|
|
232
|
+
"[SDK][Wallets][MarketData] \u2013 privateApiHost isn`t configured"
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
const token = normalizeCurrencyToToken(currency);
|
|
236
|
+
let marketData = cacheGet(MARKET_DATA_CACHE_KEY);
|
|
237
|
+
if (!marketData) {
|
|
243
238
|
const httpResponse = await fetch(
|
|
244
|
-
|
|
239
|
+
`${CONFIG.privateApiHost}/private-api/market-data/latest`,
|
|
245
240
|
{
|
|
246
241
|
method: "GET"
|
|
247
242
|
}
|
|
248
243
|
);
|
|
244
|
+
if (!httpResponse.ok) {
|
|
245
|
+
throw new Error(
|
|
246
|
+
`[SDK][Wallets][MarketData] \u2013 failed to fetch latest market data (${httpResponse.status})`
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
249
|
const data = await httpResponse.json();
|
|
250
|
-
cacheSet(
|
|
251
|
-
|
|
250
|
+
cacheSet(MARKET_DATA_CACHE_KEY, data);
|
|
251
|
+
marketData = data;
|
|
252
|
+
}
|
|
253
|
+
const tokenData = marketData[token];
|
|
254
|
+
if (!tokenData) {
|
|
255
|
+
throw new Error(
|
|
256
|
+
`[SDK][Wallets][MarketData] \u2013 missing market data for token: ${token}`
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
const usdQuote = tokenData.quotes?.usd;
|
|
260
|
+
if (!usdQuote) {
|
|
261
|
+
throw new Error(
|
|
262
|
+
`[SDK][Wallets][MarketData] \u2013 missing USD quote for token: ${token}`
|
|
263
|
+
);
|
|
252
264
|
}
|
|
253
|
-
return
|
|
265
|
+
return Number(usdQuote.price);
|
|
254
266
|
},
|
|
255
267
|
enabled: !!currency
|
|
256
268
|
});
|
|
@@ -746,11 +758,12 @@ function getHbdAssetGeneralInfoQueryOptions(username) {
|
|
|
746
758
|
);
|
|
747
759
|
let price = 1;
|
|
748
760
|
try {
|
|
749
|
-
|
|
750
|
-
"
|
|
761
|
+
await CONFIG.queryClient.prefetchQuery(
|
|
762
|
+
getTokenPriceQueryOptions("HBD")
|
|
751
763
|
);
|
|
752
|
-
const
|
|
753
|
-
|
|
764
|
+
const marketPrice = CONFIG.queryClient.getQueryData(
|
|
765
|
+
getTokenPriceQueryOptions("HBD").queryKey
|
|
766
|
+
) ?? 0;
|
|
754
767
|
if (typeof marketPrice === "number" && Number.isFinite(marketPrice)) {
|
|
755
768
|
price = marketPrice;
|
|
756
769
|
}
|
|
@@ -891,7 +904,7 @@ function getHiveAssetTransactionsQueryOptions(username, limit = 20, group) {
|
|
|
891
904
|
case "transfer_to_savings":
|
|
892
905
|
case "transfer_to_vesting":
|
|
893
906
|
case "recurrent_transfer":
|
|
894
|
-
return
|
|
907
|
+
return parseAsset(item.amount).symbol === "HIVE";
|
|
895
908
|
case "fill_recurrent_transfer":
|
|
896
909
|
const asset = parseAsset(item.amount);
|
|
897
910
|
return ["HIVE"].includes(asset.symbol);
|
|
@@ -941,11 +954,14 @@ function getHivePowerAssetTransactionsQueryOptions(username, limit = 20, group)
|
|
|
941
954
|
item.reward_vests
|
|
942
955
|
);
|
|
943
956
|
return rewardVests.amount > 0;
|
|
957
|
+
case "transfer_to_vesting":
|
|
958
|
+
return true;
|
|
944
959
|
case "transfer":
|
|
945
960
|
case "transfer_to_savings":
|
|
946
|
-
case "transfer_to_vesting":
|
|
947
961
|
case "recurrent_transfer":
|
|
948
|
-
return ["VESTS", "HP"].includes(
|
|
962
|
+
return ["VESTS", "HP"].includes(
|
|
963
|
+
parseAsset(item.amount).symbol
|
|
964
|
+
);
|
|
949
965
|
case "fill_recurrent_transfer":
|
|
950
966
|
const asset = parseAsset(item.amount);
|
|
951
967
|
return ["VESTS", "HP"].includes(asset.symbol);
|
|
@@ -987,7 +1003,7 @@ function getHbdAssetTransactionsQueryOptions(username, limit = 20, group) {
|
|
|
987
1003
|
case "transfer_to_savings":
|
|
988
1004
|
case "transfer_to_vesting":
|
|
989
1005
|
case "recurrent_transfer":
|
|
990
|
-
return
|
|
1006
|
+
return parseAsset(item.amount).symbol === "HBD";
|
|
991
1007
|
case "fill_recurrent_transfer":
|
|
992
1008
|
const asset = parseAsset(item.amount);
|
|
993
1009
|
return ["HBD"].includes(asset.symbol);
|
|
@@ -1752,12 +1768,23 @@ function getHiveEngineTokenGeneralInfoQueryOptions(username, symbol) {
|
|
|
1752
1768
|
const balance = balanceList?.find((i) => i.symbol === symbol);
|
|
1753
1769
|
const market = marketList?.find((i) => i.symbol === symbol);
|
|
1754
1770
|
const lastPrice = +(market?.lastPrice ?? "0");
|
|
1771
|
+
const liquidBalance = parseFloat(balance?.balance ?? "0");
|
|
1772
|
+
const stakedBalance = parseFloat(balance?.stake ?? "0");
|
|
1773
|
+
const unstakingBalance = parseFloat(balance?.pendingUnstake ?? "0");
|
|
1774
|
+
const parts = [
|
|
1775
|
+
{ name: "liquid", balance: liquidBalance },
|
|
1776
|
+
{ name: "staked", balance: stakedBalance }
|
|
1777
|
+
];
|
|
1778
|
+
if (unstakingBalance > 0) {
|
|
1779
|
+
parts.push({ name: "unstaking", balance: unstakingBalance });
|
|
1780
|
+
}
|
|
1755
1781
|
return {
|
|
1756
1782
|
name: symbol,
|
|
1757
1783
|
title: metadata?.name ?? "",
|
|
1758
1784
|
price: lastPrice === 0 ? 0 : Number(lastPrice * (hiveData?.price ?? 0)),
|
|
1759
|
-
accountBalance:
|
|
1760
|
-
layer: "ENGINE"
|
|
1785
|
+
accountBalance: liquidBalance + stakedBalance,
|
|
1786
|
+
layer: "ENGINE",
|
|
1787
|
+
parts
|
|
1761
1788
|
};
|
|
1762
1789
|
}
|
|
1763
1790
|
});
|
|
@@ -2213,6 +2240,9 @@ function getPointsAssetTransactionsQueryOptions(username, type) {
|
|
|
2213
2240
|
`${CONFIG.privateApiHost}/private-api/point-list`,
|
|
2214
2241
|
{
|
|
2215
2242
|
method: "POST",
|
|
2243
|
+
headers: {
|
|
2244
|
+
"Content-Type": "application/json"
|
|
2245
|
+
},
|
|
2216
2246
|
body: JSON.stringify({
|
|
2217
2247
|
username,
|
|
2218
2248
|
type: type ?? 0
|
|
@@ -2486,10 +2516,10 @@ function getAptAssetGeneralInfoQueryOptions(username) {
|
|
|
2486
2516
|
getAptAssetBalanceQueryOptions(address).queryKey
|
|
2487
2517
|
) ?? 0) / 1e8;
|
|
2488
2518
|
await CONFIG.queryClient.prefetchQuery(
|
|
2489
|
-
|
|
2519
|
+
getTokenPriceQueryOptions("APT")
|
|
2490
2520
|
);
|
|
2491
2521
|
const price = CONFIG.queryClient.getQueryData(
|
|
2492
|
-
|
|
2522
|
+
getTokenPriceQueryOptions("APT").queryKey
|
|
2493
2523
|
) ?? 0;
|
|
2494
2524
|
return {
|
|
2495
2525
|
name: "APT",
|
|
@@ -2537,10 +2567,10 @@ function getBnbAssetGeneralInfoQueryOptions(username) {
|
|
|
2537
2567
|
getBnbAssetBalanceQueryOptions(address).queryKey
|
|
2538
2568
|
) ?? 0) / 1e18;
|
|
2539
2569
|
await CONFIG.queryClient.prefetchQuery(
|
|
2540
|
-
|
|
2570
|
+
getTokenPriceQueryOptions("BNB")
|
|
2541
2571
|
);
|
|
2542
2572
|
const price = CONFIG.queryClient.getQueryData(
|
|
2543
|
-
|
|
2573
|
+
getTokenPriceQueryOptions("BNB").queryKey
|
|
2544
2574
|
) ?? 0;
|
|
2545
2575
|
return {
|
|
2546
2576
|
name: "BNB",
|
|
@@ -2588,10 +2618,10 @@ function getBtcAssetGeneralInfoQueryOptions(username) {
|
|
|
2588
2618
|
getBtcAssetBalanceQueryOptions(address).queryKey
|
|
2589
2619
|
) ?? 0) / 1e8;
|
|
2590
2620
|
await CONFIG.queryClient.prefetchQuery(
|
|
2591
|
-
|
|
2621
|
+
getTokenPriceQueryOptions("BTC")
|
|
2592
2622
|
);
|
|
2593
2623
|
const price = CONFIG.queryClient.getQueryData(
|
|
2594
|
-
|
|
2624
|
+
getTokenPriceQueryOptions("BTC").queryKey
|
|
2595
2625
|
) ?? 0;
|
|
2596
2626
|
return {
|
|
2597
2627
|
name: "BTC",
|
|
@@ -2639,10 +2669,10 @@ function getEthAssetGeneralInfoQueryOptions(username) {
|
|
|
2639
2669
|
getEthAssetBalanceQueryOptions(address).queryKey
|
|
2640
2670
|
) ?? 0) / 1e18;
|
|
2641
2671
|
await CONFIG.queryClient.prefetchQuery(
|
|
2642
|
-
|
|
2672
|
+
getTokenPriceQueryOptions("ETH")
|
|
2643
2673
|
);
|
|
2644
2674
|
const price = CONFIG.queryClient.getQueryData(
|
|
2645
|
-
|
|
2675
|
+
getTokenPriceQueryOptions("ETH").queryKey
|
|
2646
2676
|
) ?? 0;
|
|
2647
2677
|
return {
|
|
2648
2678
|
name: "ETH",
|
|
@@ -2690,10 +2720,10 @@ function getSolAssetGeneralInfoQueryOptions(username) {
|
|
|
2690
2720
|
getSolAssetBalanceQueryOptions(address).queryKey
|
|
2691
2721
|
) ?? 0) / 1e9;
|
|
2692
2722
|
await CONFIG.queryClient.prefetchQuery(
|
|
2693
|
-
|
|
2723
|
+
getTokenPriceQueryOptions("SOL")
|
|
2694
2724
|
);
|
|
2695
2725
|
const price = CONFIG.queryClient.getQueryData(
|
|
2696
|
-
|
|
2726
|
+
getTokenPriceQueryOptions("SOL").queryKey
|
|
2697
2727
|
) ?? 0;
|
|
2698
2728
|
return {
|
|
2699
2729
|
name: "SOL",
|
|
@@ -2741,10 +2771,10 @@ function getTonAssetGeneralInfoQueryOptions(username) {
|
|
|
2741
2771
|
getTonAssetBalanceQueryOptions(address).queryKey
|
|
2742
2772
|
) ?? 0) / 1e9;
|
|
2743
2773
|
await CONFIG.queryClient.prefetchQuery(
|
|
2744
|
-
|
|
2774
|
+
getTokenPriceQueryOptions("TON")
|
|
2745
2775
|
);
|
|
2746
2776
|
const price = CONFIG.queryClient.getQueryData(
|
|
2747
|
-
|
|
2777
|
+
getTokenPriceQueryOptions("TON").queryKey
|
|
2748
2778
|
) ?? 0;
|
|
2749
2779
|
return {
|
|
2750
2780
|
name: "TON",
|
|
@@ -2792,10 +2822,10 @@ function getTronAssetGeneralInfoQueryOptions(username) {
|
|
|
2792
2822
|
getTronAssetBalanceQueryOptions(address).queryKey
|
|
2793
2823
|
) ?? 0) / 1e6;
|
|
2794
2824
|
await CONFIG.queryClient.prefetchQuery(
|
|
2795
|
-
|
|
2825
|
+
getTokenPriceQueryOptions("TRX")
|
|
2796
2826
|
);
|
|
2797
2827
|
const price = CONFIG.queryClient.getQueryData(
|
|
2798
|
-
|
|
2828
|
+
getTokenPriceQueryOptions("TRX").queryKey
|
|
2799
2829
|
) ?? 0;
|
|
2800
2830
|
return {
|
|
2801
2831
|
name: "TRX",
|
|
@@ -2916,22 +2946,30 @@ function getTokenOperationsQueryOptions(token, username, isForOwner = false) {
|
|
|
2916
2946
|
case "TRX":
|
|
2917
2947
|
return [];
|
|
2918
2948
|
}
|
|
2949
|
+
if (!username) {
|
|
2950
|
+
return ["transfer" /* Transfer */];
|
|
2951
|
+
}
|
|
2952
|
+
const queryClient = getQueryClient();
|
|
2919
2953
|
const balancesListQuery = getHiveEngineTokensBalancesQueryOptions(username);
|
|
2920
|
-
await
|
|
2921
|
-
const balances = getQueryClient().getQueryData(
|
|
2922
|
-
balancesListQuery.queryKey
|
|
2923
|
-
);
|
|
2954
|
+
const balances = await queryClient.ensureQueryData(balancesListQuery);
|
|
2924
2955
|
const tokensQuery = getHiveEngineTokensMetadataQueryOptions(
|
|
2925
|
-
balances
|
|
2956
|
+
balances.map((b) => b.symbol)
|
|
2926
2957
|
);
|
|
2927
|
-
await
|
|
2928
|
-
const
|
|
2929
|
-
const
|
|
2930
|
-
const tokenInfo = tokens?.find((t) => t.symbol === token);
|
|
2958
|
+
const tokens = await queryClient.ensureQueryData(tokensQuery);
|
|
2959
|
+
const balanceInfo = balances.find((m) => m.symbol === token);
|
|
2960
|
+
const tokenInfo = tokens.find((t) => t.symbol === token);
|
|
2931
2961
|
const canDelegate = isForOwner && tokenInfo?.delegationEnabled && balanceInfo && parseFloat(balanceInfo.delegationsOut) !== parseFloat(balanceInfo.balance);
|
|
2932
2962
|
const canUndelegate = isForOwner && parseFloat(balanceInfo?.delegationsOut ?? "0") > 0;
|
|
2933
|
-
const
|
|
2934
|
-
const
|
|
2963
|
+
const stakeBalance = parseFloat(balanceInfo?.stake ?? "0");
|
|
2964
|
+
const pendingUnstakeBalance = parseFloat(
|
|
2965
|
+
balanceInfo?.pendingUnstake ?? "0"
|
|
2966
|
+
);
|
|
2967
|
+
const supportsStakingFeature = Boolean(
|
|
2968
|
+
tokenInfo?.stakingEnabled || (tokenInfo?.unstakingCooldown ?? 0) > 0 || parseFloat(tokenInfo?.totalStaked ?? "0") > 0
|
|
2969
|
+
);
|
|
2970
|
+
const hasStakingBalances = stakeBalance > 0 || pendingUnstakeBalance > 0;
|
|
2971
|
+
const canStake = isForOwner && Boolean(tokenInfo?.stakingEnabled);
|
|
2972
|
+
const canUnstake = isForOwner && (supportsStakingFeature || hasStakingBalances);
|
|
2935
2973
|
return [
|
|
2936
2974
|
"transfer" /* Transfer */,
|
|
2937
2975
|
...canDelegate ? ["delegate" /* Delegate */] : [],
|
|
@@ -3342,6 +3380,6 @@ function useWalletOperation(username, asset, operation) {
|
|
|
3342
3380
|
// src/index.ts
|
|
3343
3381
|
rememberScryptBsvVersion();
|
|
3344
3382
|
|
|
3345
|
-
export { AssetOperation, EcencyWalletBasicTokens, EcencyWalletCurrency, private_api_exports as EcencyWalletsPrivateApi, NaiMap, PointTransactionType, Symbol2 as Symbol, buildAptTx, buildEthTx, buildExternalTx, buildPsbt, buildSolTx, buildTonTx, buildTronTx, decryptMemoWithAccounts, decryptMemoWithKeys, delay, delegateEngineToken, delegateHive, deriveHiveKey, deriveHiveKeys, deriveHiveMasterPasswordKey, deriveHiveMasterPasswordKeys, detectHiveKeyDerivation, encryptMemoWithAccounts, encryptMemoWithKeys, getAccountWalletAssetInfoQueryOptions, getAccountWalletListQueryOptions, getAllTokensListQueryOptions, getBoundFetch,
|
|
3383
|
+
export { AssetOperation, EcencyWalletBasicTokens, EcencyWalletCurrency, private_api_exports as EcencyWalletsPrivateApi, NaiMap, PointTransactionType, Symbol2 as Symbol, buildAptTx, buildEthTx, buildExternalTx, buildPsbt, buildSolTx, buildTonTx, buildTronTx, decryptMemoWithAccounts, decryptMemoWithKeys, delay, delegateEngineToken, delegateHive, deriveHiveKey, deriveHiveKeys, deriveHiveMasterPasswordKey, deriveHiveMasterPasswordKeys, detectHiveKeyDerivation, encryptMemoWithAccounts, encryptMemoWithKeys, getAccountWalletAssetInfoQueryOptions, getAccountWalletListQueryOptions, getAllTokensListQueryOptions, getBoundFetch, getHbdAssetGeneralInfoQueryOptions, getHbdAssetTransactionsQueryOptions, getHiveAssetGeneralInfoQueryOptions, getHiveAssetMetricQueryOptions, getHiveAssetTransactionsQueryOptions, getHiveAssetWithdrawalRoutesQueryOptions, getHiveEngineTokenGeneralInfoQueryOptions, getHiveEngineTokenTransactionsQueryOptions, getHiveEngineTokensBalancesQueryOptions, getHiveEngineTokensMarketQueryOptions, getHiveEngineTokensMetadataQueryOptions, getHiveEngineTokensMetricsQueryOptions, getHivePowerAssetGeneralInfoQueryOptions, getHivePowerAssetTransactionsQueryOptions, getHivePowerDelegatesInfiniteQueryOptions, getHivePowerDelegatingsQueryOptions, getLarynxAssetGeneralInfoQueryOptions, getLarynxPowerAssetGeneralInfoQueryOptions, getPointsAssetGeneralInfoQueryOptions, getPointsAssetTransactionsQueryOptions, getPointsQueryOptions, getSpkAssetGeneralInfoQueryOptions, getSpkMarketsQueryOptions, getTokenOperationsQueryOptions, getTokenPriceQueryOptions, getWallet, isEmptyDate, lockLarynx, mnemonicToSeedBip39, parseAsset, powerDownHive, powerUpHive, powerUpLarynx, rewardSpk, signDigest, signExternalTx, signExternalTxAndBroadcast, signTx, signTxAndBroadcast, stakeEngineToken, transferEngineToken, transferHive, transferPoint, transferSpk, transferToSavingsHive, undelegateEngineToken, unstakeEngineToken, useClaimPoints, useClaimRewards, useGetExternalWalletBalanceQuery, useHiveKeysQuery, useImportWallet, useSaveWalletInformationToMetadata, useSeedPhrase, useWalletCreate, useWalletOperation, useWalletsCacheQuery, vestsToHp, withdrawVestingRouteHive };
|
|
3346
3384
|
//# sourceMappingURL=index.mjs.map
|
|
3347
3385
|
//# sourceMappingURL=index.mjs.map
|