@ecency/wallets 1.5.20 → 1.5.23

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';
@@ -67,7 +67,7 @@ interface AccountPointsResponse {
67
67
  *
68
68
  * Keep attention: this mutation doesn't save wallet to somewhere in a server
69
69
  */
70
- declare function useWalletCreate(username: string, currency: EcencyWalletCurrency): {
70
+ declare function useWalletCreate(username: string, currency: EcencyWalletCurrency, importedSeed?: string): {
71
71
  createWallet: _tanstack_react_query.UseMutationResult<EcencyTokenMetadata, Error, void, unknown>;
72
72
  importWallet: () => void;
73
73
  };
@@ -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';
@@ -2975,162 +2975,8 @@ function getAllTokensListQueryOptions(username) {
2975
2975
  }
2976
2976
  });
2977
2977
  }
2978
- function normalizeString(value) {
2979
- if (typeof value === "string") {
2980
- const trimmed = value.trim();
2981
- return trimmed.length > 0 ? trimmed : void 0;
2982
- }
2983
- return void 0;
2984
- }
2985
- function normalizeNumber(value) {
2986
- if (typeof value === "number" && Number.isFinite(value)) {
2987
- return value;
2988
- }
2989
- if (typeof value === "string") {
2990
- const trimmed = value.trim();
2991
- if (!trimmed) {
2992
- return void 0;
2993
- }
2994
- const direct = Number.parseFloat(trimmed);
2995
- if (Number.isFinite(direct)) {
2996
- return direct;
2997
- }
2998
- const sanitized = trimmed.replace(/,/g, "");
2999
- const match = sanitized.match(/[-+]?\d+(?:\.\d+)?/);
3000
- if (match) {
3001
- const parsed = Number.parseFloat(match[0]);
3002
- if (Number.isFinite(parsed)) {
3003
- return parsed;
3004
- }
3005
- }
3006
- }
3007
- return void 0;
3008
- }
3009
- function parseToken(rawToken) {
3010
- if (!rawToken || typeof rawToken !== "object") {
3011
- return void 0;
3012
- }
3013
- const token = rawToken;
3014
- return {
3015
- name: normalizeString(token.name) ?? "",
3016
- symbol: normalizeString(token.symbol) ?? "",
3017
- layer: normalizeString(token.layer) ?? "hive",
3018
- balance: normalizeNumber(token.balance) ?? 0,
3019
- fiatRate: normalizeNumber(token.fiatRate) ?? 0,
3020
- currency: normalizeString(token.currency) ?? "usd",
3021
- precision: normalizeNumber(token.precision) ?? 3,
3022
- address: normalizeString(token.address),
3023
- error: normalizeString(token.error),
3024
- pendingRewards: normalizeNumber(token.pendingRewards),
3025
- pendingRewardsFiat: normalizeNumber(token.pendingRewardsFiat),
3026
- liquid: normalizeNumber(token.liquid),
3027
- liquidFiat: normalizeNumber(token.liquidFiat),
3028
- savings: normalizeNumber(token.savings),
3029
- savingsFiat: normalizeNumber(token.savingsFiat),
3030
- staked: normalizeNumber(token.staked),
3031
- stakedFiat: normalizeNumber(token.stakedFiat),
3032
- iconUrl: normalizeString(token.iconUrl),
3033
- actions: token.actions ?? [],
3034
- extraData: token.extraData ?? [],
3035
- apr: normalizeNumber(token.apr)
3036
- };
3037
- }
3038
- function extractTokens(payload) {
3039
- if (!payload || typeof payload !== "object") {
3040
- return [];
3041
- }
3042
- const containers = [payload];
3043
- const record = payload;
3044
- if (record.data && typeof record.data === "object") {
3045
- containers.push(record.data);
3046
- }
3047
- if (record.result && typeof record.result === "object") {
3048
- containers.push(record.result);
3049
- }
3050
- if (record.portfolio && typeof record.portfolio === "object") {
3051
- containers.push(record.portfolio);
3052
- }
3053
- for (const container of containers) {
3054
- if (Array.isArray(container)) {
3055
- return container;
3056
- }
3057
- if (container && typeof container === "object") {
3058
- for (const key of [
3059
- "wallets",
3060
- "tokens",
3061
- "assets",
3062
- "items",
3063
- "portfolio",
3064
- "balances"
3065
- ]) {
3066
- const value = container[key];
3067
- if (Array.isArray(value)) {
3068
- return value;
3069
- }
3070
- }
3071
- }
3072
- }
3073
- return [];
3074
- }
3075
- function resolveUsername(payload) {
3076
- if (!payload || typeof payload !== "object") {
3077
- return void 0;
3078
- }
3079
- const record = payload;
3080
- return normalizeString(record.username) ?? normalizeString(record.name) ?? normalizeString(record.account);
3081
- }
3082
2978
  function getVisionPortfolioQueryOptions(username, currency = "usd") {
3083
- return queryOptions({
3084
- queryKey: [
3085
- "ecency-wallets",
3086
- "portfolio",
3087
- "v2",
3088
- username,
3089
- "only-enabled",
3090
- currency
3091
- ],
3092
- enabled: Boolean(username),
3093
- staleTime: 6e4,
3094
- refetchInterval: 12e4,
3095
- queryFn: async () => {
3096
- if (!username) {
3097
- throw new Error("[SDK][Wallets] \u2013 username is required");
3098
- }
3099
- if (CONFIG.privateApiHost === void 0 || CONFIG.privateApiHost === null) {
3100
- throw new Error(
3101
- "[SDK][Wallets] \u2013 privateApiHost isn't configured for portfolio"
3102
- );
3103
- }
3104
- const endpoint = `${CONFIG.privateApiHost}/wallet-api/portfolio-v2`;
3105
- const response = await fetch(endpoint, {
3106
- method: "POST",
3107
- headers: {
3108
- Accept: "application/json",
3109
- "Content-Type": "application/json"
3110
- },
3111
- body: JSON.stringify({ username, onlyEnabled: true, currency })
3112
- });
3113
- if (!response.ok) {
3114
- throw new Error(
3115
- `[SDK][Wallets] \u2013 Vision portfolio request failed(${response.status})`
3116
- );
3117
- }
3118
- const payload = await response.json();
3119
- const tokens = extractTokens(payload).map((item) => parseToken(item)).filter((item) => Boolean(item));
3120
- if (!tokens.length) {
3121
- throw new Error(
3122
- "[SDK][Wallets] \u2013 Vision portfolio payload contained no tokens"
3123
- );
3124
- }
3125
- return {
3126
- username: resolveUsername(payload) ?? username,
3127
- currency: normalizeString(
3128
- payload?.fiatCurrency ?? payload?.currency
3129
- )?.toUpperCase(),
3130
- wallets: tokens
3131
- };
3132
- }
3133
- });
2979
+ return getPortfolioQueryOptions(username, currency, true);
3134
2980
  }
