@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.cjs
CHANGED
|
@@ -1502,7 +1502,7 @@ function useClaimRewards(username, auth, onSuccess) {
|
|
|
1502
1502
|
queryKey: sdk.getAccountFullQueryOptions(username).queryKey
|
|
1503
1503
|
});
|
|
1504
1504
|
queryClient.invalidateQueries({
|
|
1505
|
-
queryKey:
|
|
1505
|
+
queryKey: ["ecency-wallets", "portfolio", "v2", username]
|
|
1506
1506
|
});
|
|
1507
1507
|
queryClient.invalidateQueries({
|
|
1508
1508
|
queryKey: getHiveAssetGeneralInfoQueryOptions(username).queryKey
|
|
@@ -1523,7 +1523,7 @@ function useClaimRewards(username, auth, onSuccess) {
|
|
|
1523
1523
|
queryKey: sdk.getAccountFullQueryOptions(username).queryKey
|
|
1524
1524
|
});
|
|
1525
1525
|
queryClient.invalidateQueries({
|
|
1526
|
-
queryKey:
|
|
1526
|
+
queryKey: ["ecency-wallets", "portfolio", "v2", username]
|
|
1527
1527
|
});
|
|
1528
1528
|
queryClient.invalidateQueries({
|
|
1529
1529
|
queryKey: getHiveAssetGeneralInfoQueryOptions(username).queryKey
|
|
@@ -3150,9 +3150,7 @@ function parseToken(rawToken) {
|
|
|
3150
3150
|
}
|
|
3151
3151
|
const normalizedSymbol = symbol.toUpperCase();
|
|
3152
3152
|
const title = normalizeString(token.title) ?? normalizeString(token.display) ?? normalizeString(token.label) ?? normalizeString(token.friendlyName) ?? normalizeString(token.name) ?? normalizedSymbol;
|
|
3153
|
-
const price = normalizeNumber(token.fiatRate) ??
|
|
3154
|
-
token.metrics?.priceUsd
|
|
3155
|
-
) ?? 0;
|
|
3153
|
+
const price = normalizeNumber(token.fiatRate) ?? 0;
|
|
3156
3154
|
const apr = normalizeApr(token.apr) ?? normalizeApr(token.aprPercent) ?? normalizeApr(token.metrics?.apr) ?? normalizeApr(
|
|
3157
3155
|
token.metrics?.aprPercent
|
|
3158
3156
|
);
|
|
@@ -3229,14 +3227,15 @@ function resolveUsername(payload) {
|
|
|
3229
3227
|
const record = payload;
|
|
3230
3228
|
return normalizeString(record.username) ?? normalizeString(record.name) ?? normalizeString(record.account);
|
|
3231
3229
|
}
|
|
3232
|
-
function getVisionPortfolioQueryOptions(username) {
|
|
3230
|
+
function getVisionPortfolioQueryOptions(username, currency = "usd") {
|
|
3233
3231
|
return reactQuery.queryOptions({
|
|
3234
3232
|
queryKey: [
|
|
3235
3233
|
"ecency-wallets",
|
|
3236
3234
|
"portfolio",
|
|
3237
3235
|
"v2",
|
|
3238
3236
|
username,
|
|
3239
|
-
"only-enabled"
|
|
3237
|
+
"only-enabled",
|
|
3238
|
+
currency
|
|
3240
3239
|
],
|
|
3241
3240
|
enabled: Boolean(username),
|
|
3242
3241
|
staleTime: 6e4,
|
|
@@ -3257,7 +3256,7 @@ function getVisionPortfolioQueryOptions(username) {
|
|
|
3257
3256
|
Accept: "application/json",
|
|
3258
3257
|
"Content-Type": "application/json"
|
|
3259
3258
|
},
|
|
3260
|
-
body: JSON.stringify({ username, onlyEnabled: true })
|
|
3259
|
+
body: JSON.stringify({ username, onlyEnabled: true, currency })
|
|
3261
3260
|
});
|
|
3262
3261
|
if (!response.ok) {
|
|
3263
3262
|
throw new Error(
|
|
@@ -3274,7 +3273,7 @@ function getVisionPortfolioQueryOptions(username) {
|
|
|
3274
3273
|
return {
|
|
3275
3274
|
username: resolveUsername(payload) ?? username,
|
|
3276
3275
|
currency: normalizeString(
|
|
3277
|
-
payload?.currency
|
|
3276
|
+
payload?.fiatCurrency ?? payload?.currency
|
|
3278
3277
|
)?.toUpperCase(),
|
|
3279
3278
|
wallets: tokens
|
|
3280
3279
|
};
|
|
@@ -3300,12 +3299,12 @@ var BASIC_TOKENS = [
|
|
|
3300
3299
|
"HP" /* HivePower */,
|
|
3301
3300
|
"HBD" /* HiveDollar */
|
|
3302
3301
|
];
|
|
3303
|
-
function getAccountWalletListQueryOptions(username) {
|
|
3302
|
+
function getAccountWalletListQueryOptions(username, currency = "usd") {
|
|
3304
3303
|
return reactQuery.queryOptions({
|
|
3305
|
-
queryKey: ["ecency-wallets", "list", username],
|
|
3304
|
+
queryKey: ["ecency-wallets", "list", username, currency],
|
|
3306
3305
|
enabled: !!username,
|
|
3307
3306
|
queryFn: async () => {
|
|
3308
|
-
const portfolioQuery = getVisionPortfolioQueryOptions(username);
|
|
3307
|
+
const portfolioQuery = getVisionPortfolioQueryOptions(username, currency);
|
|
3309
3308
|
const queryClient = sdk.getQueryClient();
|
|
3310
3309
|
const accountQuery = sdk.getAccountFullQueryOptions(username);
|
|
3311
3310
|
let account;
|
|
@@ -3783,6 +3782,7 @@ function getTronAssetGeneralInfoQueryOptions(username) {
|
|
|
3783
3782
|
// src/modules/wallets/queries/get-account-wallet-asset-info-query-options.ts
|
|
3784
3783
|
function getAccountWalletAssetInfoQueryOptions(username, asset, options2 = { refetch: false }) {
|
|
3785
3784
|
const queryClient = sdk.getQueryClient();
|
|
3785
|
+
const currency = options2.currency ?? "usd";
|
|
3786
3786
|
const fetchQuery = async (queryOptions43) => {
|
|
3787
3787
|
if (options2.refetch) {
|
|
3788
3788
|
await queryClient.fetchQuery(queryOptions43);
|
|
@@ -3791,7 +3791,22 @@ function getAccountWalletAssetInfoQueryOptions(username, asset, options2 = { ref
|
|
|
3791
3791
|
}
|
|
3792
3792
|
return queryClient.getQueryData(queryOptions43.queryKey);
|
|
3793
3793
|
};
|
|
3794
|
-
const
|
|
3794
|
+
const convertPriceToUserCurrency = async (assetInfo) => {
|
|
3795
|
+
if (!assetInfo || currency === "usd") {
|
|
3796
|
+
return assetInfo;
|
|
3797
|
+
}
|
|
3798
|
+
try {
|
|
3799
|
+
const conversionRate = await sdk.getCurrencyRate(currency);
|
|
3800
|
+
return {
|
|
3801
|
+
...assetInfo,
|
|
3802
|
+
price: assetInfo.price * conversionRate
|
|
3803
|
+
};
|
|
3804
|
+
} catch (error) {
|
|
3805
|
+
console.warn(`Failed to convert price from USD to ${currency}:`, error);
|
|
3806
|
+
return assetInfo;
|
|
3807
|
+
}
|
|
3808
|
+
};
|
|
3809
|
+
const portfolioQuery = getVisionPortfolioQueryOptions(username, currency);
|
|
3795
3810
|
const getPortfolioAssetInfo = async () => {
|
|
3796
3811
|
try {
|
|
3797
3812
|
const portfolio = await queryClient.fetchQuery(portfolioQuery);
|
|
@@ -3804,53 +3819,56 @@ function getAccountWalletAssetInfoQueryOptions(username, asset, options2 = { ref
|
|
|
3804
3819
|
}
|
|
3805
3820
|
};
|
|
3806
3821
|
return reactQuery.queryOptions({
|
|
3807
|
-
queryKey: ["ecency-wallets", "asset-info", username, asset],
|
|
3822
|
+
queryKey: ["ecency-wallets", "asset-info", username, asset, currency],
|
|
3808
3823
|
queryFn: async () => {
|
|
3809
3824
|
const portfolioAssetInfo = await getPortfolioAssetInfo();
|
|
3810
|
-
if (portfolioAssetInfo) {
|
|
3825
|
+
if (portfolioAssetInfo && portfolioAssetInfo.price > 0) {
|
|
3811
3826
|
return portfolioAssetInfo;
|
|
3812
3827
|
}
|
|
3828
|
+
let assetInfo;
|
|
3813
3829
|
if (asset === "HIVE") {
|
|
3814
|
-
|
|
3830
|
+
assetInfo = await fetchQuery(getHiveAssetGeneralInfoQueryOptions(username));
|
|
3815
3831
|
} else if (asset === "HP") {
|
|
3816
|
-
|
|
3832
|
+
assetInfo = await fetchQuery(getHivePowerAssetGeneralInfoQueryOptions(username));
|
|
3817
3833
|
} else if (asset === "HBD") {
|
|
3818
|
-
|
|
3834
|
+
assetInfo = await fetchQuery(getHbdAssetGeneralInfoQueryOptions(username));
|
|
3819
3835
|
} else if (asset === "SPK") {
|
|
3820
|
-
|
|
3836
|
+
assetInfo = await fetchQuery(getSpkAssetGeneralInfoQueryOptions(username));
|
|
3821
3837
|
} else if (asset === "LARYNX") {
|
|
3822
|
-
|
|
3838
|
+
assetInfo = await fetchQuery(getLarynxAssetGeneralInfoQueryOptions(username));
|
|
3823
3839
|
} else if (asset === "LP") {
|
|
3824
|
-
|
|
3840
|
+
assetInfo = await fetchQuery(getLarynxPowerAssetGeneralInfoQueryOptions(username));
|
|
3825
3841
|
} else if (asset === "POINTS") {
|
|
3826
|
-
|
|
3842
|
+
assetInfo = await fetchQuery(getPointsAssetGeneralInfoQueryOptions(username));
|
|
3827
3843
|
} else if (asset === "APT") {
|
|
3828
|
-
|
|
3844
|
+
assetInfo = await fetchQuery(getAptAssetGeneralInfoQueryOptions(username));
|
|
3829
3845
|
} else if (asset === "BNB") {
|
|
3830
|
-
|
|
3846
|
+
assetInfo = await fetchQuery(getBnbAssetGeneralInfoQueryOptions(username));
|
|
3831
3847
|
} else if (asset === "BTC") {
|
|
3832
|
-
|
|
3848
|
+
assetInfo = await fetchQuery(getBtcAssetGeneralInfoQueryOptions(username));
|
|
3833
3849
|
} else if (asset === "ETH") {
|
|
3834
|
-
|
|
3850
|
+
assetInfo = await fetchQuery(getEthAssetGeneralInfoQueryOptions(username));
|
|
3835
3851
|
} else if (asset === "SOL") {
|
|
3836
|
-
|
|
3852
|
+
assetInfo = await fetchQuery(getSolAssetGeneralInfoQueryOptions(username));
|
|
3837
3853
|
} else if (asset === "TON") {
|
|
3838
|
-
|
|
3854
|
+
assetInfo = await fetchQuery(getTonAssetGeneralInfoQueryOptions(username));
|
|
3839
3855
|
} else if (asset === "TRX") {
|
|
3840
|
-
|
|
3841
|
-
}
|
|
3842
|
-
const balances = await queryClient.ensureQueryData(
|
|
3843
|
-
getHiveEngineTokensBalancesQueryOptions(username)
|
|
3844
|
-
);
|
|
3845
|
-
if (balances.some((balance) => balance.symbol === asset)) {
|
|
3846
|
-
return await fetchQuery(
|
|
3847
|
-
getHiveEngineTokenGeneralInfoQueryOptions(username, asset)
|
|
3848
|
-
);
|
|
3856
|
+
assetInfo = await fetchQuery(getTronAssetGeneralInfoQueryOptions(username));
|
|
3849
3857
|
} else {
|
|
3850
|
-
|
|
3851
|
-
|
|
3858
|
+
const balances = await queryClient.ensureQueryData(
|
|
3859
|
+
getHiveEngineTokensBalancesQueryOptions(username)
|
|
3852
3860
|
);
|
|
3861
|
+
if (balances.some((balance) => balance.symbol === asset)) {
|
|
3862
|
+
assetInfo = await fetchQuery(
|
|
3863
|
+
getHiveEngineTokenGeneralInfoQueryOptions(username, asset)
|
|
3864
|
+
);
|
|
3865
|
+
} else {
|
|
3866
|
+
throw new Error(
|
|
3867
|
+
"[SDK][Wallets] \u2013 has requested unrecognized asset info"
|
|
3868
|
+
);
|
|
3869
|
+
}
|
|
3853
3870
|
}
|
|
3871
|
+
return await convertPriceToUserCurrency(assetInfo);
|
|
3854
3872
|
}
|
|
3855
3873
|
});
|
|
3856
3874
|
}
|
|
@@ -3864,9 +3882,9 @@ function hasNonZeroSavingsBalance(parts) {
|
|
|
3864
3882
|
)
|
|
3865
3883
|
);
|
|
3866
3884
|
}
|
|
3867
|
-
function getTokenOperationsQueryOptions(token, username, isForOwner = false) {
|
|
3885
|
+
function getTokenOperationsQueryOptions(token, username, isForOwner = false, currency = "usd") {
|
|
3868
3886
|
return reactQuery.queryOptions({
|
|
3869
|
-
queryKey: ["wallets", "token-operations", token, username, isForOwner],
|
|
3887
|
+
queryKey: ["wallets", "token-operations", token, username, isForOwner, currency],
|
|
3870
3888
|
queryFn: async () => {
|
|
3871
3889
|
const queryClient = sdk.getQueryClient();
|
|
3872
3890
|
const normalizedToken = token.toUpperCase();
|
|
@@ -3875,7 +3893,7 @@ function getTokenOperationsQueryOptions(token, username, isForOwner = false) {
|
|
|
3875
3893
|
}
|
|
3876
3894
|
try {
|
|
3877
3895
|
const portfolio = await queryClient.fetchQuery(
|
|
3878
|
-
getVisionPortfolioQueryOptions(username)
|
|
3896
|
+
getVisionPortfolioQueryOptions(username, currency)
|
|
3879
3897
|
);
|
|
3880
3898
|
const assetEntry = portfolio.wallets.find(
|
|
3881
3899
|
(assetItem) => assetItem.info.name === normalizedToken
|
|
@@ -4327,7 +4345,7 @@ function useWalletOperation(username, asset, operation, auth) {
|
|
|
4327
4345
|
});
|
|
4328
4346
|
setTimeout(
|
|
4329
4347
|
() => sdk.getQueryClient().invalidateQueries({
|
|
4330
|
-
queryKey:
|
|
4348
|
+
queryKey: ["ecency-wallets", "portfolio", "v2", username]
|
|
4331
4349
|
}),
|
|
4332
4350
|
4e3
|
|
4333
4351
|
);
|