@ecency/wallets 1.4.26 → 1.4.27
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 +20 -1
- package/dist/browser/index.js +432 -9
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +432 -8
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +432 -9
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/node/index.mjs
CHANGED
|
@@ -2648,16 +2648,400 @@ function getAllTokensListQueryOptions(username) {
|
|
|
2648
2648
|
}
|
|
2649
2649
|
});
|
|
2650
2650
|
}
|
|
2651
|
+
var ACTION_ALIAS_MAP = {
|
|
2652
|
+
"transfer-to-savings": "transfer-saving" /* TransferToSavings */,
|
|
2653
|
+
"transfer-savings": "transfer-saving" /* TransferToSavings */,
|
|
2654
|
+
"savings-transfer": "transfer-saving" /* TransferToSavings */,
|
|
2655
|
+
"withdraw-from-savings": "withdraw-saving" /* WithdrawFromSavings */,
|
|
2656
|
+
"withdraw-savings": "withdraw-saving" /* WithdrawFromSavings */,
|
|
2657
|
+
"savings-withdraw": "withdraw-saving" /* WithdrawFromSavings */,
|
|
2658
|
+
"powerup": "power-up" /* PowerUp */,
|
|
2659
|
+
"power-down": "power-down" /* PowerDown */,
|
|
2660
|
+
"powerdown": "power-down" /* PowerDown */,
|
|
2661
|
+
"hp-delegate": "delegate" /* Delegate */,
|
|
2662
|
+
"delegate-hp": "delegate" /* Delegate */,
|
|
2663
|
+
"delegate-power": "delegate" /* Delegate */,
|
|
2664
|
+
"undelegate-power": "undelegate" /* Undelegate */,
|
|
2665
|
+
"undelegate-token": "undelegate" /* Undelegate */,
|
|
2666
|
+
"stake-token": "stake" /* Stake */,
|
|
2667
|
+
"stake-power": "stake" /* Stake */,
|
|
2668
|
+
"unstake-token": "unstake" /* Unstake */,
|
|
2669
|
+
"unstake-power": "unstake" /* Unstake */,
|
|
2670
|
+
"lock-liquidity": "lock" /* LockLiquidity */,
|
|
2671
|
+
"lock-liq": "lock" /* LockLiquidity */,
|
|
2672
|
+
"gift-points": "gift" /* Gift */,
|
|
2673
|
+
"points-gift": "gift" /* Gift */,
|
|
2674
|
+
"promote-post": "promote" /* Promote */,
|
|
2675
|
+
"promote-entry": "promote" /* Promote */,
|
|
2676
|
+
"claim-points": "claim" /* Claim */,
|
|
2677
|
+
"claim-rewards": "claim" /* Claim */,
|
|
2678
|
+
"buy-points": "buy" /* Buy */,
|
|
2679
|
+
"swap-token": "swap" /* Swap */,
|
|
2680
|
+
"swap-tokens": "swap" /* Swap */,
|
|
2681
|
+
"withdraw-routes": "withdraw-routes" /* WithdrawRoutes */,
|
|
2682
|
+
"withdrawroutes": "withdraw-routes" /* WithdrawRoutes */,
|
|
2683
|
+
"claim-interest": "claim-interest" /* ClaimInterest */
|
|
2684
|
+
};
|
|
2685
|
+
var KNOWN_OPERATION_VALUES = new Map(
|
|
2686
|
+
Object.values(AssetOperation).map((value) => [value, value])
|
|
2687
|
+
);
|
|
2688
|
+
var DERIVED_PART_KEY_MAP = {
|
|
2689
|
+
liquid: ["liquid", "liquidBalance", "liquid_amount", "liquidTokens"],
|
|
2690
|
+
savings: ["savings", "savingsBalance", "savings_amount"],
|
|
2691
|
+
staked: ["staked", "stakedBalance", "staking", "stake", "power"],
|
|
2692
|
+
delegated: ["delegated", "delegatedBalance", "delegationsOut"],
|
|
2693
|
+
received: ["received", "receivedBalance", "delegationsIn"],
|
|
2694
|
+
pending: [
|
|
2695
|
+
"pending",
|
|
2696
|
+
"pendingRewards",
|
|
2697
|
+
"unclaimed",
|
|
2698
|
+
"unclaimedBalance",
|
|
2699
|
+
"pendingReward"
|
|
2700
|
+
]
|
|
2701
|
+
};
|
|
2702
|
+
var EXTRA_DATA_PART_KEY_MAP = {
|
|
2703
|
+
delegated: "outgoing_delegations",
|
|
2704
|
+
outgoing: "outgoing_delegations",
|
|
2705
|
+
delegations_out: "outgoing_delegations",
|
|
2706
|
+
delegated_hive_power: "outgoing_delegations",
|
|
2707
|
+
delegated_hp: "outgoing_delegations",
|
|
2708
|
+
received: "incoming_delegations",
|
|
2709
|
+
incoming: "incoming_delegations",
|
|
2710
|
+
delegations_in: "incoming_delegations",
|
|
2711
|
+
received_hive_power: "incoming_delegations",
|
|
2712
|
+
received_hp: "incoming_delegations",
|
|
2713
|
+
powering_down: "pending_power_down",
|
|
2714
|
+
power_down: "pending_power_down",
|
|
2715
|
+
powering_down_hive_power: "pending_power_down"
|
|
2716
|
+
};
|
|
2717
|
+
function normalizeString(value) {
|
|
2718
|
+
if (typeof value === "string") {
|
|
2719
|
+
const trimmed = value.trim();
|
|
2720
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
2721
|
+
}
|
|
2722
|
+
return void 0;
|
|
2723
|
+
}
|
|
2724
|
+
function normalizeNumber(value) {
|
|
2725
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
2726
|
+
return value;
|
|
2727
|
+
}
|
|
2728
|
+
if (typeof value === "string") {
|
|
2729
|
+
const trimmed = value.trim();
|
|
2730
|
+
if (!trimmed) {
|
|
2731
|
+
return void 0;
|
|
2732
|
+
}
|
|
2733
|
+
const direct = Number.parseFloat(trimmed);
|
|
2734
|
+
if (Number.isFinite(direct)) {
|
|
2735
|
+
return direct;
|
|
2736
|
+
}
|
|
2737
|
+
const sanitized = trimmed.replace(/,/g, "");
|
|
2738
|
+
const match = sanitized.match(/[-+]?\d+(?:\.\d+)?/);
|
|
2739
|
+
if (match) {
|
|
2740
|
+
const parsed = Number.parseFloat(match[0]);
|
|
2741
|
+
if (Number.isFinite(parsed)) {
|
|
2742
|
+
return parsed;
|
|
2743
|
+
}
|
|
2744
|
+
}
|
|
2745
|
+
}
|
|
2746
|
+
return void 0;
|
|
2747
|
+
}
|
|
2748
|
+
function normalizeApr(value) {
|
|
2749
|
+
const numeric = normalizeNumber(value);
|
|
2750
|
+
if (numeric === void 0) {
|
|
2751
|
+
if (typeof value === "string") {
|
|
2752
|
+
const trimmed = value.trim();
|
|
2753
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
2754
|
+
}
|
|
2755
|
+
return void 0;
|
|
2756
|
+
}
|
|
2757
|
+
return numeric.toString();
|
|
2758
|
+
}
|
|
2759
|
+
function normalizeParts(rawParts) {
|
|
2760
|
+
if (Array.isArray(rawParts)) {
|
|
2761
|
+
const parsed = rawParts.map((item) => {
|
|
2762
|
+
if (!item || typeof item !== "object") {
|
|
2763
|
+
return void 0;
|
|
2764
|
+
}
|
|
2765
|
+
const name = normalizeString(
|
|
2766
|
+
item.name ?? item.label ?? item.type ?? item.part
|
|
2767
|
+
);
|
|
2768
|
+
const balance = normalizeNumber(
|
|
2769
|
+
item.balance ?? item.amount ?? item.value
|
|
2770
|
+
);
|
|
2771
|
+
if (!name || balance === void 0) {
|
|
2772
|
+
return void 0;
|
|
2773
|
+
}
|
|
2774
|
+
return { name, balance };
|
|
2775
|
+
}).filter((item) => Boolean(item));
|
|
2776
|
+
return parsed.length ? parsed : void 0;
|
|
2777
|
+
}
|
|
2778
|
+
if (rawParts && typeof rawParts === "object") {
|
|
2779
|
+
const parsed = Object.entries(rawParts).map(([name, amount]) => {
|
|
2780
|
+
const balance = normalizeNumber(amount);
|
|
2781
|
+
if (!name || balance === void 0) {
|
|
2782
|
+
return void 0;
|
|
2783
|
+
}
|
|
2784
|
+
return { name, balance };
|
|
2785
|
+
}).filter((item) => Boolean(item));
|
|
2786
|
+
return parsed.length ? parsed : void 0;
|
|
2787
|
+
}
|
|
2788
|
+
return void 0;
|
|
2789
|
+
}
|
|
2790
|
+
function deriveParts(record) {
|
|
2791
|
+
const derived = Object.entries(DERIVED_PART_KEY_MAP).map(([name, keys]) => {
|
|
2792
|
+
for (const key of keys) {
|
|
2793
|
+
const value = normalizeNumber(record[key]);
|
|
2794
|
+
if (value !== void 0) {
|
|
2795
|
+
return { name, balance: value };
|
|
2796
|
+
}
|
|
2797
|
+
}
|
|
2798
|
+
return void 0;
|
|
2799
|
+
}).filter((item) => Boolean(item));
|
|
2800
|
+
return derived.length ? derived : void 0;
|
|
2801
|
+
}
|
|
2802
|
+
function normalizePartKey(value) {
|
|
2803
|
+
return value.trim().toLowerCase().replace(/[\s-]+/g, "_");
|
|
2804
|
+
}
|
|
2805
|
+
function mergeParts(...sources) {
|
|
2806
|
+
const order = [];
|
|
2807
|
+
const values2 = /* @__PURE__ */ new Map();
|
|
2808
|
+
for (const parts of sources) {
|
|
2809
|
+
if (!parts) {
|
|
2810
|
+
continue;
|
|
2811
|
+
}
|
|
2812
|
+
for (const part of parts) {
|
|
2813
|
+
if (!part?.name || typeof part.balance !== "number") {
|
|
2814
|
+
continue;
|
|
2815
|
+
}
|
|
2816
|
+
const existing = values2.get(part.name);
|
|
2817
|
+
if (existing === void 0) {
|
|
2818
|
+
order.push(part.name);
|
|
2819
|
+
values2.set(part.name, part.balance);
|
|
2820
|
+
} else {
|
|
2821
|
+
values2.set(part.name, existing + part.balance);
|
|
2822
|
+
}
|
|
2823
|
+
}
|
|
2824
|
+
}
|
|
2825
|
+
return order.length ? order.map((name) => ({ name, balance: values2.get(name) })) : void 0;
|
|
2826
|
+
}
|
|
2827
|
+
function normalizeExtraDataParts(rawExtraData) {
|
|
2828
|
+
const items = Array.isArray(rawExtraData) ? rawExtraData : rawExtraData && typeof rawExtraData === "object" ? Object.values(rawExtraData) : [];
|
|
2829
|
+
const parts = items.map((item) => {
|
|
2830
|
+
if (!item || typeof item !== "object") {
|
|
2831
|
+
return void 0;
|
|
2832
|
+
}
|
|
2833
|
+
const record = item;
|
|
2834
|
+
const keyCandidate = normalizeString(record.dataKey) ?? normalizeString(record.key) ?? normalizeString(record.name);
|
|
2835
|
+
if (!keyCandidate) {
|
|
2836
|
+
return void 0;
|
|
2837
|
+
}
|
|
2838
|
+
const canonical = normalizePartKey(keyCandidate);
|
|
2839
|
+
const partName = EXTRA_DATA_PART_KEY_MAP[canonical];
|
|
2840
|
+
if (!partName) {
|
|
2841
|
+
return void 0;
|
|
2842
|
+
}
|
|
2843
|
+
const balance = normalizeNumber(
|
|
2844
|
+
record.balance ?? record.amount ?? record.value ?? record.displayValue ?? record.text
|
|
2845
|
+
);
|
|
2846
|
+
if (balance === void 0) {
|
|
2847
|
+
return void 0;
|
|
2848
|
+
}
|
|
2849
|
+
return { name: partName, balance: Math.abs(balance) };
|
|
2850
|
+
}).filter((part) => Boolean(part));
|
|
2851
|
+
return parts.length ? parts : void 0;
|
|
2852
|
+
}
|
|
2853
|
+
function normalizeActionKey(value) {
|
|
2854
|
+
return value.trim().toLowerCase().replace(/[\s_]+/g, "-");
|
|
2855
|
+
}
|
|
2856
|
+
function mapActions(rawActions) {
|
|
2857
|
+
if (!rawActions) {
|
|
2858
|
+
return [];
|
|
2859
|
+
}
|
|
2860
|
+
const rawList = Array.isArray(rawActions) ? rawActions : [rawActions];
|
|
2861
|
+
const result = [];
|
|
2862
|
+
for (const raw of rawList) {
|
|
2863
|
+
let candidate;
|
|
2864
|
+
if (typeof raw === "string") {
|
|
2865
|
+
candidate = raw;
|
|
2866
|
+
} else if (raw && typeof raw === "object") {
|
|
2867
|
+
const record = raw;
|
|
2868
|
+
candidate = normalizeString(record.code) ?? normalizeString(record.name) ?? normalizeString(record.action);
|
|
2869
|
+
}
|
|
2870
|
+
if (!candidate) {
|
|
2871
|
+
continue;
|
|
2872
|
+
}
|
|
2873
|
+
const canonical = normalizeActionKey(candidate);
|
|
2874
|
+
const operation = KNOWN_OPERATION_VALUES.get(canonical) ?? ACTION_ALIAS_MAP[canonical];
|
|
2875
|
+
if (operation && !result.includes(operation)) {
|
|
2876
|
+
result.push(operation);
|
|
2877
|
+
}
|
|
2878
|
+
}
|
|
2879
|
+
return result;
|
|
2880
|
+
}
|
|
2881
|
+
function parseToken(rawToken) {
|
|
2882
|
+
if (!rawToken || typeof rawToken !== "object") {
|
|
2883
|
+
return void 0;
|
|
2884
|
+
}
|
|
2885
|
+
const token = rawToken;
|
|
2886
|
+
const symbol = normalizeString(token.symbol) ?? normalizeString(token.asset) ?? normalizeString(token.name);
|
|
2887
|
+
if (!symbol) {
|
|
2888
|
+
return void 0;
|
|
2889
|
+
}
|
|
2890
|
+
const normalizedSymbol = symbol.toUpperCase();
|
|
2891
|
+
const title = normalizeString(token.title) ?? normalizeString(token.display) ?? normalizeString(token.label) ?? normalizeString(token.friendlyName) ?? normalizeString(token.name) ?? normalizedSymbol;
|
|
2892
|
+
const price = normalizeNumber(token.fiatRate) ?? normalizeNumber(token.price) ?? normalizeNumber(token.priceUsd) ?? normalizeNumber(token.usdPrice) ?? normalizeNumber(token.metrics?.price) ?? normalizeNumber(
|
|
2893
|
+
token.metrics?.priceUsd
|
|
2894
|
+
) ?? 0;
|
|
2895
|
+
const apr = normalizeApr(token.apr) ?? normalizeApr(token.aprPercent) ?? normalizeApr(token.metrics?.apr) ?? normalizeApr(
|
|
2896
|
+
token.metrics?.aprPercent
|
|
2897
|
+
);
|
|
2898
|
+
const baseParts = normalizeParts(
|
|
2899
|
+
token.parts ?? token.balances ?? token.sections ?? token.breakdown ?? token.accountBreakdown ?? token.walletParts
|
|
2900
|
+
) ?? deriveParts(token);
|
|
2901
|
+
const parts = mergeParts(
|
|
2902
|
+
baseParts,
|
|
2903
|
+
normalizeExtraDataParts(
|
|
2904
|
+
token.extraData ?? token.extra_data ?? token.extra ?? token.badges
|
|
2905
|
+
)
|
|
2906
|
+
);
|
|
2907
|
+
const accountBalance = normalizeNumber(token.balance) ?? normalizeNumber(token.accountBalance) ?? normalizeNumber(token.totalBalance) ?? normalizeNumber(token.total) ?? normalizeNumber(token.amount) ?? (baseParts ? baseParts.reduce((total, part) => total + (part.balance ?? 0), 0) : parts ? parts.reduce((total, part) => total + (part.balance ?? 0), 0) : 0);
|
|
2908
|
+
const layer = normalizeString(token.layer) ?? normalizeString(token.chain) ?? normalizeString(token.category) ?? normalizeString(token.type);
|
|
2909
|
+
return {
|
|
2910
|
+
symbol: normalizedSymbol,
|
|
2911
|
+
info: {
|
|
2912
|
+
name: normalizedSymbol,
|
|
2913
|
+
title,
|
|
2914
|
+
price,
|
|
2915
|
+
accountBalance,
|
|
2916
|
+
apr: apr ?? void 0,
|
|
2917
|
+
layer: layer ?? void 0,
|
|
2918
|
+
parts
|
|
2919
|
+
},
|
|
2920
|
+
operations: mapActions(
|
|
2921
|
+
token.actions ?? token.available_actions ?? token.availableActions ?? token.operations ?? token.supportedActions
|
|
2922
|
+
)
|
|
2923
|
+
};
|
|
2924
|
+
}
|
|
2925
|
+
function extractTokens(payload) {
|
|
2926
|
+
if (!payload || typeof payload !== "object") {
|
|
2927
|
+
return [];
|
|
2928
|
+
}
|
|
2929
|
+
const containers = [payload];
|
|
2930
|
+
const record = payload;
|
|
2931
|
+
if (record.data && typeof record.data === "object") {
|
|
2932
|
+
containers.push(record.data);
|
|
2933
|
+
}
|
|
2934
|
+
if (record.result && typeof record.result === "object") {
|
|
2935
|
+
containers.push(record.result);
|
|
2936
|
+
}
|
|
2937
|
+
if (record.portfolio && typeof record.portfolio === "object") {
|
|
2938
|
+
containers.push(record.portfolio);
|
|
2939
|
+
}
|
|
2940
|
+
for (const container of containers) {
|
|
2941
|
+
if (Array.isArray(container)) {
|
|
2942
|
+
return container;
|
|
2943
|
+
}
|
|
2944
|
+
if (container && typeof container === "object") {
|
|
2945
|
+
for (const key of [
|
|
2946
|
+
"wallets",
|
|
2947
|
+
"tokens",
|
|
2948
|
+
"assets",
|
|
2949
|
+
"items",
|
|
2950
|
+
"portfolio",
|
|
2951
|
+
"balances"
|
|
2952
|
+
]) {
|
|
2953
|
+
const value = container[key];
|
|
2954
|
+
if (Array.isArray(value)) {
|
|
2955
|
+
return value;
|
|
2956
|
+
}
|
|
2957
|
+
}
|
|
2958
|
+
}
|
|
2959
|
+
}
|
|
2960
|
+
return [];
|
|
2961
|
+
}
|
|
2962
|
+
function resolveUsername(payload) {
|
|
2963
|
+
if (!payload || typeof payload !== "object") {
|
|
2964
|
+
return void 0;
|
|
2965
|
+
}
|
|
2966
|
+
const record = payload;
|
|
2967
|
+
return normalizeString(record.username) ?? normalizeString(record.name) ?? normalizeString(record.account);
|
|
2968
|
+
}
|
|
2969
|
+
function getVisionPortfolioQueryOptions(username) {
|
|
2970
|
+
return queryOptions({
|
|
2971
|
+
queryKey: [
|
|
2972
|
+
"ecency-wallets",
|
|
2973
|
+
"portfolio",
|
|
2974
|
+
"v2",
|
|
2975
|
+
username,
|
|
2976
|
+
"only-enabled"
|
|
2977
|
+
],
|
|
2978
|
+
enabled: Boolean(username),
|
|
2979
|
+
staleTime: 6e4,
|
|
2980
|
+
refetchInterval: 12e4,
|
|
2981
|
+
queryFn: async () => {
|
|
2982
|
+
if (!username) {
|
|
2983
|
+
throw new Error("[SDK][Wallets] \u2013 username is required");
|
|
2984
|
+
}
|
|
2985
|
+
if (!CONFIG.privateApiHost) {
|
|
2986
|
+
throw new Error(
|
|
2987
|
+
"[SDK][Wallets] \u2013 privateApiHost isn't configured for portfolio"
|
|
2988
|
+
);
|
|
2989
|
+
}
|
|
2990
|
+
const endpoint = `${CONFIG.privateApiHost}/wallet-api/portfolio-v2`;
|
|
2991
|
+
const response = await fetch(endpoint, {
|
|
2992
|
+
method: "POST",
|
|
2993
|
+
headers: {
|
|
2994
|
+
Accept: "application/json",
|
|
2995
|
+
"Content-Type": "application/json"
|
|
2996
|
+
},
|
|
2997
|
+
body: JSON.stringify({ username, onlyEnabled: true })
|
|
2998
|
+
});
|
|
2999
|
+
if (!response.ok) {
|
|
3000
|
+
throw new Error(
|
|
3001
|
+
`[SDK][Wallets] \u2013 Vision portfolio request failed(${response.status})`
|
|
3002
|
+
);
|
|
3003
|
+
}
|
|
3004
|
+
const payload = await response.json();
|
|
3005
|
+
const tokens = extractTokens(payload).map((item) => parseToken(item)).filter((item) => Boolean(item));
|
|
3006
|
+
if (!tokens.length) {
|
|
3007
|
+
throw new Error(
|
|
3008
|
+
"[SDK][Wallets] \u2013 Vision portfolio payload contained no tokens"
|
|
3009
|
+
);
|
|
3010
|
+
}
|
|
3011
|
+
return {
|
|
3012
|
+
username: resolveUsername(payload) ?? username,
|
|
3013
|
+
currency: normalizeString(
|
|
3014
|
+
payload?.currency
|
|
3015
|
+
)?.toUpperCase(),
|
|
3016
|
+
wallets: tokens
|
|
3017
|
+
};
|
|
3018
|
+
}
|
|
3019
|
+
});
|
|
3020
|
+
}
|
|
3021
|
+
|
|
3022
|
+
// src/modules/wallets/queries/use-get-account-wallet-list-query.ts
|
|
2651
3023
|
function getAccountWalletListQueryOptions(username) {
|
|
2652
3024
|
return queryOptions({
|
|
2653
3025
|
queryKey: ["ecency-wallets", "list", username],
|
|
2654
3026
|
enabled: !!username,
|
|
2655
3027
|
queryFn: async () => {
|
|
3028
|
+
const portfolioQuery = getVisionPortfolioQueryOptions(username);
|
|
3029
|
+
const queryClient = getQueryClient();
|
|
3030
|
+
try {
|
|
3031
|
+
const portfolio = await queryClient.fetchQuery(portfolioQuery);
|
|
3032
|
+
const tokensFromPortfolio = portfolio.wallets.map(
|
|
3033
|
+
(asset) => asset.info.name
|
|
3034
|
+
);
|
|
3035
|
+
if (tokensFromPortfolio.length > 0) {
|
|
3036
|
+
return Array.from(new Set(tokensFromPortfolio));
|
|
3037
|
+
}
|
|
3038
|
+
} catch {
|
|
3039
|
+
}
|
|
2656
3040
|
const accountQuery = getAccountFullQueryOptions(username);
|
|
2657
|
-
await
|
|
3041
|
+
await queryClient.fetchQuery({
|
|
2658
3042
|
queryKey: accountQuery.queryKey
|
|
2659
3043
|
});
|
|
2660
|
-
const account =
|
|
3044
|
+
const account = queryClient.getQueryData(
|
|
2661
3045
|
accountQuery.queryKey
|
|
2662
3046
|
);
|
|
2663
3047
|
if (account?.profile?.tokens instanceof Array) {
|
|
@@ -3103,17 +3487,33 @@ function getTronAssetGeneralInfoQueryOptions(username) {
|
|
|
3103
3487
|
// src/modules/wallets/queries/get-account-wallet-asset-info-query-options.ts
|
|
3104
3488
|
function getAccountWalletAssetInfoQueryOptions(username, asset, options2 = { refetch: false }) {
|
|
3105
3489
|
const queryClient = getQueryClient();
|
|
3106
|
-
const fetchQuery = async (
|
|
3490
|
+
const fetchQuery = async (queryOptions40) => {
|
|
3107
3491
|
if (options2.refetch) {
|
|
3108
|
-
await queryClient.fetchQuery(
|
|
3492
|
+
await queryClient.fetchQuery(queryOptions40);
|
|
3109
3493
|
} else {
|
|
3110
|
-
await queryClient.prefetchQuery(
|
|
3494
|
+
await queryClient.prefetchQuery(queryOptions40);
|
|
3495
|
+
}
|
|
3496
|
+
return queryClient.getQueryData(queryOptions40.queryKey);
|
|
3497
|
+
};
|
|
3498
|
+
const portfolioQuery = getVisionPortfolioQueryOptions(username);
|
|
3499
|
+
const getPortfolioAssetInfo = async () => {
|
|
3500
|
+
try {
|
|
3501
|
+
const portfolio = await queryClient.fetchQuery(portfolioQuery);
|
|
3502
|
+
const assetInfo = portfolio.wallets.find(
|
|
3503
|
+
(assetItem) => assetItem.info.name === asset.toUpperCase()
|
|
3504
|
+
);
|
|
3505
|
+
return assetInfo?.info;
|
|
3506
|
+
} catch {
|
|
3507
|
+
return void 0;
|
|
3111
3508
|
}
|
|
3112
|
-
return queryClient.getQueryData(queryOptions39.queryKey);
|
|
3113
3509
|
};
|
|
3114
3510
|
return queryOptions({
|
|
3115
3511
|
queryKey: ["ecency-wallets", "asset-info", username, asset],
|
|
3116
3512
|
queryFn: async () => {
|
|
3513
|
+
const portfolioAssetInfo = await getPortfolioAssetInfo();
|
|
3514
|
+
if (portfolioAssetInfo) {
|
|
3515
|
+
return portfolioAssetInfo;
|
|
3516
|
+
}
|
|
3117
3517
|
if (asset === "HIVE") {
|
|
3118
3518
|
return fetchQuery(getHiveAssetGeneralInfoQueryOptions(username));
|
|
3119
3519
|
} else if (asset === "HP") {
|
|
@@ -3163,15 +3563,38 @@ function getTokenOperationsQueryOptions(token, username, isForOwner = false) {
|
|
|
3163
3563
|
queryKey: ["wallets", "token-operations", token, username, isForOwner],
|
|
3164
3564
|
queryFn: async () => {
|
|
3165
3565
|
const queryClient = getQueryClient();
|
|
3566
|
+
const normalizedToken = token.toUpperCase();
|
|
3567
|
+
const portfolioOperations = await (async () => {
|
|
3568
|
+
if (!isForOwner || !username) {
|
|
3569
|
+
return void 0;
|
|
3570
|
+
}
|
|
3571
|
+
try {
|
|
3572
|
+
const portfolio = await queryClient.fetchQuery(
|
|
3573
|
+
getVisionPortfolioQueryOptions(username)
|
|
3574
|
+
);
|
|
3575
|
+
const assetEntry = portfolio.wallets.find(
|
|
3576
|
+
(assetItem) => assetItem.info.name === normalizedToken
|
|
3577
|
+
);
|
|
3578
|
+
if (assetEntry?.operations.length) {
|
|
3579
|
+
return assetEntry.operations;
|
|
3580
|
+
}
|
|
3581
|
+
} catch {
|
|
3582
|
+
return void 0;
|
|
3583
|
+
}
|
|
3584
|
+
return void 0;
|
|
3585
|
+
})();
|
|
3586
|
+
if (portfolioOperations && portfolioOperations.length > 0) {
|
|
3587
|
+
return portfolioOperations;
|
|
3588
|
+
}
|
|
3166
3589
|
const ensureAssetInfo = async () => {
|
|
3167
3590
|
if (!isForOwner || !username) {
|
|
3168
3591
|
return void 0;
|
|
3169
3592
|
}
|
|
3170
3593
|
return await queryClient.ensureQueryData(
|
|
3171
|
-
getAccountWalletAssetInfoQueryOptions(username,
|
|
3594
|
+
getAccountWalletAssetInfoQueryOptions(username, normalizedToken)
|
|
3172
3595
|
);
|
|
3173
3596
|
};
|
|
3174
|
-
switch (
|
|
3597
|
+
switch (normalizedToken) {
|
|
3175
3598
|
case "HIVE" /* Hive */: {
|
|
3176
3599
|
const assetInfo = await ensureAssetInfo();
|
|
3177
3600
|
const savingsBalance = assetInfo?.parts?.find(
|
|
@@ -3731,6 +4154,6 @@ function useWalletOperation(username, asset, operation) {
|
|
|
3731
4154
|
// src/index.ts
|
|
3732
4155
|
rememberScryptBsvVersion();
|
|
3733
4156
|
|
|
3734
|
-
export { AssetOperation, EcencyWalletBasicTokens, EcencyWalletCurrency, private_api_exports as EcencyWalletsPrivateApi, HIVE_ACCOUNT_OPERATION_GROUPS, HIVE_OPERATION_LIST, HIVE_OPERATION_NAME_BY_ID, HIVE_OPERATION_ORDERS, NaiMap, PointTransactionType, Symbol2 as Symbol, broadcastWithWalletHiveAuth, buildAptTx, buildEthTx, buildExternalTx, buildPsbt, buildSolTx, buildTonTx, buildTronTx, claimInterestHive, 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, hasWalletHiveAuthBroadcast, isEmptyDate, lockLarynx, mnemonicToSeedBip39, parseAsset, powerDownHive, powerUpHive, powerUpLarynx, registerWalletHiveAuthBroadcast, resolveHiveOperationFilters, rewardSpk, signDigest, signExternalTx, signExternalTxAndBroadcast, signTx, signTxAndBroadcast, stakeEngineToken, transferEngineToken, transferFromSavingsHive, transferHive, transferLarynx, transferPoint, transferSpk, transferToSavingsHive, undelegateEngineToken, unstakeEngineToken, useClaimPoints, useClaimRewards, useGetExternalWalletBalanceQuery, useHiveKeysQuery, useImportWallet, useSaveWalletInformationToMetadata, useSeedPhrase, useWalletCreate, useWalletOperation, useWalletsCacheQuery, vestsToHp, withdrawVestingRouteHive };
|
|
4157
|
+
export { AssetOperation, EcencyWalletBasicTokens, EcencyWalletCurrency, private_api_exports as EcencyWalletsPrivateApi, HIVE_ACCOUNT_OPERATION_GROUPS, HIVE_OPERATION_LIST, HIVE_OPERATION_NAME_BY_ID, HIVE_OPERATION_ORDERS, NaiMap, PointTransactionType, Symbol2 as Symbol, broadcastWithWalletHiveAuth, buildAptTx, buildEthTx, buildExternalTx, buildPsbt, buildSolTx, buildTonTx, buildTronTx, claimInterestHive, 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, getVisionPortfolioQueryOptions, getWallet, hasWalletHiveAuthBroadcast, isEmptyDate, lockLarynx, mnemonicToSeedBip39, parseAsset, powerDownHive, powerUpHive, powerUpLarynx, registerWalletHiveAuthBroadcast, resolveHiveOperationFilters, rewardSpk, signDigest, signExternalTx, signExternalTxAndBroadcast, signTx, signTxAndBroadcast, stakeEngineToken, transferEngineToken, transferFromSavingsHive, transferHive, transferLarynx, transferPoint, transferSpk, transferToSavingsHive, undelegateEngineToken, unstakeEngineToken, useClaimPoints, useClaimRewards, useGetExternalWalletBalanceQuery, useHiveKeysQuery, useImportWallet, useSaveWalletInformationToMetadata, useSeedPhrase, useWalletCreate, useWalletOperation, useWalletsCacheQuery, vestsToHp, withdrawVestingRouteHive };
|
|
3735
4158
|
//# sourceMappingURL=index.mjs.map
|
|
3736
4159
|
//# sourceMappingURL=index.mjs.map
|