@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.cjs
CHANGED
|
@@ -229,55 +229,67 @@ var cacheGet = (key) => {
|
|
|
229
229
|
const v = cache.get(key);
|
|
230
230
|
return v === undefinedValue ? void 0 : v;
|
|
231
231
|
};
|
|
232
|
-
|
|
232
|
+
var CURRENCY_TO_TOKEN_MAP = {
|
|
233
|
+
["BTC" /* BTC */]: "btc",
|
|
234
|
+
["ETH" /* ETH */]: "eth",
|
|
235
|
+
["SOL" /* SOL */]: "sol",
|
|
236
|
+
["TON" /* TON */]: "ton",
|
|
237
|
+
["TRX" /* TRON */]: "trx",
|
|
238
|
+
["APT" /* APT */]: "apt",
|
|
239
|
+
["BNB" /* BNB */]: "bnb",
|
|
240
|
+
HBD: "hbd",
|
|
241
|
+
HIVE: "hive"
|
|
242
|
+
};
|
|
243
|
+
var MARKET_DATA_CACHE_KEY = "market-data/latest";
|
|
244
|
+
var normalizeCurrencyToToken = (currency) => {
|
|
245
|
+
const upperCased = currency.toUpperCase();
|
|
246
|
+
return CURRENCY_TO_TOKEN_MAP[upperCased] ?? currency.toLowerCase();
|
|
247
|
+
};
|
|
248
|
+
function getTokenPriceQueryOptions(currency) {
|
|
233
249
|
return reactQuery.queryOptions({
|
|
234
|
-
queryKey: ["ecency-wallets", "
|
|
250
|
+
queryKey: ["ecency-wallets", "market-data", currency],
|
|
235
251
|
queryFn: async () => {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
break;
|
|
241
|
-
case "ETH" /* ETH */:
|
|
242
|
-
curr = "ethereum";
|
|
243
|
-
break;
|
|
244
|
-
case "SOL" /* SOL */:
|
|
245
|
-
curr = "solana";
|
|
246
|
-
break;
|
|
247
|
-
case "TON" /* TON */:
|
|
248
|
-
curr = "ton";
|
|
249
|
-
break;
|
|
250
|
-
case "TRX" /* TRON */:
|
|
251
|
-
curr = "tron";
|
|
252
|
-
break;
|
|
253
|
-
case "APT" /* APT */:
|
|
254
|
-
curr = "aptos";
|
|
255
|
-
break;
|
|
256
|
-
case "BNB" /* BNB */:
|
|
257
|
-
curr = "binancecoin";
|
|
258
|
-
break;
|
|
259
|
-
case "TON" /* TON */:
|
|
260
|
-
curr = "the-open-network";
|
|
261
|
-
break;
|
|
262
|
-
default:
|
|
263
|
-
curr = currency;
|
|
252
|
+
if (!currency) {
|
|
253
|
+
throw new Error(
|
|
254
|
+
"[SDK][Wallets][MarketData] \u2013 currency wasn`t provided"
|
|
255
|
+
);
|
|
264
256
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
257
|
+
if (!sdk.CONFIG.privateApiHost) {
|
|
258
|
+
throw new Error(
|
|
259
|
+
"[SDK][Wallets][MarketData] \u2013 privateApiHost isn`t configured"
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
const token = normalizeCurrencyToToken(currency);
|
|
263
|
+
let marketData = cacheGet(MARKET_DATA_CACHE_KEY);
|
|
264
|
+
if (!marketData) {
|
|
270
265
|
const httpResponse = await fetch(
|
|
271
|
-
|
|
266
|
+
`${sdk.CONFIG.privateApiHost}/private-api/market-data/latest`,
|
|
272
267
|
{
|
|
273
268
|
method: "GET"
|
|
274
269
|
}
|
|
275
270
|
);
|
|
271
|
+
if (!httpResponse.ok) {
|
|
272
|
+
throw new Error(
|
|
273
|
+
`[SDK][Wallets][MarketData] \u2013 failed to fetch latest market data (${httpResponse.status})`
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
276
|
const data = await httpResponse.json();
|
|
277
|
-
cacheSet(
|
|
278
|
-
|
|
277
|
+
cacheSet(MARKET_DATA_CACHE_KEY, data);
|
|
278
|
+
marketData = data;
|
|
279
|
+
}
|
|
280
|
+
const tokenData = marketData[token];
|
|
281
|
+
if (!tokenData) {
|
|
282
|
+
throw new Error(
|
|
283
|
+
`[SDK][Wallets][MarketData] \u2013 missing market data for token: ${token}`
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
const usdQuote = tokenData.quotes?.usd;
|
|
287
|
+
if (!usdQuote) {
|
|
288
|
+
throw new Error(
|
|
289
|
+
`[SDK][Wallets][MarketData] \u2013 missing USD quote for token: ${token}`
|
|
290
|
+
);
|
|
279
291
|
}
|
|
280
|
-
return
|
|
292
|
+
return Number(usdQuote.price);
|
|
281
293
|
},
|
|
282
294
|
enabled: !!currency
|
|
283
295
|
});
|
|
@@ -773,11 +785,12 @@ function getHbdAssetGeneralInfoQueryOptions(username) {
|
|
|
773
785
|
);
|
|
774
786
|
let price = 1;
|
|
775
787
|
try {
|
|
776
|
-
|
|
777
|
-
"
|
|
788
|
+
await sdk.CONFIG.queryClient.prefetchQuery(
|
|
789
|
+
getTokenPriceQueryOptions("HBD")
|
|
778
790
|
);
|
|
779
|
-
const
|
|
780
|
-
|
|
791
|
+
const marketPrice = sdk.CONFIG.queryClient.getQueryData(
|
|
792
|
+
getTokenPriceQueryOptions("HBD").queryKey
|
|
793
|
+
) ?? 0;
|
|
781
794
|
if (typeof marketPrice === "number" && Number.isFinite(marketPrice)) {
|
|
782
795
|
price = marketPrice;
|
|
783
796
|
}
|
|
@@ -918,7 +931,7 @@ function getHiveAssetTransactionsQueryOptions(username, limit = 20, group) {
|
|
|
918
931
|
case "transfer_to_savings":
|
|
919
932
|
case "transfer_to_vesting":
|
|
920
933
|
case "recurrent_transfer":
|
|
921
|
-
return
|
|
934
|
+
return parseAsset(item.amount).symbol === "HIVE";
|
|
922
935
|
case "fill_recurrent_transfer":
|
|
923
936
|
const asset = parseAsset(item.amount);
|
|
924
937
|
return ["HIVE"].includes(asset.symbol);
|
|
@@ -968,11 +981,14 @@ function getHivePowerAssetTransactionsQueryOptions(username, limit = 20, group)
|
|
|
968
981
|
item.reward_vests
|
|
969
982
|
);
|
|
970
983
|
return rewardVests.amount > 0;
|
|
984
|
+
case "transfer_to_vesting":
|
|
985
|
+
return true;
|
|
971
986
|
case "transfer":
|
|
972
987
|
case "transfer_to_savings":
|
|
973
|
-
case "transfer_to_vesting":
|
|
974
988
|
case "recurrent_transfer":
|
|
975
|
-
return ["VESTS", "HP"].includes(
|
|
989
|
+
return ["VESTS", "HP"].includes(
|
|
990
|
+
parseAsset(item.amount).symbol
|
|
991
|
+
);
|
|
976
992
|
case "fill_recurrent_transfer":
|
|
977
993
|
const asset = parseAsset(item.amount);
|
|
978
994
|
return ["VESTS", "HP"].includes(asset.symbol);
|
|
@@ -1014,7 +1030,7 @@ function getHbdAssetTransactionsQueryOptions(username, limit = 20, group) {
|
|
|
1014
1030
|
case "transfer_to_savings":
|
|
1015
1031
|
case "transfer_to_vesting":
|
|
1016
1032
|
case "recurrent_transfer":
|
|
1017
|
-
return
|
|
1033
|
+
return parseAsset(item.amount).symbol === "HBD";
|
|
1018
1034
|
case "fill_recurrent_transfer":
|
|
1019
1035
|
const asset = parseAsset(item.amount);
|
|
1020
1036
|
return ["HBD"].includes(asset.symbol);
|
|
@@ -1779,12 +1795,23 @@ function getHiveEngineTokenGeneralInfoQueryOptions(username, symbol) {
|
|
|
1779
1795
|
const balance = balanceList?.find((i) => i.symbol === symbol);
|
|
1780
1796
|
const market = marketList?.find((i) => i.symbol === symbol);
|
|
1781
1797
|
const lastPrice = +(market?.lastPrice ?? "0");
|
|
1798
|
+
const liquidBalance = parseFloat(balance?.balance ?? "0");
|
|
1799
|
+
const stakedBalance = parseFloat(balance?.stake ?? "0");
|
|
1800
|
+
const unstakingBalance = parseFloat(balance?.pendingUnstake ?? "0");
|
|
1801
|
+
const parts = [
|
|
1802
|
+
{ name: "liquid", balance: liquidBalance },
|
|
1803
|
+
{ name: "staked", balance: stakedBalance }
|
|
1804
|
+
];
|
|
1805
|
+
if (unstakingBalance > 0) {
|
|
1806
|
+
parts.push({ name: "unstaking", balance: unstakingBalance });
|
|
1807
|
+
}
|
|
1782
1808
|
return {
|
|
1783
1809
|
name: symbol,
|
|
1784
1810
|
title: metadata?.name ?? "",
|
|
1785
1811
|
price: lastPrice === 0 ? 0 : Number(lastPrice * (hiveData?.price ?? 0)),
|
|
1786
|
-
accountBalance:
|
|
1787
|
-
layer: "ENGINE"
|
|
1812
|
+
accountBalance: liquidBalance + stakedBalance,
|
|
1813
|
+
layer: "ENGINE",
|
|
1814
|
+
parts
|
|
1788
1815
|
};
|
|
1789
1816
|
}
|
|
1790
1817
|
});
|
|
@@ -2240,6 +2267,9 @@ function getPointsAssetTransactionsQueryOptions(username, type) {
|
|
|
2240
2267
|
`${sdk.CONFIG.privateApiHost}/private-api/point-list`,
|
|
2241
2268
|
{
|
|
2242
2269
|
method: "POST",
|
|
2270
|
+
headers: {
|
|
2271
|
+
"Content-Type": "application/json"
|
|
2272
|
+
},
|
|
2243
2273
|
body: JSON.stringify({
|
|
2244
2274
|
username,
|
|
2245
2275
|
type: type ?? 0
|
|
@@ -2513,10 +2543,10 @@ function getAptAssetGeneralInfoQueryOptions(username) {
|
|
|
2513
2543
|
getAptAssetBalanceQueryOptions(address).queryKey
|
|
2514
2544
|
) ?? 0) / 1e8;
|
|
2515
2545
|
await sdk.CONFIG.queryClient.prefetchQuery(
|
|
2516
|
-
|
|
2546
|
+
getTokenPriceQueryOptions("APT")
|
|
2517
2547
|
);
|
|
2518
2548
|
const price = sdk.CONFIG.queryClient.getQueryData(
|
|
2519
|
-
|
|
2549
|
+
getTokenPriceQueryOptions("APT").queryKey
|
|
2520
2550
|
) ?? 0;
|
|
2521
2551
|
return {
|
|
2522
2552
|
name: "APT",
|
|
@@ -2564,10 +2594,10 @@ function getBnbAssetGeneralInfoQueryOptions(username) {
|
|
|
2564
2594
|
getBnbAssetBalanceQueryOptions(address).queryKey
|
|
2565
2595
|
) ?? 0) / 1e18;
|
|
2566
2596
|
await sdk.CONFIG.queryClient.prefetchQuery(
|
|
2567
|
-
|
|
2597
|
+
getTokenPriceQueryOptions("BNB")
|
|
2568
2598
|
);
|
|
2569
2599
|
const price = sdk.CONFIG.queryClient.getQueryData(
|
|
2570
|
-
|
|
2600
|
+
getTokenPriceQueryOptions("BNB").queryKey
|
|
2571
2601
|
) ?? 0;
|
|
2572
2602
|
return {
|
|
2573
2603
|
name: "BNB",
|
|
@@ -2615,10 +2645,10 @@ function getBtcAssetGeneralInfoQueryOptions(username) {
|
|
|
2615
2645
|
getBtcAssetBalanceQueryOptions(address).queryKey
|
|
2616
2646
|
) ?? 0) / 1e8;
|
|
2617
2647
|
await sdk.CONFIG.queryClient.prefetchQuery(
|
|
2618
|
-
|
|
2648
|
+
getTokenPriceQueryOptions("BTC")
|
|
2619
2649
|
);
|
|
2620
2650
|
const price = sdk.CONFIG.queryClient.getQueryData(
|
|
2621
|
-
|
|
2651
|
+
getTokenPriceQueryOptions("BTC").queryKey
|
|
2622
2652
|
) ?? 0;
|
|
2623
2653
|
return {
|
|
2624
2654
|
name: "BTC",
|
|
@@ -2666,10 +2696,10 @@ function getEthAssetGeneralInfoQueryOptions(username) {
|
|
|
2666
2696
|
getEthAssetBalanceQueryOptions(address).queryKey
|
|
2667
2697
|
) ?? 0) / 1e18;
|
|
2668
2698
|
await sdk.CONFIG.queryClient.prefetchQuery(
|
|
2669
|
-
|
|
2699
|
+
getTokenPriceQueryOptions("ETH")
|
|
2670
2700
|
);
|
|
2671
2701
|
const price = sdk.CONFIG.queryClient.getQueryData(
|
|
2672
|
-
|
|
2702
|
+
getTokenPriceQueryOptions("ETH").queryKey
|
|
2673
2703
|
) ?? 0;
|
|
2674
2704
|
return {
|
|
2675
2705
|
name: "ETH",
|
|
@@ -2717,10 +2747,10 @@ function getSolAssetGeneralInfoQueryOptions(username) {
|
|
|
2717
2747
|
getSolAssetBalanceQueryOptions(address).queryKey
|
|
2718
2748
|
) ?? 0) / 1e9;
|
|
2719
2749
|
await sdk.CONFIG.queryClient.prefetchQuery(
|
|
2720
|
-
|
|
2750
|
+
getTokenPriceQueryOptions("SOL")
|
|
2721
2751
|
);
|
|
2722
2752
|
const price = sdk.CONFIG.queryClient.getQueryData(
|
|
2723
|
-
|
|
2753
|
+
getTokenPriceQueryOptions("SOL").queryKey
|
|
2724
2754
|
) ?? 0;
|
|
2725
2755
|
return {
|
|
2726
2756
|
name: "SOL",
|
|
@@ -2768,10 +2798,10 @@ function getTonAssetGeneralInfoQueryOptions(username) {
|
|
|
2768
2798
|
getTonAssetBalanceQueryOptions(address).queryKey
|
|
2769
2799
|
) ?? 0) / 1e9;
|
|
2770
2800
|
await sdk.CONFIG.queryClient.prefetchQuery(
|
|
2771
|
-
|
|
2801
|
+
getTokenPriceQueryOptions("TON")
|
|
2772
2802
|
);
|
|
2773
2803
|
const price = sdk.CONFIG.queryClient.getQueryData(
|
|
2774
|
-
|
|
2804
|
+
getTokenPriceQueryOptions("TON").queryKey
|
|
2775
2805
|
) ?? 0;
|
|
2776
2806
|
return {
|
|
2777
2807
|
name: "TON",
|
|
@@ -2819,10 +2849,10 @@ function getTronAssetGeneralInfoQueryOptions(username) {
|
|
|
2819
2849
|
getTronAssetBalanceQueryOptions(address).queryKey
|
|
2820
2850
|
) ?? 0) / 1e6;
|
|
2821
2851
|
await sdk.CONFIG.queryClient.prefetchQuery(
|
|
2822
|
-
|
|
2852
|
+
getTokenPriceQueryOptions("TRX")
|
|
2823
2853
|
);
|
|
2824
2854
|
const price = sdk.CONFIG.queryClient.getQueryData(
|
|
2825
|
-
|
|
2855
|
+
getTokenPriceQueryOptions("TRX").queryKey
|
|
2826
2856
|
) ?? 0;
|
|
2827
2857
|
return {
|
|
2828
2858
|
name: "TRX",
|
|
@@ -2943,22 +2973,30 @@ function getTokenOperationsQueryOptions(token, username, isForOwner = false) {
|
|
|
2943
2973
|
case "TRX":
|
|
2944
2974
|
return [];
|
|
2945
2975
|
}
|
|
2976
|
+
if (!username) {
|
|
2977
|
+
return ["transfer" /* Transfer */];
|
|
2978
|
+
}
|
|
2979
|
+
const queryClient = sdk.getQueryClient();
|
|
2946
2980
|
const balancesListQuery = getHiveEngineTokensBalancesQueryOptions(username);
|
|
2947
|
-
await
|
|
2948
|
-
const balances = sdk.getQueryClient().getQueryData(
|
|
2949
|
-
balancesListQuery.queryKey
|
|
2950
|
-
);
|
|
2981
|
+
const balances = await queryClient.ensureQueryData(balancesListQuery);
|
|
2951
2982
|
const tokensQuery = getHiveEngineTokensMetadataQueryOptions(
|
|
2952
|
-
balances
|
|
2983
|
+
balances.map((b) => b.symbol)
|
|
2953
2984
|
);
|
|
2954
|
-
await
|
|
2955
|
-
const
|
|
2956
|
-
const
|
|
2957
|
-
const tokenInfo = tokens?.find((t) => t.symbol === token);
|
|
2985
|
+
const tokens = await queryClient.ensureQueryData(tokensQuery);
|
|
2986
|
+
const balanceInfo = balances.find((m) => m.symbol === token);
|
|
2987
|
+
const tokenInfo = tokens.find((t) => t.symbol === token);
|
|
2958
2988
|
const canDelegate = isForOwner && tokenInfo?.delegationEnabled && balanceInfo && parseFloat(balanceInfo.delegationsOut) !== parseFloat(balanceInfo.balance);
|
|
2959
2989
|
const canUndelegate = isForOwner && parseFloat(balanceInfo?.delegationsOut ?? "0") > 0;
|
|
2960
|
-
const
|
|
2961
|
-
const
|
|
2990
|
+
const stakeBalance = parseFloat(balanceInfo?.stake ?? "0");
|
|
2991
|
+
const pendingUnstakeBalance = parseFloat(
|
|
2992
|
+
balanceInfo?.pendingUnstake ?? "0"
|
|
2993
|
+
);
|
|
2994
|
+
const supportsStakingFeature = Boolean(
|
|
2995
|
+
tokenInfo?.stakingEnabled || (tokenInfo?.unstakingCooldown ?? 0) > 0 || parseFloat(tokenInfo?.totalStaked ?? "0") > 0
|
|
2996
|
+
);
|
|
2997
|
+
const hasStakingBalances = stakeBalance > 0 || pendingUnstakeBalance > 0;
|
|
2998
|
+
const canStake = isForOwner && Boolean(tokenInfo?.stakingEnabled);
|
|
2999
|
+
const canUnstake = isForOwner && (supportsStakingFeature || hasStakingBalances);
|
|
2962
3000
|
return [
|
|
2963
3001
|
"transfer" /* Transfer */,
|
|
2964
3002
|
...canDelegate ? ["delegate" /* Delegate */] : [],
|
|
@@ -3399,7 +3437,6 @@ exports.getAccountWalletAssetInfoQueryOptions = getAccountWalletAssetInfoQueryOp
|
|
|
3399
3437
|
exports.getAccountWalletListQueryOptions = getAccountWalletListQueryOptions;
|
|
3400
3438
|
exports.getAllTokensListQueryOptions = getAllTokensListQueryOptions;
|
|
3401
3439
|
exports.getBoundFetch = getBoundFetch;
|
|
3402
|
-
exports.getCoinGeckoPriceQueryOptions = getCoinGeckoPriceQueryOptions;
|
|
3403
3440
|
exports.getHbdAssetGeneralInfoQueryOptions = getHbdAssetGeneralInfoQueryOptions;
|
|
3404
3441
|
exports.getHbdAssetTransactionsQueryOptions = getHbdAssetTransactionsQueryOptions;
|
|
3405
3442
|
exports.getHiveAssetGeneralInfoQueryOptions = getHiveAssetGeneralInfoQueryOptions;
|
|
@@ -3424,6 +3461,7 @@ exports.getPointsQueryOptions = getPointsQueryOptions;
|
|
|
3424
3461
|
exports.getSpkAssetGeneralInfoQueryOptions = getSpkAssetGeneralInfoQueryOptions;
|
|
3425
3462
|
exports.getSpkMarketsQueryOptions = getSpkMarketsQueryOptions;
|
|
3426
3463
|
exports.getTokenOperationsQueryOptions = getTokenOperationsQueryOptions;
|
|
3464
|
+
exports.getTokenPriceQueryOptions = getTokenPriceQueryOptions;
|
|
3427
3465
|
exports.getWallet = getWallet;
|
|
3428
3466
|
exports.isEmptyDate = isEmptyDate;
|
|
3429
3467
|
exports.lockLarynx = lockLarynx;
|