@ecency/wallets 1.5.10 → 1.5.12
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 +28 -16
- package/dist/browser/index.js +36 -182
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +36 -182
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +36 -182
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/browser/index.d.ts
CHANGED
|
@@ -775,6 +775,7 @@ declare enum AssetOperation {
|
|
|
775
775
|
WithdrawRoutes = "withdraw-routes",
|
|
776
776
|
ClaimInterest = "claim-interest",
|
|
777
777
|
Swap = "swap",
|
|
778
|
+
Convert = "convert",
|
|
778
779
|
Gift = "gift",
|
|
779
780
|
Promote = "promote",
|
|
780
781
|
Claim = "claim",
|
|
@@ -1814,25 +1815,36 @@ declare function getTokenOperationsQueryOptions(token: string, username: string,
|
|
|
1814
1815
|
|
|
1815
1816
|
declare function useWalletsCacheQuery(username?: string): _tanstack_react_query.DefinedUseQueryResult<Map<EcencyWalletCurrency, EcencyTokenMetadata>, Error>;
|
|
1816
1817
|
|
|
1818
|
+
type PortfolioLayer = "points" | "hive" | "chain" | "spk" | "engine";
|
|
1819
|
+
interface TokenAction {
|
|
1820
|
+
id: string;
|
|
1821
|
+
[key: string]: unknown;
|
|
1822
|
+
}
|
|
1817
1823
|
interface VisionPortfolioWalletItem {
|
|
1818
|
-
symbol: string;
|
|
1819
1824
|
name: string;
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
+
symbol: string;
|
|
1826
|
+
layer: PortfolioLayer;
|
|
1827
|
+
balance: number;
|
|
1828
|
+
fiatRate: number;
|
|
1829
|
+
currency: string;
|
|
1830
|
+
precision: number;
|
|
1831
|
+
address?: string;
|
|
1832
|
+
error?: string;
|
|
1825
1833
|
pendingRewards?: number;
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1834
|
+
pendingRewardsFiat?: number;
|
|
1835
|
+
liquid?: number;
|
|
1836
|
+
liquidFiat?: number;
|
|
1837
|
+
savings?: number;
|
|
1838
|
+
savingsFiat?: number;
|
|
1839
|
+
staked?: number;
|
|
1840
|
+
stakedFiat?: number;
|
|
1841
|
+
iconUrl?: string;
|
|
1842
|
+
actions?: TokenAction[];
|
|
1843
|
+
extraData?: Array<{
|
|
1844
|
+
dataKey: string;
|
|
1845
|
+
value: any;
|
|
1846
|
+
}>;
|
|
1847
|
+
apr?: number;
|
|
1836
1848
|
}
|
|
1837
1849
|
interface VisionPortfolioResponse {
|
|
1838
1850
|
username: string;
|
package/dist/browser/index.js
CHANGED
|
@@ -1564,6 +1564,7 @@ var AssetOperation = /* @__PURE__ */ ((AssetOperation2) => {
|
|
|
1564
1564
|
AssetOperation2["WithdrawRoutes"] = "withdraw-routes";
|
|
1565
1565
|
AssetOperation2["ClaimInterest"] = "claim-interest";
|
|
1566
1566
|
AssetOperation2["Swap"] = "swap";
|
|
1567
|
+
AssetOperation2["Convert"] = "convert";
|
|
1567
1568
|
AssetOperation2["Gift"] = "gift";
|
|
1568
1569
|
AssetOperation2["Promote"] = "promote";
|
|
1569
1570
|
AssetOperation2["Claim"] = "claim";
|
|
@@ -2876,35 +2877,6 @@ function getAllTokensListQueryOptions(username) {
|
|
|
2876
2877
|
}
|
|
2877
2878
|
});
|
|
2878
2879
|
}
|
|
2879
|
-
var DERIVED_PART_KEY_MAP = {
|
|
2880
|
-
liquid: ["liquid", "liquidBalance", "liquid_amount", "liquidTokens"],
|
|
2881
|
-
savings: ["savings", "savingsBalance", "savings_amount"],
|
|
2882
|
-
staked: ["staked", "stakedBalance", "staking", "stake", "power"],
|
|
2883
|
-
delegated: ["delegated", "delegatedBalance", "delegationsOut"],
|
|
2884
|
-
received: ["received", "receivedBalance", "delegationsIn"],
|
|
2885
|
-
pending: [
|
|
2886
|
-
"pending",
|
|
2887
|
-
"pendingRewards",
|
|
2888
|
-
"unclaimed",
|
|
2889
|
-
"unclaimedBalance",
|
|
2890
|
-
"pendingReward"
|
|
2891
|
-
]
|
|
2892
|
-
};
|
|
2893
|
-
var EXTRA_DATA_PART_KEY_MAP = {
|
|
2894
|
-
delegated: "outgoing_delegations",
|
|
2895
|
-
outgoing: "outgoing_delegations",
|
|
2896
|
-
delegations_out: "outgoing_delegations",
|
|
2897
|
-
delegated_hive_power: "outgoing_delegations",
|
|
2898
|
-
delegated_hp: "outgoing_delegations",
|
|
2899
|
-
received: "incoming_delegations",
|
|
2900
|
-
incoming: "incoming_delegations",
|
|
2901
|
-
delegations_in: "incoming_delegations",
|
|
2902
|
-
received_hive_power: "incoming_delegations",
|
|
2903
|
-
received_hp: "incoming_delegations",
|
|
2904
|
-
powering_down: "pending_power_down",
|
|
2905
|
-
power_down: "pending_power_down",
|
|
2906
|
-
powering_down_hive_power: "pending_power_down"
|
|
2907
|
-
};
|
|
2908
2880
|
function normalizeString(value) {
|
|
2909
2881
|
if (typeof value === "string") {
|
|
2910
2882
|
const trimmed = value.trim();
|
|
@@ -2936,151 +2908,33 @@ function normalizeNumber(value) {
|
|
|
2936
2908
|
}
|
|
2937
2909
|
return void 0;
|
|
2938
2910
|
}
|
|
2939
|
-
function normalizeApr(value) {
|
|
2940
|
-
const numeric = normalizeNumber(value);
|
|
2941
|
-
if (numeric === void 0) {
|
|
2942
|
-
if (typeof value === "string") {
|
|
2943
|
-
const trimmed = value.trim();
|
|
2944
|
-
return trimmed.length > 0 ? trimmed : void 0;
|
|
2945
|
-
}
|
|
2946
|
-
return void 0;
|
|
2947
|
-
}
|
|
2948
|
-
return numeric.toString();
|
|
2949
|
-
}
|
|
2950
|
-
function normalizeParts(rawParts) {
|
|
2951
|
-
if (Array.isArray(rawParts)) {
|
|
2952
|
-
const parsed = rawParts.map((item) => {
|
|
2953
|
-
if (!item || typeof item !== "object") {
|
|
2954
|
-
return void 0;
|
|
2955
|
-
}
|
|
2956
|
-
const name = normalizeString(
|
|
2957
|
-
item.name ?? item.label ?? item.type ?? item.part
|
|
2958
|
-
);
|
|
2959
|
-
const balance = normalizeNumber(
|
|
2960
|
-
item.balance ?? item.amount ?? item.value
|
|
2961
|
-
);
|
|
2962
|
-
if (!name || balance === void 0) {
|
|
2963
|
-
return void 0;
|
|
2964
|
-
}
|
|
2965
|
-
return { name, balance };
|
|
2966
|
-
}).filter((item) => Boolean(item));
|
|
2967
|
-
return parsed.length ? parsed : void 0;
|
|
2968
|
-
}
|
|
2969
|
-
if (rawParts && typeof rawParts === "object") {
|
|
2970
|
-
const parsed = Object.entries(rawParts).map(([name, amount]) => {
|
|
2971
|
-
const balance = normalizeNumber(amount);
|
|
2972
|
-
if (!name || balance === void 0) {
|
|
2973
|
-
return void 0;
|
|
2974
|
-
}
|
|
2975
|
-
return { name, balance };
|
|
2976
|
-
}).filter((item) => Boolean(item));
|
|
2977
|
-
return parsed.length ? parsed : void 0;
|
|
2978
|
-
}
|
|
2979
|
-
return void 0;
|
|
2980
|
-
}
|
|
2981
|
-
function deriveParts(record) {
|
|
2982
|
-
const derived = Object.entries(DERIVED_PART_KEY_MAP).map(([name, keys]) => {
|
|
2983
|
-
for (const key of keys) {
|
|
2984
|
-
const value = normalizeNumber(record[key]);
|
|
2985
|
-
if (value !== void 0) {
|
|
2986
|
-
return { name, balance: value };
|
|
2987
|
-
}
|
|
2988
|
-
}
|
|
2989
|
-
return void 0;
|
|
2990
|
-
}).filter((item) => Boolean(item));
|
|
2991
|
-
return derived.length ? derived : void 0;
|
|
2992
|
-
}
|
|
2993
|
-
function normalizePartKey(value) {
|
|
2994
|
-
return value.trim().toLowerCase().replace(/[\s-]+/g, "_");
|
|
2995
|
-
}
|
|
2996
|
-
function mergeParts(...sources) {
|
|
2997
|
-
const order = [];
|
|
2998
|
-
const values2 = /* @__PURE__ */ new Map();
|
|
2999
|
-
for (const parts of sources) {
|
|
3000
|
-
if (!parts) {
|
|
3001
|
-
continue;
|
|
3002
|
-
}
|
|
3003
|
-
for (const part of parts) {
|
|
3004
|
-
if (!part?.name || typeof part.balance !== "number") {
|
|
3005
|
-
continue;
|
|
3006
|
-
}
|
|
3007
|
-
const existing = values2.get(part.name);
|
|
3008
|
-
if (existing === void 0) {
|
|
3009
|
-
order.push(part.name);
|
|
3010
|
-
values2.set(part.name, part.balance);
|
|
3011
|
-
} else {
|
|
3012
|
-
values2.set(part.name, existing + part.balance);
|
|
3013
|
-
}
|
|
3014
|
-
}
|
|
3015
|
-
}
|
|
3016
|
-
return order.length ? order.map((name) => ({ name, balance: values2.get(name) })) : void 0;
|
|
3017
|
-
}
|
|
3018
|
-
function normalizeExtraDataParts(rawExtraData) {
|
|
3019
|
-
const items = Array.isArray(rawExtraData) ? rawExtraData : rawExtraData && typeof rawExtraData === "object" ? Object.values(rawExtraData) : [];
|
|
3020
|
-
const parts = items.map((item) => {
|
|
3021
|
-
if (!item || typeof item !== "object") {
|
|
3022
|
-
return void 0;
|
|
3023
|
-
}
|
|
3024
|
-
const record = item;
|
|
3025
|
-
const keyCandidate = normalizeString(record.dataKey) ?? normalizeString(record.key) ?? normalizeString(record.name);
|
|
3026
|
-
if (!keyCandidate) {
|
|
3027
|
-
return void 0;
|
|
3028
|
-
}
|
|
3029
|
-
const canonical = normalizePartKey(keyCandidate);
|
|
3030
|
-
const partName = EXTRA_DATA_PART_KEY_MAP[canonical];
|
|
3031
|
-
if (!partName) {
|
|
3032
|
-
return void 0;
|
|
3033
|
-
}
|
|
3034
|
-
const balance = normalizeNumber(
|
|
3035
|
-
record.balance ?? record.amount ?? record.value ?? record.displayValue ?? record.text
|
|
3036
|
-
);
|
|
3037
|
-
if (balance === void 0) {
|
|
3038
|
-
return void 0;
|
|
3039
|
-
}
|
|
3040
|
-
return { name: partName, balance: Math.abs(balance) };
|
|
3041
|
-
}).filter((part) => Boolean(part));
|
|
3042
|
-
return parts.length ? parts : void 0;
|
|
3043
|
-
}
|
|
3044
2911
|
function parseToken(rawToken) {
|
|
3045
2912
|
if (!rawToken || typeof rawToken !== "object") {
|
|
3046
2913
|
return void 0;
|
|
3047
2914
|
}
|
|
3048
2915
|
const token = rawToken;
|
|
3049
|
-
const symbol = normalizeString(token.symbol) ?? normalizeString(token.asset) ?? normalizeString(token.name);
|
|
3050
|
-
if (!symbol) {
|
|
3051
|
-
return void 0;
|
|
3052
|
-
}
|
|
3053
|
-
const normalizedSymbol = symbol.toUpperCase();
|
|
3054
|
-
const title = normalizeString(token.title) ?? normalizeString(token.display) ?? normalizeString(token.label) ?? normalizeString(token.friendlyName) ?? normalizeString(token.name) ?? normalizedSymbol;
|
|
3055
|
-
const price = normalizeNumber(token.fiatRate) ?? 0;
|
|
3056
|
-
const apr = normalizeApr(token.apr) ?? normalizeApr(token.aprPercent) ?? normalizeApr(token.metrics?.apr) ?? normalizeApr(
|
|
3057
|
-
token.metrics?.aprPercent
|
|
3058
|
-
);
|
|
3059
|
-
const baseParts = normalizeParts(
|
|
3060
|
-
token.parts ?? token.balances ?? token.sections ?? token.breakdown ?? token.accountBreakdown ?? token.walletParts
|
|
3061
|
-
) ?? deriveParts(token);
|
|
3062
|
-
const parts = mergeParts(
|
|
3063
|
-
baseParts,
|
|
3064
|
-
normalizeExtraDataParts(
|
|
3065
|
-
token.extraData ?? token.extra_data ?? token.extra ?? token.badges
|
|
3066
|
-
)
|
|
3067
|
-
);
|
|
3068
|
-
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);
|
|
3069
|
-
const layer = normalizeString(token.layer) ?? normalizeString(token.chain) ?? normalizeString(token.category) ?? normalizeString(token.type);
|
|
3070
|
-
const pendingRewards = normalizeNumber(token.pendingRewards);
|
|
3071
2916
|
return {
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
2917
|
+
name: normalizeString(token.name) ?? "",
|
|
2918
|
+
symbol: normalizeString(token.symbol) ?? "",
|
|
2919
|
+
layer: normalizeString(token.layer) ?? "hive",
|
|
2920
|
+
balance: normalizeNumber(token.balance) ?? 0,
|
|
2921
|
+
fiatRate: normalizeNumber(token.fiatRate) ?? 0,
|
|
2922
|
+
currency: normalizeString(token.currency) ?? "usd",
|
|
2923
|
+
precision: normalizeNumber(token.precision) ?? 3,
|
|
2924
|
+
address: normalizeString(token.address),
|
|
2925
|
+
error: normalizeString(token.error),
|
|
2926
|
+
pendingRewards: normalizeNumber(token.pendingRewards),
|
|
2927
|
+
pendingRewardsFiat: normalizeNumber(token.pendingRewardsFiat),
|
|
2928
|
+
liquid: normalizeNumber(token.liquid),
|
|
2929
|
+
liquidFiat: normalizeNumber(token.liquidFiat),
|
|
2930
|
+
savings: normalizeNumber(token.savings),
|
|
2931
|
+
savingsFiat: normalizeNumber(token.savingsFiat),
|
|
2932
|
+
staked: normalizeNumber(token.staked),
|
|
2933
|
+
stakedFiat: normalizeNumber(token.stakedFiat),
|
|
2934
|
+
iconUrl: normalizeString(token.iconUrl),
|
|
2935
|
+
actions: token.actions ?? [],
|
|
2936
|
+
extraData: token.extraData ?? [],
|
|
2937
|
+
apr: normalizeNumber(token.apr)
|
|
3084
2938
|
};
|
|
3085
2939
|
}
|
|
3086
2940
|
function extractTokens(payload) {
|
|
@@ -3144,7 +2998,7 @@ function getVisionPortfolioQueryOptions(username, currency = "usd") {
|
|
|
3144
2998
|
if (!username) {
|
|
3145
2999
|
throw new Error("[SDK][Wallets] \u2013 username is required");
|
|
3146
3000
|
}
|
|
3147
|
-
if (
|
|
3001
|
+
if (CONFIG.privateApiHost === void 0 || CONFIG.privateApiHost === null) {
|
|
3148
3002
|
throw new Error(
|
|
3149
3003
|
"[SDK][Wallets] \u2013 privateApiHost isn't configured for portfolio"
|
|
3150
3004
|
);
|
|
@@ -3237,7 +3091,7 @@ function getAccountWalletListQueryOptions(username, currency = "usd") {
|
|
|
3237
3091
|
try {
|
|
3238
3092
|
const portfolio = await queryClient.fetchQuery(portfolioQuery);
|
|
3239
3093
|
const tokensFromPortfolio = portfolio.wallets.map(
|
|
3240
|
-
(asset) => asset.
|
|
3094
|
+
(asset) => asset.symbol
|
|
3241
3095
|
);
|
|
3242
3096
|
if (tokensFromPortfolio.length > 0) {
|
|
3243
3097
|
const visibleTokens = tokensFromPortfolio.map((token) => token?.toUpperCase?.()).filter((token) => Boolean(token)).filter(isTokenVisible);
|
|
@@ -3711,18 +3565,17 @@ function getAccountWalletAssetInfoQueryOptions(username, asset, options2 = { ref
|
|
|
3711
3565
|
try {
|
|
3712
3566
|
const portfolio = await queryClient.fetchQuery(portfolioQuery);
|
|
3713
3567
|
const assetInfo = portfolio.wallets.find(
|
|
3714
|
-
(assetItem) => assetItem.
|
|
3568
|
+
(assetItem) => assetItem.symbol.toUpperCase() === asset.toUpperCase()
|
|
3715
3569
|
);
|
|
3716
3570
|
if (!assetInfo) return void 0;
|
|
3717
3571
|
return {
|
|
3718
|
-
name: assetInfo.
|
|
3719
|
-
title: assetInfo.
|
|
3720
|
-
price: assetInfo.
|
|
3721
|
-
accountBalance: assetInfo.
|
|
3722
|
-
apr: assetInfo.apr,
|
|
3572
|
+
name: assetInfo.symbol,
|
|
3573
|
+
title: assetInfo.name,
|
|
3574
|
+
price: assetInfo.fiatRate,
|
|
3575
|
+
accountBalance: assetInfo.balance,
|
|
3576
|
+
apr: assetInfo.apr?.toString(),
|
|
3723
3577
|
layer: assetInfo.layer,
|
|
3724
|
-
pendingRewards: assetInfo.pendingRewards
|
|
3725
|
-
parts: assetInfo.parts
|
|
3578
|
+
pendingRewards: assetInfo.pendingRewards
|
|
3726
3579
|
};
|
|
3727
3580
|
} catch (e) {
|
|
3728
3581
|
return void 0;
|
|
@@ -3796,7 +3649,7 @@ function getTokenOperationsQueryOptions(token, username, isForOwner = false, cur
|
|
|
3796
3649
|
getVisionPortfolioQueryOptions(username, currency)
|
|
3797
3650
|
);
|
|
3798
3651
|
const assetEntry = portfolio.wallets.find(
|
|
3799
|
-
(assetItem) => assetItem.symbol
|
|
3652
|
+
(assetItem) => assetItem.symbol.toUpperCase() === normalizedToken
|
|
3800
3653
|
);
|
|
3801
3654
|
if (!assetEntry) {
|
|
3802
3655
|
return [];
|
|
@@ -3851,7 +3704,7 @@ function getTokenOperationsQueryOptions(token, username, isForOwner = false, cur
|
|
|
3851
3704
|
"swap": "swap" /* Swap */,
|
|
3852
3705
|
"swap-token": "swap" /* Swap */,
|
|
3853
3706
|
"swap-tokens": "swap" /* Swap */,
|
|
3854
|
-
"convert": "
|
|
3707
|
+
"convert": "convert" /* Convert */,
|
|
3855
3708
|
// Points operations
|
|
3856
3709
|
"promote": "promote" /* Promote */,
|
|
3857
3710
|
"promote-post": "promote" /* Promote */,
|
|
@@ -3879,9 +3732,10 @@ function getTokenOperationsQueryOptions(token, username, isForOwner = false, cur
|
|
|
3879
3732
|
(op) => op.toLowerCase() === canonical
|
|
3880
3733
|
);
|
|
3881
3734
|
return directMatch;
|
|
3882
|
-
}).filter((op) => Boolean(op));
|
|
3735
|
+
}).filter((op) => Boolean(op)).filter((op, index, self) => self.indexOf(op) === index);
|
|
3883
3736
|
const isHiveOrHbd = ["HIVE", "HBD"].includes(normalizedToken);
|
|
3884
|
-
const
|
|
3737
|
+
const rawToken = assetEntry;
|
|
3738
|
+
const hasSavings = Number(rawToken.savings ?? 0) > 0;
|
|
3885
3739
|
if (isHiveOrHbd && !hasSavings) {
|
|
3886
3740
|
return operations.filter(
|
|
3887
3741
|
(operation) => operation !== "withdraw-saving" /* WithdrawFromSavings */
|