@ecency/wallets 1.5.20 → 1.5.23
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 +11 -41
- package/dist/browser/index.js +10 -163
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +9 -162
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +10 -163
- 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';
|
|
@@ -2973,162 +2973,8 @@ function getAllTokensListQueryOptions(username) {
|
|
|
2973
2973
|
}
|
|
2974
2974
|
});
|
|
2975
2975
|
}
|
|
2976
|
-
function normalizeString(value) {
|
|
2977
|
-
if (typeof value === "string") {
|
|
2978
|
-
const trimmed = value.trim();
|
|
2979
|
-
return trimmed.length > 0 ? trimmed : void 0;
|
|
2980
|
-
}
|
|
2981
|
-
return void 0;
|
|
2982
|
-
}
|
|
2983
|
-
function normalizeNumber(value) {
|
|
2984
|
-
if (typeof value === "number" && Number.isFinite(value)) {
|
|
2985
|
-
return value;
|
|
2986
|
-
}
|
|
2987
|
-
if (typeof value === "string") {
|
|
2988
|
-
const trimmed = value.trim();
|
|
2989
|
-
if (!trimmed) {
|
|
2990
|
-
return void 0;
|
|
2991
|
-
}
|
|
2992
|
-
const direct = Number.parseFloat(trimmed);
|
|
2993
|
-
if (Number.isFinite(direct)) {
|
|
2994
|
-
return direct;
|
|
2995
|
-
}
|
|
2996
|
-
const sanitized = trimmed.replace(/,/g, "");
|
|
2997
|
-
const match = sanitized.match(/[-+]?\d+(?:\.\d+)?/);
|
|
2998
|
-
if (match) {
|
|
2999
|
-
const parsed = Number.parseFloat(match[0]);
|
|
3000
|
-
if (Number.isFinite(parsed)) {
|
|
3001
|
-
return parsed;
|
|
3002
|
-
}
|
|
3003
|
-
}
|
|
3004
|
-
}
|
|
3005
|
-
return void 0;
|
|
3006
|
-
}
|
|
3007
|
-
function parseToken(rawToken) {
|
|
3008
|
-
if (!rawToken || typeof rawToken !== "object") {
|
|
3009
|
-
return void 0;
|
|
3010
|
-
}
|
|
3011
|
-
const token = rawToken;
|
|
3012
|
-
return {
|
|
3013
|
-
name: normalizeString(token.name) ?? "",
|
|
3014
|
-
symbol: normalizeString(token.symbol) ?? "",
|
|
3015
|
-
layer: normalizeString(token.layer) ?? "hive",
|
|
3016
|
-
balance: normalizeNumber(token.balance) ?? 0,
|
|
3017
|
-
fiatRate: normalizeNumber(token.fiatRate) ?? 0,
|
|
3018
|
-
currency: normalizeString(token.currency) ?? "usd",
|
|
3019
|
-
precision: normalizeNumber(token.precision) ?? 3,
|
|
3020
|
-
address: normalizeString(token.address),
|
|
3021
|
-
error: normalizeString(token.error),
|
|
3022
|
-
pendingRewards: normalizeNumber(token.pendingRewards),
|
|
3023
|
-
pendingRewardsFiat: normalizeNumber(token.pendingRewardsFiat),
|
|
3024
|
-
liquid: normalizeNumber(token.liquid),
|
|
3025
|
-
liquidFiat: normalizeNumber(token.liquidFiat),
|
|
3026
|
-
savings: normalizeNumber(token.savings),
|
|
3027
|
-
savingsFiat: normalizeNumber(token.savingsFiat),
|
|
3028
|
-
staked: normalizeNumber(token.staked),
|
|
3029
|
-
stakedFiat: normalizeNumber(token.stakedFiat),
|
|
3030
|
-
iconUrl: normalizeString(token.iconUrl),
|
|
3031
|
-
actions: token.actions ?? [],
|
|
3032
|
-
extraData: token.extraData ?? [],
|
|
3033
|
-
apr: normalizeNumber(token.apr)
|
|
3034
|
-
};
|
|
3035
|
-
}
|
|
3036
|
-
function extractTokens(payload) {
|
|
3037
|
-
if (!payload || typeof payload !== "object") {
|
|
3038
|
-
return [];
|
|
3039
|
-
}
|
|
3040
|
-
const containers = [payload];
|
|
3041
|
-
const record = payload;
|
|
3042
|
-
if (record.data && typeof record.data === "object") {
|
|
3043
|
-
containers.push(record.data);
|
|
3044
|
-
}
|
|
3045
|
-
if (record.result && typeof record.result === "object") {
|
|
3046
|
-
containers.push(record.result);
|
|
3047
|
-
}
|
|
3048
|
-
if (record.portfolio && typeof record.portfolio === "object") {
|
|
3049
|
-
containers.push(record.portfolio);
|
|
3050
|
-
}
|
|
3051
|
-
for (const container of containers) {
|
|
3052
|
-
if (Array.isArray(container)) {
|
|
3053
|
-
return container;
|
|
3054
|
-
}
|
|
3055
|
-
if (container && typeof container === "object") {
|
|
3056
|
-
for (const key of [
|
|
3057
|
-
"wallets",
|
|
3058
|
-
"tokens",
|
|
3059
|
-
"assets",
|
|
3060
|
-
"items",
|
|
3061
|
-
"portfolio",
|
|
3062
|
-
"balances"
|
|
3063
|
-
]) {
|
|
3064
|
-
const value = container[key];
|
|
3065
|
-
if (Array.isArray(value)) {
|
|
3066
|
-
return value;
|
|
3067
|
-
}
|
|
3068
|
-
}
|
|
3069
|
-
}
|
|
3070
|
-
}
|
|
3071
|
-
return [];
|
|
3072
|
-
}
|
|
3073
|
-
function resolveUsername(payload) {
|
|
3074
|
-
if (!payload || typeof payload !== "object") {
|
|
3075
|
-
return void 0;
|
|
3076
|
-
}
|
|
3077
|
-
const record = payload;
|
|
3078
|
-
return normalizeString(record.username) ?? normalizeString(record.name) ?? normalizeString(record.account);
|
|
3079
|
-
}
|
|
3080
2976
|
function getVisionPortfolioQueryOptions(username, currency = "usd") {
|
|
3081
|
-
return
|
|
3082
|
-
queryKey: [
|
|
3083
|
-
"ecency-wallets",
|
|
3084
|
-
"portfolio",
|
|
3085
|
-
"v2",
|
|
3086
|
-
username,
|
|
3087
|
-
"only-enabled",
|
|
3088
|
-
currency
|
|
3089
|
-
],
|
|
3090
|
-
enabled: Boolean(username),
|
|
3091
|
-
staleTime: 6e4,
|
|
3092
|
-
refetchInterval: 12e4,
|
|
3093
|
-
queryFn: async () => {
|
|
3094
|
-
if (!username) {
|
|
3095
|
-
throw new Error("[SDK][Wallets] \u2013 username is required");
|
|
3096
|
-
}
|
|
3097
|
-
if (CONFIG.privateApiHost === void 0 || CONFIG.privateApiHost === null) {
|
|
3098
|
-
throw new Error(
|
|
3099
|
-
"[SDK][Wallets] \u2013 privateApiHost isn't configured for portfolio"
|
|
3100
|
-
);
|
|
3101
|
-
}
|
|
3102
|
-
const endpoint = `${CONFIG.privateApiHost}/wallet-api/portfolio-v2`;
|
|
3103
|
-
const response = await fetch(endpoint, {
|
|
3104
|
-
method: "POST",
|
|
3105
|
-
headers: {
|
|
3106
|
-
Accept: "application/json",
|
|
3107
|
-
"Content-Type": "application/json"
|
|
3108
|
-
},
|
|
3109
|
-
body: JSON.stringify({ username, onlyEnabled: true, currency })
|
|
3110
|
-
});
|
|
3111
|
-
if (!response.ok) {
|
|
3112
|
-
throw new Error(
|
|
3113
|
-
`[SDK][Wallets] \u2013 Vision portfolio request failed(${response.status})`
|
|
3114
|
-
);
|
|
3115
|
-
}
|
|
3116
|
-
const payload = await response.json();
|
|
3117
|
-
const tokens = extractTokens(payload).map((item) => parseToken(item)).filter((item) => Boolean(item));
|
|
3118
|
-
if (!tokens.length) {
|
|
3119
|
-
throw new Error(
|
|
3120
|
-
"[SDK][Wallets] \u2013 Vision portfolio payload contained no tokens"
|
|
3121
|
-
);
|
|
3122
|
-
}
|
|
3123
|
-
return {
|
|
3124
|
-
username: resolveUsername(payload) ?? username,
|
|
3125
|
-
currency: normalizeString(
|
|
3126
|
-
payload?.fiatCurrency ?? payload?.currency
|
|
3127
|
-
)?.toUpperCase(),
|
|
3128
|
-
wallets: tokens
|
|
3129
|
-
};
|
|
3130
|
-
}
|
|
3131
|
-
});
|
|
2977
|
+
return getPortfolioQueryOptions(username, currency, true);
|
|
3132
2978
|
}
|
|
3133
2979
|
|
|
3134
2980
|
// src/modules/wallets/queries/use-get-account-wallet-list-query.ts
|
|
@@ -3633,13 +3479,13 @@ function getTronAssetGeneralInfoQueryOptions(username) {
|
|
|
3633
3479
|
function getAccountWalletAssetInfoQueryOptions(username, asset, options2 = { refetch: false }) {
|
|
3634
3480
|
const queryClient = getQueryClient();
|
|
3635
3481
|
const currency = options2.currency ?? "usd";
|
|
3636
|
-
const fetchQuery = async (
|
|
3482
|
+
const fetchQuery = async (queryOptions42) => {
|
|
3637
3483
|
if (options2.refetch) {
|
|
3638
|
-
await queryClient.fetchQuery(
|
|
3484
|
+
await queryClient.fetchQuery(queryOptions42);
|
|
3639
3485
|
} else {
|
|
3640
|
-
await queryClient.prefetchQuery(
|
|
3486
|
+
await queryClient.prefetchQuery(queryOptions42);
|
|
3641
3487
|
}
|
|
3642
|
-
return queryClient.getQueryData(
|
|
3488
|
+
return queryClient.getQueryData(queryOptions42.queryKey);
|
|
3643
3489
|
};
|
|
3644
3490
|
const convertPriceToUserCurrency = async (assetInfo) => {
|
|
3645
3491
|
if (!assetInfo || currency === "usd") {
|
|
@@ -3769,7 +3615,7 @@ function getTokenOperationsQueryOptions(token, username, isForOwner = false, cur
|
|
|
3769
3615
|
queryFn: async () => {
|
|
3770
3616
|
const queryClient = getQueryClient();
|
|
3771
3617
|
const normalizedToken = token.toUpperCase();
|
|
3772
|
-
if (!username) {
|
|
3618
|
+
if (!username || !isForOwner) {
|
|
3773
3619
|
return [];
|
|
3774
3620
|
}
|
|
3775
3621
|
try {
|
|
@@ -3905,12 +3751,13 @@ var PATHS = {
|
|
|
3905
3751
|
["APT" /* APT */]: "m/44'/637'/0'/0'/0'"
|
|
3906
3752
|
// Aptos (BIP44)
|
|
3907
3753
|
};
|
|
3908
|
-
function useWalletCreate(username, currency) {
|
|
3909
|
-
const { data:
|
|
3754
|
+
function useWalletCreate(username, currency, importedSeed) {
|
|
3755
|
+
const { data: generatedMnemonic } = useSeedPhrase(username);
|
|
3910
3756
|
const queryClient = useQueryClient();
|
|
3911
3757
|
const createWallet = useMutation({
|
|
3912
3758
|
mutationKey: ["ecency-wallets", "create-wallet", username, currency],
|
|
3913
3759
|
mutationFn: async () => {
|
|
3760
|
+
const mnemonic = importedSeed || generatedMnemonic;
|
|
3914
3761
|
if (!mnemonic) {
|
|
3915
3762
|
throw new Error("[Ecency][Wallets] - No seed to create a wallet");
|
|
3916
3763
|
}
|