@ecency/wallets 1.5.19 → 1.5.21

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.
@@ -1,6 +1,6 @@
1
1
  import * as _tanstack_react_query from '@tanstack/react-query';
2
2
  import { UseMutationOptions, useMutation } from '@tanstack/react-query';
3
- import { AuthContext, useBroadcastMutation } from '@ecency/sdk';
3
+ import { AuthContext, useBroadcastMutation, PortfolioWalletItem, PortfolioResponse } from '@ecency/sdk';
4
4
  export { getHiveEngineMetrics, getHiveEngineOpenOrders, getHiveEngineOrderBook, getHiveEngineTradeHistory } from '@ecency/sdk';
5
5
  import { BaseWallet, SignTxParams } from '@okxweb3/coin-base';
6
6
  import { OperationName, VirtualOperationName, SMTAsset, PrivateKey, Operation, TransactionConfirmation, Client } from '@hiveio/dhive';
@@ -1824,47 +1824,17 @@ declare function getTokenOperationsQueryOptions(token: string, username: string,
1824
1824
 
1825
1825
  declare function useWalletsCacheQuery(username?: string): _tanstack_react_query.DefinedUseQueryResult<Map<EcencyWalletCurrency, EcencyTokenMetadata>, Error>;
1826
1826
 
1827
- type PortfolioLayer = "points" | "hive" | "chain" | "spk" | "engine";
1828
- interface TokenAction {
1829
- id: string;
1830
- [key: string]: unknown;
1831
- }
1832
- interface VisionPortfolioWalletItem {
1833
- name: string;
1834
- symbol: string;
1835
- layer: PortfolioLayer;
1836
- balance: number;
1837
- fiatRate: number;
1838
- currency: string;
1839
- precision: number;
1840
- address?: string;
1841
- error?: string;
1842
- pendingRewards?: number;
1843
- pendingRewardsFiat?: number;
1844
- liquid?: number;
1845
- liquidFiat?: number;
1846
- savings?: number;
1847
- savingsFiat?: number;
1848
- staked?: number;
1849
- stakedFiat?: number;
1850
- iconUrl?: string;
1851
- actions?: TokenAction[];
1852
- extraData?: Array<{
1853
- dataKey: string;
1854
- value: any;
1855
- }>;
1856
- apr?: number;
1857
- }
1858
- interface VisionPortfolioResponse {
1859
- username: string;
1860
- currency?: string;
1861
- wallets: VisionPortfolioWalletItem[];
1862
- }
1863
- declare function getVisionPortfolioQueryOptions(username: string, currency?: string): _tanstack_react_query.OmitKeyof<_tanstack_react_query.UseQueryOptions<VisionPortfolioResponse, Error, VisionPortfolioResponse, string[]>, "queryFn"> & {
1864
- queryFn?: _tanstack_react_query.QueryFunction<VisionPortfolioResponse, string[], never> | undefined;
1827
+ type VisionPortfolioWalletItem = PortfolioWalletItem;
1828
+ type VisionPortfolioResponse = PortfolioResponse;
1829
+ /**
1830
+ * @deprecated Use getPortfolioQueryOptions from @ecency/sdk instead
1831
+ * This wrapper is maintained for backwards compatibility
1832
+ */
1833
+ declare function getVisionPortfolioQueryOptions(username: string, currency?: string): _tanstack_react_query.OmitKeyof<_tanstack_react_query.UseQueryOptions<PortfolioResponse, Error, PortfolioResponse, string[]>, "queryFn"> & {
1834
+ queryFn?: _tanstack_react_query.QueryFunction<PortfolioResponse, string[], never> | undefined;
1865
1835
  } & {
1866
1836
  queryKey: string[] & {
1867
- [dataTagSymbol]: VisionPortfolioResponse;
1837
+ [dataTagSymbol]: PortfolioResponse;
1868
1838
  [dataTagErrorSymbol]: Error;
1869
1839
  };
1870
1840
  };
@@ -1,4 +1,4 @@
1
- import { CONFIG, getAccountFullQueryOptions, getQueryClient, getDynamicPropsQueryOptions, useBroadcastMutation, getSpkMarkets, getSpkWallet, getHiveEngineTokensMarket, getHiveEngineTokensBalances, getHiveEngineTokensMetadata, getHiveEngineTokenTransactions, getHiveEngineTokenMetrics, getHiveEngineUnclaimedRewards, EcencyAnalytics, useAccountUpdate, getCurrencyRate } from '@ecency/sdk';
1
+ import { CONFIG, getAccountFullQueryOptions, getQueryClient, getDynamicPropsQueryOptions, useBroadcastMutation, getSpkMarkets, getSpkWallet, getHiveEngineTokensMarket, getHiveEngineTokensBalances, getHiveEngineTokensMetadata, getHiveEngineTokenTransactions, getHiveEngineTokenMetrics, getHiveEngineUnclaimedRewards, EcencyAnalytics, getPortfolioQueryOptions, 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';
@@ -38,10 +38,23 @@ if (typeof globalLike._scrypt_bsv !== "undefined") {
38
38
  globalLike._scrypt_bsv = void 0;
39
39
  }
40
40
  }
41
+ if (typeof globalLike._bitcore !== "undefined") {
42
+ if (typeof globalLike._bitcore === "object") {
43
+ globalLike.__bitcorePreviousVersion = globalLike._bitcore;
44
+ }
45
+ try {
46
+ delete globalLike._bitcore;
47
+ } catch {
48
+ globalLike._bitcore = void 0;
49
+ }
50
+ }
41
51
  function rememberScryptBsvVersion() {
42
52
  if (typeof globalLike._scrypt_bsv === "string") {
43
53
  globalLike.__scryptBsvPreviousVersion = globalLike._scrypt_bsv;
44
54
  }
55
+ if (typeof globalLike._bitcore === "object") {
56
+ globalLike.__bitcorePreviousVersion = globalLike._bitcore;
57
+ }
45
58
  }
46
59
 
47
60
  // src/modules/wallets/enums/ecency-wallet-currency.ts
@@ -2962,162 +2975,8 @@ function getAllTokensListQueryOptions(username) {
2962
2975
  }
2963
2976
  });
