@ecency/wallets 1.5.7 → 1.5.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 +4 -3
- package/dist/browser/index.js +62 -44
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +61 -43
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +62 -44
- 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 } from '@ecency/sdk';
|
|
1
|
+
import { CONFIG, getAccountFullQueryOptions, getQueryClient, getDynamicPropsQueryOptions, useBroadcastMutation, getSpkMarkets, getSpkWallet, getHiveEngineTokensMarket, getHiveEngineTokensBalances, getHiveEngineTokensMetadata, getHiveEngineTokenTransactions, getHiveEngineTokenMetrics, getHiveEngineUnclaimedRewards, EcencyAnalytics, 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';
|
|
@@ -1475,7 +1475,7 @@ function useClaimRewards(username, auth, onSuccess) {
|
|
|
1475
1475
|
queryKey: getAccountFullQueryOptions(username).queryKey
|
|
1476
1476
|
});
|
|
1477
1477
|
queryClient.invalidateQueries({
|
|
1478
|
-
queryKey:
|
|
1478
|
+
queryKey: ["ecency-wallets", "portfolio", "v2", username]
|
|
1479
1479
|
});
|
|
1480
1480
|
queryClient.invalidateQueries({
|
|
1481
1481
|
queryKey: getHiveAssetGeneralInfoQueryOptions(username).queryKey
|
|
@@ -1496,7 +1496,7 @@ function useClaimRewards(username, auth, onSuccess) {
|
|
|
1496
1496
|
queryKey: getAccountFullQueryOptions(username).queryKey
|
|
1497
1497
|
});
|
|
1498
1498
|
queryClient.invalidateQueries({
|
|
1499
|
-
queryKey:
|
|
1499
|
+
queryKey: ["ecency-wallets", "portfolio", "v2", username]
|
|
1500
1500
|
});
|
|
1501
1501
|
queryClient.invalidateQueries({
|
|
1502
1502
|
queryKey: getHiveAssetGeneralInfoQueryOptions(username).queryKey
|
|
@@ -3123,9 +3123,7 @@ function parseToken(rawToken) {
|
|
|
3123
3123
|
}
|
|
3124
3124
|
const normalizedSymbol = symbol.toUpperCase();
|
|
3125
3125
|
const title = normalizeString(token.title) ?? normalizeString(token.display) ?? normalizeString(token.label) ?? normalizeString(token.friendlyName) ?? normalizeString(token.name) ?? normalizedSymbol;
|
|
3126
|
-
const price = normalizeNumber(token.fiatRate) ??
|
|
3127
|
-
token.metrics?.priceUsd
|
|
3128
|
-
) ?? 0;
|
|
3126
|
+
const price = normalizeNumber(token.fiatRate) ?? 0;
|
|
3129
3127
|
const apr = normalizeApr(token.apr) ?? normalizeApr(token.aprPercent) ?? normalizeApr(token.metrics?.apr) ?? normalizeApr(
|
|
3130
3128
|
token.metrics?.aprPercent
|
|
3131
3129
|
);
|
|
@@ -3202,14 +3200,15 @@ function resolveUsername(payload) {
|
|
|
3202
3200
|
const record = payload;
|
|
3203
3201
|
return normalizeString(record.username) ?? normalizeString(record.name) ?? normalizeString(record.account);
|
|
3204
3202
|
}
|
|
3205
|
-
function getVisionPortfolioQueryOptions(username) {
|
|
3203
|
+
function getVisionPortfolioQueryOptions(username, currency = "usd") {
|
|
3206
3204
|
return queryOptions({
|
|
3207
3205
|
queryKey: [
|
|
3208
3206
|
"ecency-wallets",
|
|
3209
3207
|
"portfolio",
|
|
3210
3208
|
"v2",
|
|
3211
3209
|
username,
|
|
3212
|
-
"only-enabled"
|
|
3210
|
+
"only-enabled",
|
|
3211
|
+
currency
|
|
3213
3212
|
],
|
|
3214
3213
|
enabled: Boolean(username),
|
|
3215
3214
|
staleTime: 6e4,
|
|
@@ -3230,7 +3229,7 @@ function getVisionPortfolioQueryOptions(username) {
|
|
|
3230
3229
|
Accept: "application/json",
|
|
3231
3230
|
"Content-Type": "application/json"
|
|
3232
3231
|
},
|
|
3233
|
-
body: JSON.stringify({ username, onlyEnabled: true })
|
|
3232
|
+
body: JSON.stringify({ username, onlyEnabled: true, currency })
|
|
3234
3233
|
});
|
|
3235
3234
|
if (!response.ok) {
|
|
3236
3235
|
throw new Error(
|
|
@@ -3247,7 +3246,7 @@ function getVisionPortfolioQueryOptions(username) {
|
|
|
3247
3246
|
return {
|
|
3248
3247
|
username: resolveUsername(payload) ?? username,
|
|
3249
3248
|
currency: normalizeString(
|
|
3250
|
-
payload?.currency
|
|
3249
|
+
payload?.fiatCurrency ?? payload?.currency
|
|
3251
3250
|
)?.toUpperCase(),
|
|
3252
3251
|
wallets: tokens
|
|
3253
3252
|
};
|
|
@@ -3273,12 +3272,12 @@ var BASIC_TOKENS = [
|
|
|
3273
3272
|
"HP" /* HivePower */,
|
|
3274
3273
|
"HBD" /* HiveDollar */
|
|
3275
3274
|
];
|
|
3276
|
-
function getAccountWalletListQueryOptions(username) {
|
|
3275
|
+
function getAccountWalletListQueryOptions(username, currency = "usd") {
|
|
3277
3276
|
return queryOptions({
|
|
3278
|
-
queryKey: ["ecency-wallets", "list", username],
|
|
3277
|
+
queryKey: ["ecency-wallets", "list", username, currency],
|
|
3279
3278
|
enabled: !!username,
|
|
3280
3279
|
queryFn: async () => {
|
|
3281
|
-
const portfolioQuery = getVisionPortfolioQueryOptions(username);
|
|
3280
|
+
const portfolioQuery = getVisionPortfolioQueryOptions(username, currency);
|
|
3282
3281
|
const queryClient = getQueryClient();
|
|
3283
3282
|
const accountQuery = getAccountFullQueryOptions(username);
|
|
3284
3283
|
let account;
|
|
@@ -3756,6 +3755,7 @@ function getTronAssetGeneralInfoQueryOptions(username) {
|
|
|
3756
3755
|
// src/modules/wallets/queries/get-account-wallet-asset-info-query-options.ts
|
|
3757
3756
|
function getAccountWalletAssetInfoQueryOptions(username, asset, options2 = { refetch: false }) {
|
|
3758
3757
|
const queryClient = getQueryClient();
|
|
3758
|
+
const currency = options2.currency ?? "usd";
|
|
3759
3759
|
const fetchQuery = async (queryOptions43) => {
|
|
3760
3760
|
if (options2.refetch) {
|
|
3761
3761
|
await queryClient.fetchQuery(queryOptions43);
|
|
@@ -3764,7 +3764,22 @@ function getAccountWalletAssetInfoQueryOptions(username, asset, options2 = { ref
|
|
|
3764
3764
|
}
|
|
3765
3765
|
return queryClient.getQueryData(queryOptions43.queryKey);
|
|
3766
3766
|
};
|
|
3767
|
-
const
|
|
3767
|
+
const convertPriceToUserCurrency = async (assetInfo) => {
|
|
3768
|
+
if (!assetInfo || currency === "usd") {
|
|
3769
|
+
return assetInfo;
|
|
3770
|
+
}
|
|
3771
|
+
try {
|
|
3772
|
+
const conversionRate = await getCurrencyRate(currency);
|
|
3773
|
+
return {
|
|
3774
|
+
...assetInfo,
|
|
3775
|
+
price: assetInfo.price * conversionRate
|
|
3776
|
+
};
|
|
3777
|
+
} catch (error) {
|
|
3778
|
+
console.warn(`Failed to convert price from USD to ${currency}:`, error);
|
|
3779
|
+
return assetInfo;
|
|
3780
|
+
}
|
|
3781
|
+
};
|
|
3782
|
+
const portfolioQuery = getVisionPortfolioQueryOptions(username, currency);
|
|
3768
3783
|
const getPortfolioAssetInfo = async () => {
|
|
3769
3784
|
try {
|
|
3770
3785
|
const portfolio = await queryClient.fetchQuery(portfolioQuery);
|
|
@@ -3777,53 +3792,56 @@ function getAccountWalletAssetInfoQueryOptions(username, asset, options2 = { ref
|
|
|
3777
3792
|
}
|
|
3778
3793
|
};
|
|
3779
3794
|
return queryOptions({
|
|
3780
|
-
queryKey: ["ecency-wallets", "asset-info", username, asset],
|
|
3795
|
+
queryKey: ["ecency-wallets", "asset-info", username, asset, currency],
|
|
3781
3796
|
queryFn: async () => {
|
|
3782
3797
|
const portfolioAssetInfo = await getPortfolioAssetInfo();
|
|
3783
|
-
if (portfolioAssetInfo) {
|
|
3798
|
+
if (portfolioAssetInfo && portfolioAssetInfo.price > 0) {
|
|
3784
3799
|
return portfolioAssetInfo;
|
|
3785
3800
|
}
|
|
3801
|
+
let assetInfo;
|
|
3786
3802
|
if (asset === "HIVE") {
|
|
3787
|
-
|
|
3803
|
+
assetInfo = await fetchQuery(getHiveAssetGeneralInfoQueryOptions(username));
|
|
3788
3804
|
} else if (asset === "HP") {
|
|
3789
|
-
|
|
3805
|
+
assetInfo = await fetchQuery(getHivePowerAssetGeneralInfoQueryOptions(username));
|
|
3790
3806
|
} else if (asset === "HBD") {
|
|
3791
|
-
|
|
3807
|
+
assetInfo = await fetchQuery(getHbdAssetGeneralInfoQueryOptions(username));
|
|
3792
3808
|
} else if (asset === "SPK") {
|
|
3793
|
-
|
|
3809
|
+
assetInfo = await fetchQuery(getSpkAssetGeneralInfoQueryOptions(username));
|
|
3794
3810
|
} else if (asset === "LARYNX") {
|
|
3795
|
-
|
|
3811
|
+
assetInfo = await fetchQuery(getLarynxAssetGeneralInfoQueryOptions(username));
|
|
3796
3812
|
} else if (asset === "LP") {
|
|
3797
|
-
|
|
3813
|
+
assetInfo = await fetchQuery(getLarynxPowerAssetGeneralInfoQueryOptions(username));
|
|
3798
3814
|
} else if (asset === "POINTS") {
|
|
3799
|
-
|
|
3815
|
+
assetInfo = await fetchQuery(getPointsAssetGeneralInfoQueryOptions(username));
|
|
3800
3816
|
} else if (asset === "APT") {
|
|
3801
|
-
|
|
3817
|
+
assetInfo = await fetchQuery(getAptAssetGeneralInfoQueryOptions(username));
|
|
3802
3818
|
} else if (asset === "BNB") {
|
|
3803
|
-
|
|
3819
|
+
assetInfo = await fetchQuery(getBnbAssetGeneralInfoQueryOptions(username));
|
|
3804
3820
|
} else if (asset === "BTC") {
|
|
3805
|
-
|
|
3821
|
+
assetInfo = await fetchQuery(getBtcAssetGeneralInfoQueryOptions(username));
|
|
3806
3822
|
} else if (asset === "ETH") {
|
|
3807
|
-
|
|
3823
|
+
assetInfo = await fetchQuery(getEthAssetGeneralInfoQueryOptions(username));
|
|
3808
3824
|
} else if (asset === "SOL") {
|
|
3809
|
-
|
|
3825
|
+
assetInfo = await fetchQuery(getSolAssetGeneralInfoQueryOptions(username));
|
|
3810
3826
|
} else if (asset === "TON") {
|
|
3811
|
-
|
|
3827
|
+
assetInfo = await fetchQuery(getTonAssetGeneralInfoQueryOptions(username));
|
|
3812
3828
|
} else if (asset === "TRX") {
|
|
3813
|
-
|
|
3814
|
-
}
|
|
3815
|
-
const balances = await queryClient.ensureQueryData(
|
|
3816
|
-
getHiveEngineTokensBalancesQueryOptions(username)
|
|
3817
|
-
);
|
|
3818
|
-
if (balances.some((balance) => balance.symbol === asset)) {
|
|
3819
|
-
return await fetchQuery(
|
|
3820
|
-
getHiveEngineTokenGeneralInfoQueryOptions(username, asset)
|
|
3821
|
-
);
|
|
3829
|
+
assetInfo = await fetchQuery(getTronAssetGeneralInfoQueryOptions(username));
|
|
3822
3830
|
} else {
|
|
3823
|
-
|
|
3824
|
-
|
|
3831
|
+
const balances = await queryClient.ensureQueryData(
|
|
3832
|
+
getHiveEngineTokensBalancesQueryOptions(username)
|
|
3825
3833
|
);
|
|
3834
|
+
if (balances.some((balance) => balance.symbol === asset)) {
|
|
3835
|
+
assetInfo = await fetchQuery(
|
|
3836
|
+
getHiveEngineTokenGeneralInfoQueryOptions(username, asset)
|
|
3837
|
+
);
|
|
3838
|
+
} else {
|
|
3839
|
+
throw new Error(
|
|
3840
|
+
"[SDK][Wallets] \u2013 has requested unrecognized asset info"
|
|
3841
|
+
);
|
|
3842
|
+
}
|
|
3826
3843
|
}
|
|
3844
|
+
return await convertPriceToUserCurrency(assetInfo);
|
|
3827
3845
|
}
|
|
3828
3846
|
});
|
|
3829
3847
|
}
|
|
@@ -3837,9 +3855,9 @@ function hasNonZeroSavingsBalance(parts) {
|
|
|
3837
3855
|
)
|
|
3838
3856
|
);
|
|
3839
3857
|
}
|
|
3840
|
-
function getTokenOperationsQueryOptions(token, username, isForOwner = false) {
|
|
3858
|
+
function getTokenOperationsQueryOptions(token, username, isForOwner = false, currency = "usd") {
|
|
3841
3859
|
return queryOptions({
|
|
3842
|
-
queryKey: ["wallets", "token-operations", token, username, isForOwner],
|
|
3860
|
+
queryKey: ["wallets", "token-operations", token, username, isForOwner, currency],
|
|
3843
3861
|
queryFn: async () => {
|
|
3844
3862
|
const queryClient = getQueryClient();
|
|
3845
3863
|
const normalizedToken = token.toUpperCase();
|
|
@@ -3848,7 +3866,7 @@ function getTokenOperationsQueryOptions(token, username, isForOwner = false) {
|
|
|
3848
3866
|
}
|
|
3849
3867
|
try {
|
|
3850
3868
|
const portfolio = await queryClient.fetchQuery(
|
|
3851
|
-
getVisionPortfolioQueryOptions(username)
|
|
3869
|
+
getVisionPortfolioQueryOptions(username, currency)
|
|
3852
3870
|
);
|
|
3853
3871
|
const assetEntry = portfolio.wallets.find(
|
|
3854
3872
|
(assetItem) => assetItem.info.name === normalizedToken
|
|
@@ -4300,7 +4318,7 @@ function useWalletOperation(username, asset, operation, auth) {
|
|
|
4300
4318
|
});
|
|
4301
4319
|
setTimeout(
|
|
4302
4320
|
() => getQueryClient().invalidateQueries({
|
|
4303
|
-
queryKey:
|
|
4321
|
+
queryKey: ["ecency-wallets", "portfolio", "v2", username]
|
|
4304
4322
|
}),
|
|
4305
4323
|
4e3
|
|
4306
4324
|
);
|