@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/browser/index.d.ts
CHANGED
|
@@ -1781,7 +1781,7 @@ declare function getAllTokensListQueryOptions(username?: string): _tanstack_reac
|
|
|
1781
1781
|
};
|
|
1782
1782
|
};
|
|
1783
1783
|
|
|
1784
|
-
declare function getAccountWalletListQueryOptions(username: string): _tanstack_react_query.OmitKeyof<_tanstack_react_query.UseQueryOptions<string[], Error, string[], string[]>, "queryFn"> & {
|
|
1784
|
+
declare function getAccountWalletListQueryOptions(username: string, currency?: string): _tanstack_react_query.OmitKeyof<_tanstack_react_query.UseQueryOptions<string[], Error, string[], string[]>, "queryFn"> & {
|
|
1785
1785
|
queryFn?: _tanstack_react_query.QueryFunction<string[], string[], never> | undefined;
|
|
1786
1786
|
} & {
|
|
1787
1787
|
queryKey: string[] & {
|
|
@@ -1792,6 +1792,7 @@ declare function getAccountWalletListQueryOptions(username: string): _tanstack_r
|
|
|
1792
1792
|
|
|
1793
1793
|
interface Options {
|
|
1794
1794
|
refetch: boolean;
|
|
1795
|
+
currency?: string;
|
|
1795
1796
|
}
|
|
1796
1797
|
declare function getAccountWalletAssetInfoQueryOptions(username: string, asset: string, options?: Options): _tanstack_react_query.OmitKeyof<_tanstack_react_query.UseQueryOptions<GeneralAssetInfo | undefined, Error, GeneralAssetInfo | undefined, string[]>, "queryFn"> & {
|
|
1797
1798
|
queryFn?: _tanstack_react_query.QueryFunction<GeneralAssetInfo | undefined, string[], never> | undefined;
|
|
@@ -1802,7 +1803,7 @@ declare function getAccountWalletAssetInfoQueryOptions(username: string, asset:
|
|
|
1802
1803
|
};
|
|
1803
1804
|
};
|
|
1804
1805
|
|
|
1805
|
-
declare function getTokenOperationsQueryOptions(token: string, username: string, isForOwner?: boolean): _tanstack_react_query.OmitKeyof<_tanstack_react_query.UseQueryOptions<AssetOperation[], Error, AssetOperation[], (string | boolean)[]>, "queryFn"> & {
|
|
1806
|
+
declare function getTokenOperationsQueryOptions(token: string, username: string, isForOwner?: boolean, currency?: string): _tanstack_react_query.OmitKeyof<_tanstack_react_query.UseQueryOptions<AssetOperation[], Error, AssetOperation[], (string | boolean)[]>, "queryFn"> & {
|
|
1806
1807
|
queryFn?: _tanstack_react_query.QueryFunction<AssetOperation[], (string | boolean)[], never> | undefined;
|
|
1807
1808
|
} & {
|
|
1808
1809
|
queryKey: (string | boolean)[] & {
|
|
@@ -1823,7 +1824,7 @@ interface VisionPortfolioResponse {
|
|
|
1823
1824
|
currency?: string;
|
|
1824
1825
|
wallets: VisionPortfolioWalletItem[];
|
|
1825
1826
|
}
|
|
1826
|
-
declare function getVisionPortfolioQueryOptions(username: string): _tanstack_react_query.OmitKeyof<_tanstack_react_query.UseQueryOptions<VisionPortfolioResponse, Error, VisionPortfolioResponse, string[]>, "queryFn"> & {
|
|
1827
|
+
declare function getVisionPortfolioQueryOptions(username: string, currency?: string): _tanstack_react_query.OmitKeyof<_tanstack_react_query.UseQueryOptions<VisionPortfolioResponse, Error, VisionPortfolioResponse, string[]>, "queryFn"> & {
|
|
1827
1828
|
queryFn?: _tanstack_react_query.QueryFunction<VisionPortfolioResponse, string[], never> | undefined;
|
|
1828
1829
|
} & {
|
|
1829
1830
|
queryKey: string[] & {
|
package/dist/browser/index.js
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';
|
|
@@ -1477,7 +1477,7 @@ function useClaimRewards(username, auth, onSuccess) {
|
|
|
1477
1477
|
queryKey: getAccountFullQueryOptions(username).queryKey
|
|
1478
1478
|
});
|
|
1479
1479
|
queryClient.invalidateQueries({
|
|
1480
|
-
queryKey:
|
|
1480
|
+
queryKey: ["ecency-wallets", "portfolio", "v2", username]
|
|
1481
1481
|
});
|
|
1482
1482
|
queryClient.invalidateQueries({
|
|
1483
1483
|
queryKey: getHiveAssetGeneralInfoQueryOptions(username).queryKey
|
|
@@ -1498,7 +1498,7 @@ function useClaimRewards(username, auth, onSuccess) {
|
|
|
1498
1498
|
queryKey: getAccountFullQueryOptions(username).queryKey
|
|
1499
1499
|
});
|
|
1500
1500
|
queryClient.invalidateQueries({
|
|
1501
|
-
queryKey:
|
|
1501
|
+
queryKey: ["ecency-wallets", "portfolio", "v2", username]
|
|
1502
1502
|
});
|
|
1503
1503
|
queryClient.invalidateQueries({
|
|
1504
1504
|
queryKey: getHiveAssetGeneralInfoQueryOptions(username).queryKey
|
|
@@ -3125,9 +3125,7 @@ function parseToken(rawToken) {
|
|
|
3125
3125
|
}
|
|
3126
3126
|
const normalizedSymbol = symbol.toUpperCase();
|
|
3127
3127
|
const title = normalizeString(token.title) ?? normalizeString(token.display) ?? normalizeString(token.label) ?? normalizeString(token.friendlyName) ?? normalizeString(token.name) ?? normalizedSymbol;
|
|
3128
|
-
const price = normalizeNumber(token.fiatRate) ??
|
|
3129
|
-
token.metrics?.priceUsd
|
|
3130
|
-
) ?? 0;
|
|
3128
|
+
const price = normalizeNumber(token.fiatRate) ?? 0;
|
|
3131
3129
|
const apr = normalizeApr(token.apr) ?? normalizeApr(token.aprPercent) ?? normalizeApr(token.metrics?.apr) ?? normalizeApr(
|
|
3132
3130
|
token.metrics?.aprPercent
|
|
3133
3131
|
);
|
|
@@ -3204,14 +3202,15 @@ function resolveUsername(payload) {
|
|
|
3204
3202
|
const record = payload;
|
|
3205
3203
|
return normalizeString(record.username) ?? normalizeString(record.name) ?? normalizeString(record.account);
|
|
3206
3204
|
}
|
|
3207
|
-
function getVisionPortfolioQueryOptions(username) {
|
|
3205
|
+
function getVisionPortfolioQueryOptions(username, currency = "usd") {
|
|
3208
3206
|
return queryOptions({
|
|
3209
3207
|
queryKey: [
|
|
3210
3208
|
"ecency-wallets",
|
|
3211
3209
|
"portfolio",
|
|
3212
3210
|
"v2",
|
|
3213
3211
|
username,
|
|
3214
|
-
"only-enabled"
|
|
3212
|
+
"only-enabled",
|
|
3213
|
+
currency
|
|
3215
3214
|
],
|
|
3216
3215
|
enabled: Boolean(username),
|
|
3217
3216
|
staleTime: 6e4,
|
|
@@ -3232,7 +3231,7 @@ function getVisionPortfolioQueryOptions(username) {
|
|
|
3232
3231
|
Accept: "application/json",
|
|
3233
3232
|
"Content-Type": "application/json"
|
|
3234
3233
|
},
|
|
3235
|
-
body: JSON.stringify({ username, onlyEnabled: true })
|
|
3234
|
+
body: JSON.stringify({ username, onlyEnabled: true, currency })
|
|
3236
3235
|
});
|
|
3237
3236
|
if (!response.ok) {
|
|
3238
3237
|
throw new Error(
|
|
@@ -3249,7 +3248,7 @@ function getVisionPortfolioQueryOptions(username) {
|
|
|
3249
3248
|
return {
|
|
3250
3249
|
username: resolveUsername(payload) ?? username,
|
|
3251
3250
|
currency: normalizeString(
|
|
3252
|
-
payload?.currency
|
|
3251
|
+
payload?.fiatCurrency ?? payload?.currency
|
|
3253
3252
|
)?.toUpperCase(),
|
|
3254
3253
|
wallets: tokens
|
|
3255
3254
|
};
|
|
@@ -3275,12 +3274,12 @@ var BASIC_TOKENS = [
|
|
|
3275
3274
|
"HP" /* HivePower */,
|
|
3276
3275
|
"HBD" /* HiveDollar */
|
|
3277
3276
|
];
|
|
3278
|
-
function getAccountWalletListQueryOptions(username) {
|
|
3277
|
+
function getAccountWalletListQueryOptions(username, currency = "usd") {
|
|
3279
3278
|
return queryOptions({
|
|
3280
|
-
queryKey: ["ecency-wallets", "list", username],
|
|
3279
|
+
queryKey: ["ecency-wallets", "list", username, currency],
|
|
3281
3280
|
enabled: !!username,
|
|
3282
3281
|
queryFn: async () => {
|
|
3283
|
-
const portfolioQuery = getVisionPortfolioQueryOptions(username);
|
|
3282
|
+
const portfolioQuery = getVisionPortfolioQueryOptions(username, currency);
|
|
3284
3283
|
const queryClient = getQueryClient();
|
|
3285
3284
|
const accountQuery = getAccountFullQueryOptions(username);
|
|
3286
3285
|
let account;
|
|
@@ -3758,6 +3757,7 @@ function getTronAssetGeneralInfoQueryOptions(username) {
|
|
|
3758
3757
|
// src/modules/wallets/queries/get-account-wallet-asset-info-query-options.ts
|
|
3759
3758
|
function getAccountWalletAssetInfoQueryOptions(username, asset, options2 = { refetch: false }) {
|
|
3760
3759
|
const queryClient = getQueryClient();
|
|
3760
|
+
const currency = options2.currency ?? "usd";
|
|
3761
3761
|
const fetchQuery = async (queryOptions43) => {
|
|
3762
3762
|
if (options2.refetch) {
|
|
3763
3763
|
await queryClient.fetchQuery(queryOptions43);
|
|
@@ -3766,7 +3766,22 @@ function getAccountWalletAssetInfoQueryOptions(username, asset, options2 = { ref
|
|
|
3766
3766
|
}
|
|
3767
3767
|
return queryClient.getQueryData(queryOptions43.queryKey);
|
|
3768
3768
|
};
|
|
3769
|
-
const
|
|
3769
|
+
const convertPriceToUserCurrency = async (assetInfo) => {
|
|
3770
|
+
if (!assetInfo || currency === "usd") {
|
|
3771
|
+
return assetInfo;
|
|
3772
|
+
}
|
|
3773
|
+
try {
|
|
3774
|
+
const conversionRate = await getCurrencyRate(currency);
|
|
3775
|
+
return {
|
|
3776
|
+
...assetInfo,
|
|
3777
|
+
price: assetInfo.price * conversionRate
|
|
3778
|
+
};
|
|
3779
|
+
} catch (error) {
|
|
3780
|
+
console.warn(`Failed to convert price from USD to ${currency}:`, error);
|
|
3781
|
+
return assetInfo;
|
|
3782
|
+
}
|
|
3783
|
+
};
|
|
3784
|
+
const portfolioQuery = getVisionPortfolioQueryOptions(username, currency);
|
|
3770
3785
|
const getPortfolioAssetInfo = async () => {
|
|
3771
3786
|
try {
|
|
3772
3787
|
const portfolio = await queryClient.fetchQuery(portfolioQuery);
|
|
@@ -3779,53 +3794,56 @@ function getAccountWalletAssetInfoQueryOptions(username, asset, options2 = { ref
|
|
|
3779
3794
|
}
|
|
3780
3795
|
};
|
|
3781
3796
|
return queryOptions({
|
|
3782
|
-
queryKey: ["ecency-wallets", "asset-info", username, asset],
|
|
3797
|
+
queryKey: ["ecency-wallets", "asset-info", username, asset, currency],
|
|
3783
3798
|
queryFn: async () => {
|
|
3784
3799
|
const portfolioAssetInfo = await getPortfolioAssetInfo();
|
|
3785
|
-
if (portfolioAssetInfo) {
|
|
3800
|
+
if (portfolioAssetInfo && portfolioAssetInfo.price > 0) {
|
|
3786
3801
|
return portfolioAssetInfo;
|
|
3787
3802
|
}
|
|
3803
|
+
let assetInfo;
|
|
3788
3804
|
if (asset === "HIVE") {
|
|
3789
|
-
|
|
3805
|
+
assetInfo = await fetchQuery(getHiveAssetGeneralInfoQueryOptions(username));
|
|
3790
3806
|
} else if (asset === "HP") {
|
|
3791
|
-
|
|
3807
|
+
assetInfo = await fetchQuery(getHivePowerAssetGeneralInfoQueryOptions(username));
|
|
3792
3808
|
} else if (asset === "HBD") {
|
|
3793
|
-
|
|
3809
|
+
assetInfo = await fetchQuery(getHbdAssetGeneralInfoQueryOptions(username));
|
|
3794
3810
|
} else if (asset === "SPK") {
|
|
3795
|
-
|
|
3811
|
+
assetInfo = await fetchQuery(getSpkAssetGeneralInfoQueryOptions(username));
|
|
3796
3812
|
} else if (asset === "LARYNX") {
|
|
3797
|
-
|
|
3813
|
+
assetInfo = await fetchQuery(getLarynxAssetGeneralInfoQueryOptions(username));
|
|
3798
3814
|
} else if (asset === "LP") {
|
|
3799
|
-
|
|
3815
|
+
assetInfo = await fetchQuery(getLarynxPowerAssetGeneralInfoQueryOptions(username));
|
|
3800
3816
|
} else if (asset === "POINTS") {
|
|
3801
|
-
|
|
3817
|
+
assetInfo = await fetchQuery(getPointsAssetGeneralInfoQueryOptions(username));
|
|
3802
3818
|
} else if (asset === "APT") {
|
|
3803
|
-
|
|
3819
|
+
assetInfo = await fetchQuery(getAptAssetGeneralInfoQueryOptions(username));
|
|
3804
3820
|
} else if (asset === "BNB") {
|
|
3805
|
-
|
|
3821
|
+
assetInfo = await fetchQuery(getBnbAssetGeneralInfoQueryOptions(username));
|
|
3806
3822
|
} else if (asset === "BTC") {
|
|
3807
|
-
|
|
3823
|
+
assetInfo = await fetchQuery(getBtcAssetGeneralInfoQueryOptions(username));
|
|
3808
3824
|
} else if (asset === "ETH") {
|
|
3809
|
-
|
|
3825
|
+
assetInfo = await fetchQuery(getEthAssetGeneralInfoQueryOptions(username));
|
|
3810
3826
|
} else if (asset === "SOL") {
|
|
3811
|
-
|
|
3827
|
+
assetInfo = await fetchQuery(getSolAssetGeneralInfoQueryOptions(username));
|
|
3812
3828
|
} else if (asset === "TON") {
|
|
3813
|
-
|
|
3829
|
+
assetInfo = await fetchQuery(getTonAssetGeneralInfoQueryOptions(username));
|
|
3814
3830
|
} else if (asset === "TRX") {
|
|
3815
|
-
|
|
3816
|
-
}
|
|
3817
|
-
const balances = await queryClient.ensureQueryData(
|
|
3818
|
-
getHiveEngineTokensBalancesQueryOptions(username)
|
|
3819
|
-
);
|
|
3820
|
-
if (balances.some((balance) => balance.symbol === asset)) {
|
|
3821
|
-
return await fetchQuery(
|
|
3822
|
-
getHiveEngineTokenGeneralInfoQueryOptions(username, asset)
|
|
3823
|
-
);
|
|
3831
|
+
assetInfo = await fetchQuery(getTronAssetGeneralInfoQueryOptions(username));
|
|
3824
3832
|
} else {
|
|
3825
|
-
|
|
3826
|
-
|
|
3833
|
+
const balances = await queryClient.ensureQueryData(
|
|
3834
|
+
getHiveEngineTokensBalancesQueryOptions(username)
|
|
3827
3835
|
);
|
|
3836
|
+
if (balances.some((balance) => balance.symbol === asset)) {
|
|
3837
|
+
assetInfo = await fetchQuery(
|
|
3838
|
+
getHiveEngineTokenGeneralInfoQueryOptions(username, asset)
|
|
3839
|
+
);
|
|
3840
|
+
} else {
|
|
3841
|
+
throw new Error(
|
|
3842
|
+
"[SDK][Wallets] \u2013 has requested unrecognized asset info"
|
|
3843
|
+
);
|
|
3844
|
+
}
|
|
3828
3845
|
}
|
|
3846
|
+
return await convertPriceToUserCurrency(assetInfo);
|
|
3829
3847
|
}
|
|
3830
3848
|
});
|
|
3831
3849
|
}
|
|
@@ -3839,9 +3857,9 @@ function hasNonZeroSavingsBalance(parts) {
|
|
|
3839
3857
|
)
|
|
3840
3858
|
);
|
|
3841
3859
|
}
|
|
3842
|
-
function getTokenOperationsQueryOptions(token, username, isForOwner = false) {
|
|
3860
|
+
function getTokenOperationsQueryOptions(token, username, isForOwner = false, currency = "usd") {
|
|
3843
3861
|
return queryOptions({
|
|
3844
|
-
queryKey: ["wallets", "token-operations", token, username, isForOwner],
|
|
3862
|
+
queryKey: ["wallets", "token-operations", token, username, isForOwner, currency],
|
|
3845
3863
|
queryFn: async () => {
|
|
3846
3864
|
const queryClient = getQueryClient();
|
|
3847
3865
|
const normalizedToken = token.toUpperCase();
|
|
@@ -3850,7 +3868,7 @@ function getTokenOperationsQueryOptions(token, username, isForOwner = false) {
|
|
|
3850
3868
|
}
|
|
3851
3869
|
try {
|
|
3852
3870
|
const portfolio = await queryClient.fetchQuery(
|
|
3853
|
-
getVisionPortfolioQueryOptions(username)
|
|
3871
|
+
getVisionPortfolioQueryOptions(username, currency)
|
|
3854
3872
|
);
|
|
3855
3873
|
const assetEntry = portfolio.wallets.find(
|
|
3856
3874
|
(assetItem) => assetItem.info.name === normalizedToken
|
|
@@ -4302,7 +4320,7 @@ function useWalletOperation(username, asset, operation, auth) {
|
|
|
4302
4320
|
});
|
|
4303
4321
|
setTimeout(
|
|
4304
4322
|
() => getQueryClient().invalidateQueries({
|
|
4305
|
-
queryKey:
|
|
4323
|
+
queryKey: ["ecency-wallets", "portfolio", "v2", username]
|
|
4306
4324
|
}),
|
|
4307
4325
|
4e3
|
|
4308
4326
|
);
|