2964
2977
  }
2965
- function normalizeString(value) {
2966
- if (typeof value === "string") {
2967
- const trimmed = value.trim();
2968
- return trimmed.length > 0 ? trimmed : void 0;
2969
- }
2970
- return void 0;
2971
- }
2972
- function normalizeNumber(value) {
2973
- if (typeof value === "number" && Number.isFinite(value)) {
2974
- return value;
2975
- }
2976
- if (typeof value === "string") {
2977
- const trimmed = value.trim();
2978
- if (!trimmed) {
2979
- return void 0;
2980
- }
2981
- const direct = Number.parseFloat(trimmed);
2982
- if (Number.isFinite(direct)) {
2983
- return direct;
2984
- }
2985
- const sanitized = trimmed.replace(/,/g, "");
2986
- const match = sanitized.match(/[-+]?\d+(?:\.\d+)?/);
2987
- if (match) {
2988
- const parsed = Number.parseFloat(match[0]);
2989
- if (Number.isFinite(parsed)) {
2990
- return parsed;
2991
- }
2992
- }
2993
- }
2994
- return void 0;
2995
- }
2996
- function parseToken(rawToken) {
2997
- if (!rawToken || typeof rawToken !== "object") {
2998
- return void 0;
2999
- }
3000
- const token = rawToken;
3001
- return {
3002
- name: normalizeString(token.name) ?? "",
3003
- symbol: normalizeString(token.symbol) ?? "",
3004
- layer: normalizeString(token.layer) ?? "hive",
3005
- balance: normalizeNumber(token.balance) ?? 0,
3006
- fiatRate: normalizeNumber(token.fiatRate) ?? 0,
3007
- currency: normalizeString(token.currency) ?? "usd",
3008
- precision: normalizeNumber(token.precision) ?? 3,
3009
- address: normalizeString(token.address),
3010
- error: normalizeString(token.error),
3011
- pendingRewards: normalizeNumber(token.pendingRewards),
3012
- pendingRewardsFiat: normalizeNumber(token.pendingRewardsFiat),
3013
- liquid: normalizeNumber(token.liquid),
3014
- liquidFiat: normalizeNumber(token.liquidFiat),
3015
- savings: normalizeNumber(token.savings),
3016
- savingsFiat: normalizeNumber(token.savingsFiat),
3017
- staked: normalizeNumber(token.staked),
3018
- stakedFiat: normalizeNumber(token.stakedFiat),
3019
- iconUrl: normalizeString(token.iconUrl),
3020
- actions: token.actions ?? [],
3021
- extraData: token.extraData ?? [],
3022
- apr: normalizeNumber(token.apr)
3023
- };
3024
- }
3025
- function extractTokens(payload) {
3026
- if (!payload || typeof payload !== "object") {
3027
- return [];
3028
- }
3029
- const containers = [payload];
3030
- const record = payload;
3031
- if (record.data && typeof record.data === "object") {
3032
- containers.push(record.data);
3033
- }
3034
- if (record.result && typeof record.result === "object") {
3035
- containers.push(record.result);
3036
- }
3037
- if (record.portfolio && typeof record.portfolio === "object") {
3038
- containers.push(record.portfolio);
3039
- }
3040
- for (const container of containers) {
3041
- if (Array.isArray(container)) {
3042
- return container;
3043
- }
3044
- if (container && typeof container === "object") {
3045
- for (const key of [
3046
- "wallets",
3047
- "tokens",
3048
- "assets",
3049
- "items",
3050
- "portfolio",
3051
- "balances"
3052
- ]) {
3053
- const value = container[key];
3054
- if (Array.isArray(value)) {
3055
- return value;
3056
- }
3057
- }
3058
- }
3059
- }
3060
- return [];
3061
- }
3062
- function resolveUsername(payload) {
3063
- if (!payload || typeof payload !== "object") {
3064
- return void 0;
3065
- }
3066
- const record = payload;
3067
- return normalizeString(record.username) ?? normalizeString(record.name) ?? normalizeString(record.account);
3068
- }
3069
2978
  function getVisionPortfolioQueryOptions(username, currency = "usd") {
3070
- return queryOptions({
3071
- queryKey: [
3072
- "ecency-wallets",
3073
- "portfolio",
3074
- "v2",
3075
- username,
3076
- "only-enabled",
3077
- currency
3078
- ],
3079
- enabled: Boolean(username),
3080
- staleTime: 6e4,
3081
- refetchInterval: 12e4,
3082
- queryFn: async () => {
3083
- if (!username) {
3084
- throw new Error("[SDK][Wallets] \u2013 username is required");
3085
- }
3086
- if (CONFIG.privateApiHost === void 0 || CONFIG.privateApiHost === null) {
3087
- throw new Error(
3088
- "[SDK][Wallets] \u2013 privateApiHost isn't configured for portfolio"
3089
- );
3090
- }
3091
- const endpoint = `${CONFIG.privateApiHost}/wallet-api/portfolio-v2`;
3092
- const response = await fetch(endpoint, {
3093
- method: "POST",
3094
- headers: {
3095
- Accept: "application/json",
3096
- "Content-Type": "application/json"
3097
- },
3098
- body: JSON.stringify({ username, onlyEnabled: true, currency })
3099
- });
3100
- if (!response.ok) {
3101
- throw new Error(
3102
- `[SDK][Wallets] \u2013 Vision portfolio request failed(${response.status})`
3103
- );
3104
- }
3105
- const payload = await response.json();
3106
- const tokens = extractTokens(payload).map((item) => parseToken(item)).filter((item) => Boolean(item));
3107
- if (!tokens.length) {
3108
- throw new Error(
3109
- "[SDK][Wallets] \u2013 Vision portfolio payload contained no tokens"
3110
- );
3111
- }
3112
- return {
3113
- username: resolveUsername(payload) ?? username,
3114
- currency: normalizeString(
3115
- payload?.fiatCurrency ?? payload?.currency
3116
- )?.toUpperCase(),
3117
- wallets: tokens
3118
- };
3119
- }
3120
- });
2979
+ return getPortfolioQueryOptions(username, currency, true);
3121
2980
  }
3122
2981
 
3123
2982
  // src/modules/wallets/queries/use-get-account-wallet-list-query.ts
@@ -3622,13 +3481,13 @@ function getTronAssetGeneralInfoQueryOptions(username) {
3622
3481
  function getAccountWalletAssetInfoQueryOptions(username, asset, options2 = { refetch: false }) {
3623
3482
  const queryClient = getQueryClient();
3624
3483
  const currency = options2.currency ?? "usd";
3625
- const fetchQuery = async (queryOptions43) => {
3484
+ const fetchQuery = async (queryOptions42) => {
3626
3485
  if (options2.refetch) {
3627
- await queryClient.fetchQuery(queryOptions43);
3486
+ await queryClient.fetchQuery(queryOptions42);
3628
3487
  } else {
3629
- await queryClient.prefetchQuery(queryOptions43);
3488
+ await queryClient.prefetchQuery(queryOptions42);
3630
3489
  }
3631
- return queryClient.getQueryData(queryOptions43.queryKey);
3490
+ return queryClient.getQueryData(queryOptions42.queryKey);
3632
3491
  };
3633
3492
  const convertPriceToUserCurrency = async (assetInfo) => {
3634
3493
  if (!assetInfo || currency === "usd") {