@ecency/wallets 1.5.19 → 1.5.21
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 +10 -40
- package/dist/browser/index.js +19 -160
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +18 -159
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +19 -160
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/node/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CONFIG, getAccountFullQueryOptions, getQueryClient, getDynamicPropsQueryOptions, useBroadcastMutation, getSpkMarkets, getSpkWallet, getHiveEngineTokensMarket, getHiveEngineTokensBalances, getHiveEngineTokensMetadata, getHiveEngineTokenTransactions, getHiveEngineTokenMetrics, getHiveEngineUnclaimedRewards, EcencyAnalytics, useAccountUpdate, getCurrencyRate } from '@ecency/sdk';
|
|
1
|
+
import { CONFIG, getAccountFullQueryOptions, getQueryClient, getDynamicPropsQueryOptions, useBroadcastMutation, getSpkMarkets, getSpkWallet, getHiveEngineTokensMarket, getHiveEngineTokensBalances, getHiveEngineTokensMetadata, getHiveEngineTokenTransactions, getHiveEngineTokenMetrics, getHiveEngineUnclaimedRewards, EcencyAnalytics, getPortfolioQueryOptions, useAccountUpdate, getCurrencyRate } from '@ecency/sdk';
|
|
2
2
|
export { getHiveEngineMetrics, getHiveEngineOpenOrders, getHiveEngineOrderBook, getHiveEngineTradeHistory } from '@ecency/sdk';
|
|
3
3
|
import { useQuery, queryOptions, infiniteQueryOptions, useQueryClient, useMutation } from '@tanstack/react-query';
|
|
4
4
|
import bip39, { mnemonicToSeedSync } from 'bip39';
|
|
@@ -36,10 +36,23 @@ if (typeof globalLike._scrypt_bsv !== "undefined") {
|
|
|
36
36
|
globalLike._scrypt_bsv = void 0;
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
+
if (typeof globalLike._bitcore !== "undefined") {
|
|
40
|
+
if (typeof globalLike._bitcore === "object") {
|
|
41
|
+
globalLike.__bitcorePreviousVersion = globalLike._bitcore;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
delete globalLike._bitcore;
|
|
45
|
+
} catch {
|
|
46
|
+
globalLike._bitcore = void 0;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
39
49
|
function rememberScryptBsvVersion() {
|
|
40
50
|
if (typeof globalLike._scrypt_bsv === "string") {
|
|
41
51
|
globalLike.__scryptBsvPreviousVersion = globalLike._scrypt_bsv;
|
|
42
52
|
}
|
|
53
|
+
if (typeof globalLike._bitcore === "object") {
|
|
54
|
+
globalLike.__bitcorePreviousVersion = globalLike._bitcore;
|
|
55
|
+
}
|
|
43
56
|
}
|
|
44
57
|
|
|
45
58
|
// src/modules/wallets/enums/ecency-wallet-currency.ts
|
|
@@ -2960,162 +2973,8 @@ function getAllTokensListQueryOptions(username) {
|
|
|
2960
2973
|
}
|
|
2961
2974
|
});
|
|
2962
2975
|
}
|
|
2963
|
-
function normalizeString(value) {
|
|
2964
|
-
if (typeof value === "string") {
|
|
2965
|
-
const trimmed = value.trim();
|
|
2966
|
-
return trimmed.length > 0 ? trimmed : void 0;
|
|
2967
|
-
}
|
|
2968
|
-
return void 0;
|
|
2969
|
-
}
|
|
2970
|
-
function normalizeNumber(value) {
|
|
2971
|
-
if (typeof value === "number" && Number.isFinite(value)) {
|
|
2972
|
-
return value;
|
|
2973
|
-
}
|
|
2974
|
-
if (typeof value === "string") {
|
|
2975
|
-
const trimmed = value.trim();
|
|
2976
|
-
if (!trimmed) {
|
|
2977
|
-
return void 0;
|
|
2978
|
-
}
|
|
2979
|
-
const direct = Number.parseFloat(trimmed);
|
|
2980
|
-
if (Number.isFinite(direct)) {
|
|
2981
|
-
return direct;
|
|
2982
|
-
}
|
|
2983
|
-
const sanitized = trimmed.replace(/,/g, "");
|
|
2984
|
-
const match = sanitized.match(/[-+]?\d+(?:\.\d+)?/);
|
|
2985
|
-
if (match) {
|
|
2986
|
-
const parsed = Number.parseFloat(match[0]);
|
|
2987
|
-
if (Number.isFinite(parsed)) {
|
|
2988
|
-
return parsed;
|
|
2989
|
-
}
|
|
2990
|
-
}
|
|
2991
|
-
}
|
|
2992
|
-
return void 0;
|
|
2993
|
-
}
|
|
2994
|
-
function parseToken(rawToken) {
|
|
2995
|
-
if (!rawToken || typeof rawToken !== "object") {
|
|
2996
|
-
return void 0;
|
|
2997
|
-
}
|
|
2998
|
-
const token = rawToken;
|
|
2999
|
-
return {
|
|
3000
|
-
name: normalizeString(token.name) ?? "",
|
|
3001
|
-
symbol: normalizeString(token.symbol) ?? "",
|
|
3002
|
-
layer: normalizeString(token.layer) ?? "hive",
|
|
3003
|
-
balance: normalizeNumber(token.balance) ?? 0,
|
|
3004
|
-
fiatRate: normalizeNumber(token.fiatRate) ?? 0,
|
|
3005
|
-
currency: normalizeString(token.currency) ?? "usd",
|
|
3006
|
-
precision: normalizeNumber(token.precision) ?? 3,
|
|
3007
|
-
address: normalizeString(token.address),
|
|
3008
|
-
error: normalizeString(token.error),
|
|
3009
|
-
pendingRewards: normalizeNumber(token.pendingRewards),
|
|
3010
|
-
pendingRewardsFiat: normalizeNumber(token.pendingRewardsFiat),
|
|
3011
|
-
liquid: normalizeNumber(token.liquid),
|
|
3012
|
-
liquidFiat: normalizeNumber(token.liquidFiat),
|
|
3013
|
-
savings: normalizeNumber(token.savings),
|
|
3014
|
-
savingsFiat: normalizeNumber(token.savingsFiat),
|
|
3015
|
-
staked: normalizeNumber(token.staked),
|
|
3016
|
-
stakedFiat: normalizeNumber(token.stakedFiat),
|
|
3017
|
-
iconUrl: normalizeString(token.iconUrl),
|
|
3018
|
-
actions: token.actions ?? [],
|
|
3019
|
-
extraData: token.extraData ?? [],
|
|
3020
|
-
apr: normalizeNumber(token.apr)
|
|
3021
|
-
};
|
|
3022
|
-
}
|
|
3023
|
-
function extractTokens(payload) {
|
|
3024
|
-
if (!payload || typeof payload !== "object") {
|
|
3025
|
-
return [];
|
|
3026
|
-
}
|
|
3027
|
-
const containers = [payload];
|
|
3028
|
-
const record = payload;
|
|
3029
|
-
if (record.data && typeof record.data === "object") {
|
|
3030
|
-
containers.push(record.data);
|
|
3031
|
-
}
|
|
3032
|
-
if (record.result && typeof record.result === "object") {
|
|
3033
|
-
containers.push(record.result);
|
|
3034
|
-
}
|
|
3035
|
-
if (record.portfolio && typeof record.portfolio === "object") {
|
|
3036
|
-
containers.push(record.portfolio);
|
|
3037
|
-
}
|
|
3038
|
-
for (const container of containers) {
|
|
3039
|
-
if (Array.isArray(container)) {
|
|
3040
|
-
return container;
|
|
3041
|
-
}
|
|
3042
|
-
if (container && typeof container === "object") {
|
|
3043
|
-
for (const key of [
|
|
3044
|
-
"wallets",
|
|
3045
|
-
"tokens",
|
|
3046
|
-
"assets",
|
|
3047
|
-
"items",
|
|
3048
|
-
"portfolio",
|
|
3049
|
-
"balances"
|
|
3050
|
-
]) {
|
|
3051
|
-
const value = container[key];
|
|
3052
|
-
if (Array.isArray(value)) {
|
|
3053
|
-
return value;
|
|
3054
|
-
}
|
|
3055
|
-
}
|
|
3056
|
-
}
|
|
3057
|
-
}
|
|
3058
|
-
return [];
|
|
3059
|
-
}
|
|
3060
|
-
function resolveUsername(payload) {
|
|
3061
|
-
if (!payload || typeof payload !== "object") {
|
|
3062
|
-
return void 0;
|
|
3063
|
-
}
|
|
3064
|
-
const record = payload;
|
|
3065
|
-
return normalizeString(record.username) ?? normalizeString(record.name) ?? normalizeString(record.account);
|
|
3066
|
-
}
|
|
3067
2976
|
function getVisionPortfolioQueryOptions(username, currency = "usd") {
|
|
3068
|
-
return
|
|
3069
|
-
queryKey: [
|
|
3070
|
-
"ecency-wallets",
|
|
3071
|
-
"portfolio",
|
|
3072
|
-
"v2",
|
|
3073
|
-
username,
|
|
3074
|
-
"only-enabled",
|
|
3075
|
-
currency
|
|
3076
|
-
],
|
|
3077
|
-
enabled: Boolean(username),
|
|
3078
|
-
staleTime: 6e4,
|
|
3079
|
-
refetchInterval: 12e4,
|
|
3080
|
-
queryFn: async () => {
|
|
3081
|
-
if (!username) {
|
|
3082
|
-
throw new Error("[SDK][Wallets] \u2013 username is required");
|
|
3083
|
-
}
|
|
3084
|
-
if (CONFIG.privateApiHost === void 0 || CONFIG.privateApiHost === null) {
|
|
3085
|
-
throw new Error(
|
|
3086
|
-
"[SDK][Wallets] \u2013 privateApiHost isn't configured for portfolio"
|
|
3087
|
-
);
|
|
3088
|
-
}
|
|
3089
|
-
const endpoint = `${CONFIG.privateApiHost}/wallet-api/portfolio-v2`;
|
|
3090
|
-
const response = await fetch(endpoint, {
|
|
3091
|
-
method: "POST",
|
|
3092
|
-
headers: {
|
|
3093
|
-
Accept: "application/json",
|
|
3094
|
-
"Content-Type": "application/json"
|
|
3095
|
-
},
|
|
3096
|
-
body: JSON.stringify({ username, onlyEnabled: true, currency })
|
|
3097
|
-
});
|
|
3098
|
-
if (!response.ok) {
|
|
3099
|
-
throw new Error(
|
|
3100
|
-
`[SDK][Wallets] \u2013 Vision portfolio request failed(${response.status})`
|
|
3101
|
-
);
|
|
3102
|
-
}
|
|
3103
|
-
const payload = await response.json();
|
|
3104
|
-
const tokens = extractTokens(payload).map((item) => parseToken(item)).filter((item) => Boolean(item));
|
|
3105
|
-
if (!tokens.length) {
|
|
3106
|
-
throw new Error(
|
|
3107
|
-
"[SDK][Wallets] \u2013 Vision portfolio payload contained no tokens"
|
|
3108
|
-
);
|
|
3109
|
-
}
|
|
3110
|
-
return {
|
|
3111
|
-
username: resolveUsername(payload) ?? username,
|
|
3112
|
-
currency: normalizeString(
|
|
3113
|
-
payload?.fiatCurrency ?? payload?.currency
|
|
3114
|
-
)?.toUpperCase(),
|
|
3115
|
-
wallets: tokens
|
|
3116
|
-
};
|
|
3117
|
-
}
|
|
3118
|
-
});
|
|
2977
|
+
return getPortfolioQueryOptions(username, currency, true);
|
|
3119
2978
|
}
|
|
3120
2979
|
|
|
3121
2980
|
// src/modules/wallets/queries/use-get-account-wallet-list-query.ts
|
|
@@ -3620,13 +3479,13 @@ function getTronAssetGeneralInfoQueryOptions(username) {
|
|
|
3620
3479
|
function getAccountWalletAssetInfoQueryOptions(username, asset, options2 = { refetch: false }) {
|
|
3621
3480
|
const queryClient = getQueryClient();
|
|
3622
3481
|
const currency = options2.currency ?? "usd";
|
|
3623
|
-
const fetchQuery = async (
|
|
3482
|
+
const fetchQuery = async (queryOptions42) => {
|
|
3624
3483
|
if (options2.refetch) {
|
|
3625
|
-
await queryClient.fetchQuery(
|
|
3484
|
+
await queryClient.fetchQuery(queryOptions42);
|
|
3626
3485
|
} else {
|
|
3627
|
-
await queryClient.prefetchQuery(
|
|
3486
|
+
await queryClient.prefetchQuery(queryOptions42);
|
|
3628
3487
|
}
|
|
3629
|
-
return queryClient.getQueryData(
|
|
3488
|
+
return queryClient.getQueryData(queryOptions42.queryKey);
|
|
3630
3489
|
};
|
|
3631
3490
|
const convertPriceToUserCurrency = async (assetInfo) => {
|
|
3632
3491
|
if (!assetInfo || currency === "usd") {
|