3135
2981
 
3136
2982
  // src/modules/wallets/queries/use-get-account-wallet-list-query.ts
@@ -3635,13 +3481,13 @@ function getTronAssetGeneralInfoQueryOptions(username) {
3635
3481
  function getAccountWalletAssetInfoQueryOptions(username, asset, options2 = { refetch: false }) {
3636
3482
  const queryClient = getQueryClient();
3637
3483
  const currency = options2.currency ?? "usd";
3638
- const fetchQuery = async (queryOptions43) => {
3484
+ const fetchQuery = async (queryOptions42) => {
3639
3485
  if (options2.refetch) {
3640
- await queryClient.fetchQuery(queryOptions43);
3486
+ await queryClient.fetchQuery(queryOptions42);
3641
3487
  } else {
3642
- await queryClient.prefetchQuery(queryOptions43);
3488
+ await queryClient.prefetchQuery(queryOptions42);
3643
3489
  }
3644
- return queryClient.getQueryData(queryOptions43.queryKey);
3490
+ return queryClient.getQueryData(queryOptions42.queryKey);
3645
3491
  };
3646
3492
  const convertPriceToUserCurrency = async (assetInfo) => {
3647
3493
  if (!assetInfo || currency === "usd") {
@@ -3771,7 +3617,7 @@ function getTokenOperationsQueryOptions(token, username, isForOwner = false, cur
3771
3617
  queryFn: async () => {
3772
3618
  const queryClient = getQueryClient();
3773
3619
  const normalizedToken = token.toUpperCase();
3774
- if (!username) {
3620
+ if (!username || !isForOwner) {
3775
3621
  return [];
3776
3622
  }
3777
3623
  try {
@@ -3907,12 +3753,13 @@ var PATHS = {
3907
3753
  ["APT" /* APT */]: "m/44'/637'/0'/0'/0'"
3908
3754
  // Aptos (BIP44)
3909
3755
  };
3910
- function useWalletCreate(username, currency) {
3911
- const { data: mnemonic } = useSeedPhrase(username);
3756
+ function useWalletCreate(username, currency, importedSeed) {
3757
+ const { data: generatedMnemonic } = useSeedPhrase(username);
3912
3758
  const queryClient = useQueryClient();
3913
3759
  const createWallet = useMutation({
3914
3760
  mutationKey: ["ecency-wallets", "create-wallet", username, currency],
3915
3761
  mutationFn: async () => {
3762
+ const mnemonic = importedSeed || generatedMnemonic;
3916
3763
  if (!mnemonic) {
3917
3764
  throw new Error("[Ecency][Wallets] - No seed to create a wallet");
3918
3765
  }