@ecency/wallets 1.4.2 → 1.4.5

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/index.d.ts CHANGED
@@ -72,22 +72,34 @@ declare function useWalletCreate(username: string, currency: EcencyWalletCurrenc
72
72
  importWallet: () => void;
73
73
  };
74
74
 
75
- interface Payload$7 {
75
+ interface Payload$8 {
76
76
  currency: string;
77
77
  address: string;
78
78
  }
79
- declare function useCreateAccountWithWallets(username: string): _tanstack_react_query.UseMutationResult<Response, Error, Payload$7, unknown>;
79
+ declare function useCreateAccountWithWallets(username: string): _tanstack_react_query.UseMutationResult<Response, Error, Payload$8, unknown>;
80
80
 
81
- interface Payload$6 {
81
+ interface Payload$7 {
82
82
  address: string;
83
83
  currency: EcencyWalletCurrency;
84
84
  }
85
- declare function useCheckWalletExistence(): _tanstack_react_query.UseMutationResult<boolean, Error, Payload$6, unknown>;
85
+ declare function useCheckWalletExistence(): _tanstack_react_query.UseMutationResult<boolean, Error, Payload$7, unknown>;
86
+
87
+ interface Payload$6 {
88
+ tokens: Record<string, string>;
89
+ hiveKeys: {
90
+ ownerPublicKey: string;
91
+ activePublicKey: string;
92
+ postingPublicKey: string;
93
+ memoPublicKey: string;
94
+ };
95
+ }
96
+ declare function useUpdateAccountWithWallets(username: string): _tanstack_react_query.UseMutationResult<Response, Error, Payload$6, unknown>;
86
97
 
87
98
  declare const index_useCheckWalletExistence: typeof useCheckWalletExistence;
88
99
  declare const index_useCreateAccountWithWallets: typeof useCreateAccountWithWallets;
100
+ declare const index_useUpdateAccountWithWallets: typeof useUpdateAccountWithWallets;
89
101
  declare namespace index {
90
- export { index_useCheckWalletExistence as useCheckWalletExistence, index_useCreateAccountWithWallets as useCreateAccountWithWallets };
102
+ export { index_useCheckWalletExistence as useCheckWalletExistence, index_useCreateAccountWithWallets as useCreateAccountWithWallets, index_useUpdateAccountWithWallets as useUpdateAccountWithWallets };
91
103
  }
92
104
 
93
105
  interface Payload$5 {
@@ -1467,6 +1479,8 @@ declare function getTokenOperationsQueryOptions(token: string, username: string,
1467
1479
  };
1468
1480
  };
1469
1481
 
1482
+ declare function useWalletsCacheQuery(username?: string): _tanstack_react_query.DefinedUseQueryResult<Map<EcencyWalletCurrency, EcencyTokenMetadata>, Error>;
1483
+
1470
1484
  declare function delay(ms: number): Promise<unknown>;
1471
1485
 
1472
1486
  declare function getWallet(currency: EcencyWalletCurrency): BaseWallet | undefined;
@@ -1624,4 +1638,6 @@ declare function buildAptTx(data: AptosParam): AptosParam;
1624
1638
  */
1625
1639
  declare function buildExternalTx(currency: EcencyWalletCurrency, tx: ExternalTxParams): string | EthTxParams | SolSignParam | TrxSignParam | TxData | AptosParam;
1626
1640
 
1627
- export { type AccountPointsResponse, type Asset, AssetOperation, type DelegateEnginePayload, type EcencyHiveKeys, type EcencyTokenMetadata, EcencyWalletBasicTokens, EcencyWalletCurrency, index as EcencyWalletsPrivateApi, type ExternalTxParams, type ExternalWalletBalance, type GeneralAssetInfo, type GeneralAssetTransaction, type HiveBasedAssetSignType, type HiveEngineMarketResponse, type HiveEngineMetric, type HiveEngineTokenBalance, type HiveEngineTokenMetadataResponse, type HiveEngineTransaction, type HiveKeyDerivation, type HiveRole, NaiMap, type PointTransaction, PointTransactionType, type Points, type PointsResponse, type SpkApiWallet, type SpkMarkets, type StakeEnginePayload, Symbol, type TransferEnginePayload, type TransferPayload, type TransformedSpkMarkets, type UndelegateEnginePayload, type UnstakeEnginePayload, buildAptTx, buildEthTx, buildExternalTx, buildPsbt, buildSolTx, buildTonTx, buildTronTx, decryptMemoWithAccounts, decryptMemoWithKeys, delay, delegateEngineToken, delegateHive, deriveHiveKey, deriveHiveKeys, deriveHiveMasterPasswordKey, deriveHiveMasterPasswordKeys, detectHiveKeyDerivation, encryptMemoWithAccounts, encryptMemoWithKeys, getAccountWalletAssetInfoQueryOptions, getAccountWalletListQueryOptions, getAllTokensListQueryOptions, getCoinGeckoPriceQueryOptions, getHbdAssetGeneralInfoQueryOptions, getHbdAssetTransactionsQueryOptions, getHiveAssetGeneralInfoQueryOptions, getHiveAssetMetricQueryOptions, getHiveAssetTransactionsQueryOptions, getHiveAssetWithdrawalRoutesQueryOptions, getHiveEngineTokenGeneralInfoQueryOptions, getHiveEngineTokenTransactionsQueryOptions, getHiveEngineTokensBalancesQueryOptions, getHiveEngineTokensMarketQueryOptions, getHiveEngineTokensMetadataQueryOptions, getHiveEngineTokensMetricsQueryOptions, getHivePowerAssetGeneralInfoQueryOptions, getHivePowerAssetTransactionsQueryOptions, getHivePowerDelegatesInfiniteQueryOptions, getHivePowerDelegatingsQueryOptions, getLarynxAssetGeneralInfoQueryOptions, getLarynxPowerAssetGeneralInfoQueryOptions, getPointsAssetGeneralInfoQueryOptions, getPointsAssetTransactionsQueryOptions, getPointsQueryOptions, getSpkAssetGeneralInfoQueryOptions, getSpkMarketsQueryOptions, getTokenOperationsQueryOptions, getWallet, isEmptyDate, lockLarynx, mnemonicToSeedBip39, parseAsset, powerDownHive, powerUpHive, powerUpLarynx, rewardSpk, signDigest, signExternalTx, signExternalTxAndBroadcast, signTx, signTxAndBroadcast, stakeEngineToken, transferEngineToken, transferHive, transferPoint, transferSpk, transferToSavingsHive, undelegateEngineToken, unstakeEngineToken, useClaimPoints, useClaimRewards, useGetExternalWalletBalanceQuery, useHiveKeysQuery, useImportWallet, useSaveWalletInformationToMetadata, useSeedPhrase, useWalletCreate, useWalletOperation, vestsToHp, withdrawVestingRouteHive };
1641
+ declare function getBoundFetch(): typeof fetch;
1642
+
1643
+ export { type AccountPointsResponse, type Asset, AssetOperation, type DelegateEnginePayload, type EcencyHiveKeys, type EcencyTokenMetadata, EcencyWalletBasicTokens, EcencyWalletCurrency, index as EcencyWalletsPrivateApi, type ExternalTxParams, type ExternalWalletBalance, type GeneralAssetInfo, type GeneralAssetTransaction, type HiveBasedAssetSignType, type HiveEngineMarketResponse, type HiveEngineMetric, type HiveEngineTokenBalance, type HiveEngineTokenMetadataResponse, type HiveEngineTransaction, type HiveKeyDerivation, type HiveRole, NaiMap, type PointTransaction, PointTransactionType, type Points, type PointsResponse, type SpkApiWallet, type SpkMarkets, type StakeEnginePayload, Symbol, type TransferEnginePayload, type TransferPayload, type TransformedSpkMarkets, type UndelegateEnginePayload, type UnstakeEnginePayload, buildAptTx, buildEthTx, buildExternalTx, buildPsbt, buildSolTx, buildTonTx, buildTronTx, decryptMemoWithAccounts, decryptMemoWithKeys, delay, delegateEngineToken, delegateHive, deriveHiveKey, deriveHiveKeys, deriveHiveMasterPasswordKey, deriveHiveMasterPasswordKeys, detectHiveKeyDerivation, encryptMemoWithAccounts, encryptMemoWithKeys, getAccountWalletAssetInfoQueryOptions, getAccountWalletListQueryOptions, getAllTokensListQueryOptions, getBoundFetch, getCoinGeckoPriceQueryOptions, getHbdAssetGeneralInfoQueryOptions, getHbdAssetTransactionsQueryOptions, getHiveAssetGeneralInfoQueryOptions, getHiveAssetMetricQueryOptions, getHiveAssetTransactionsQueryOptions, getHiveAssetWithdrawalRoutesQueryOptions, getHiveEngineTokenGeneralInfoQueryOptions, getHiveEngineTokenTransactionsQueryOptions, getHiveEngineTokensBalancesQueryOptions, getHiveEngineTokensMarketQueryOptions, getHiveEngineTokensMetadataQueryOptions, getHiveEngineTokensMetricsQueryOptions, getHivePowerAssetGeneralInfoQueryOptions, getHivePowerAssetTransactionsQueryOptions, getHivePowerDelegatesInfiniteQueryOptions, getHivePowerDelegatingsQueryOptions, getLarynxAssetGeneralInfoQueryOptions, getLarynxPowerAssetGeneralInfoQueryOptions, getPointsAssetGeneralInfoQueryOptions, getPointsAssetTransactionsQueryOptions, getPointsQueryOptions, getSpkAssetGeneralInfoQueryOptions, getSpkMarketsQueryOptions, getTokenOperationsQueryOptions, getWallet, isEmptyDate, lockLarynx, mnemonicToSeedBip39, parseAsset, powerDownHive, powerUpHive, powerUpLarynx, rewardSpk, signDigest, signExternalTx, signExternalTxAndBroadcast, signTx, signTxAndBroadcast, stakeEngineToken, transferEngineToken, transferHive, transferPoint, transferSpk, transferToSavingsHive, undelegateEngineToken, unstakeEngineToken, useClaimPoints, useClaimRewards, useGetExternalWalletBalanceQuery, useHiveKeysQuery, useImportWallet, useSaveWalletInformationToMetadata, useSeedPhrase, useWalletCreate, useWalletOperation, useWalletsCacheQuery, vestsToHp, withdrawVestingRouteHive };
package/dist/index.mjs CHANGED
@@ -14,7 +14,6 @@ import { cryptoUtils } from '@hiveio/dhive/lib/crypto';
14
14
  import { Memo } from '@hiveio/dhive/lib/memo';
15
15
  import dayjs from 'dayjs';
16
16
  import hs from 'hivesigner';
17
- import { useCallback } from 'react';
18
17
  import * as R from 'remeda';
19
18
 
20
19
  var __defProp = Object.defineProperty;
@@ -210,7 +209,7 @@ function getCoinGeckoPriceQueryOptions(currency) {
210
209
  let curr = currency;
211
210
  switch (currency) {
212
211
  case "BTC" /* BTC */:
213
- curr = "binance-wrapped-btc";
212
+ curr = "bitcoin";
214
213
  break;
215
214
  case "ETH" /* ETH */:
216
215
  curr = "ethereum";
@@ -527,6 +526,18 @@ function buildExternalTx(currency, tx) {
527
526
  }
528
527
  }
529
528
 
529
+ // src/modules/wallets/utils/get-bound-fetch.ts
530
+ var cachedFetch;
531
+ function getBoundFetch() {
532
+ if (!cachedFetch) {
533
+ if (typeof globalThis.fetch !== "function") {
534
+ throw new Error("[Ecency][Wallets] - global fetch is not available");
535
+ }
536
+ cachedFetch = globalThis.fetch.bind(globalThis);
537
+ }
538
+ return cachedFetch;
539
+ }
540
+
530
541
  // src/modules/wallets/queries/use-hive-keys-query.ts
531
542
  function useHiveKeysQuery(username) {
532
543
  const { data: seed } = useSeedPhrase(username);
@@ -2221,6 +2232,7 @@ function useClaimPoints(username, onSuccess, onError) {
2221
2232
  username,
2222
2233
  "points-claimed"
2223
2234
  );
2235
+ const fetchApi = getBoundFetch();
2224
2236
  return useMutation({
2225
2237
  mutationFn: async () => {
2226
2238
  if (!username) {
@@ -2228,7 +2240,7 @@ function useClaimPoints(username, onSuccess, onError) {
2228
2240
  "[SDK][Wallets][Assets][Points][Claim] \u2013 username wasn`t provided"
2229
2241
  );
2230
2242
  }
2231
- return fetch(CONFIG.privateApiHost + "/private-api/points-claim", {
2243
+ return fetchApi(CONFIG.privateApiHost + "/private-api/points-claim", {
2232
2244
  method: "POST",
2233
2245
  headers: {
2234
2246
  "Content-Type": "application/json"
@@ -2921,6 +2933,19 @@ function getTokenOperationsQueryOptions(token, username, isForOwner = false) {
2921
2933
  }
2922
2934
  });
2923
2935
  }
2936
+ function useWalletsCacheQuery(username) {
2937
+ const queryClient = useQueryClient();
2938
+ const queryKey = ["ecency-wallets", "wallets", username];
2939
+ const getCachedWallets = () => queryClient.getQueryData(queryKey);
2940
+ const createEmptyWalletMap = () => /* @__PURE__ */ new Map();
2941
+ return useQuery({
2942
+ queryKey,
2943
+ enabled: Boolean(username),
2944
+ initialData: () => getCachedWallets() ?? createEmptyWalletMap(),
2945
+ queryFn: async () => getCachedWallets() ?? createEmptyWalletMap(),
2946
+ staleTime: Infinity
2947
+ });
2948
+ }
2924
2949
  var PATHS = {
2925
2950
  ["BTC" /* BTC */]: "m/44'/0'/0'/0/0",
2926
2951
  // Bitcoin (BIP44)
@@ -2973,8 +2998,8 @@ function useWalletCreate(username, currency) {
2973
2998
  );
2974
2999
  }
2975
3000
  });
2976
- const importWallet = useCallback(() => {
2977
- }, []);
3001
+ const importWallet = () => {
3002
+ };
2978
3003
  return {
2979
3004
  createWallet,
2980
3005
  importWallet
@@ -2985,16 +3010,16 @@ function useWalletCreate(username, currency) {
2985
3010
  var private_api_exports = {};
2986
3011
  __export(private_api_exports, {
2987
3012
  useCheckWalletExistence: () => useCheckWalletExistence,
2988
- useCreateAccountWithWallets: () => useCreateAccountWithWallets
3013
+ useCreateAccountWithWallets: () => useCreateAccountWithWallets,
3014
+ useUpdateAccountWithWallets: () => useUpdateAccountWithWallets
2989
3015
  });
2990
3016
  function useCreateAccountWithWallets(username) {
2991
- const { data } = useQuery({
2992
- queryKey: ["ecency-wallets", "wallets", username]
2993
- });
3017
+ const { data } = useWalletsCacheQuery(username);
2994
3018
  const { data: hiveKeys } = useHiveKeysQuery(username);
3019
+ const fetchApi = getBoundFetch();
2995
3020
  return useMutation({
2996
3021
  mutationKey: ["ecency-wallets", "create-account-with-wallets", username],
2997
- mutationFn: ({ currency, address }) => fetch(CONFIG.privateApiHost + "/private-api/wallets-add", {
3022
+ mutationFn: ({ currency, address }) => fetchApi(CONFIG.privateApiHost + "/private-api/wallets-add", {
2998
3023
  method: "POST",
2999
3024
  headers: {
3000
3025
  "Content-Type": "application/json"
@@ -3042,6 +3067,39 @@ function useCheckWalletExistence() {
3042
3067
  }
3043
3068
  });
3044
3069
  }
3070
+ function useUpdateAccountWithWallets(username) {
3071
+ const fetchApi = getBoundFetch();
3072
+ return useMutation({
3073
+ mutationKey: ["ecency-wallets", "create-account-with-wallets", username],
3074
+ mutationFn: async ({ tokens, hiveKeys }) => {
3075
+ const entries = Object.entries(tokens).filter(([, address]) => Boolean(address));
3076
+ if (entries.length === 0) {
3077
+ return new Response(null, { status: 204 });
3078
+ }
3079
+ const [primaryToken, primaryAddress] = entries[0] ?? ["", ""];
3080
+ return fetchApi(CONFIG.privateApiHost + "/private-api/wallets-add", {
3081
+ method: "POST",
3082
+ headers: {
3083
+ "Content-Type": "application/json"
3084
+ },
3085
+ body: JSON.stringify({
3086
+ username,
3087
+ code: getAccessToken(username),
3088
+ token: primaryToken,
3089
+ address: primaryAddress,
3090
+ status: 3,
3091
+ meta: {
3092
+ ...Object.fromEntries(entries),
3093
+ ownerPublicKey: hiveKeys.ownerPublicKey,
3094
+ activePublicKey: hiveKeys.activePublicKey,
3095
+ postingPublicKey: hiveKeys.postingPublicKey,
3096
+ memoPublicKey: hiveKeys.memoPublicKey
3097
+ }
3098
+ })
3099
+ });
3100
+ }
3101
+ });
3102
+ }
3045
3103
 
3046
3104
  // src/modules/wallets/functions/get-keys-from-seed.ts
3047
3105
  var HD_PATHS = {
@@ -3169,18 +3227,15 @@ function useSaveWalletInformationToMetadata(username, options2) {
3169
3227
  const profileChainTokens = getGroupedChainTokens(
3170
3228
  accountData.profile?.tokens
3171
3229
  );
3172
- console.log("profile tokens are ", profileChainTokens);
3173
3230
  const payloadTokens = tokens.map(({ currency, type, privateKey, username: username2, ...meta }) => ({
3174
3231
  symbol: currency,
3175
- type: type ?? Object.values(EcencyWalletCurrency).includes(currency) ? "CHAIN" : void 0,
3232
+ type: type ?? (Object.values(EcencyWalletCurrency).includes(currency) ? "CHAIN" : void 0),
3176
3233
  meta
3177
3234
  })) ?? [];
3178
3235
  const payloadChainTokens = getGroupedChainTokens(payloadTokens, true);
3179
3236
  const payloadNonChainTokens = payloadTokens.filter(
3180
3237
  ({ type, symbol }) => type !== "CHAIN" && !Object.values(EcencyWalletCurrency).includes(symbol)
3181
3238
  );
3182
- console.log("payload tokens are ", payloadChainTokens);
3183
- console.log("payload non-chain tokens are ", payloadNonChainTokens);
3184
3239
  const mergedChainTokens = R.pipe(
3185
3240
  profileChainTokens,
3186
3241
  R.mergeDeep(payloadChainTokens),
@@ -3278,6 +3333,6 @@ function useWalletOperation(username, asset, operation) {
3278
3333
  // src/index.ts
3279
3334
  rememberScryptBsvVersion();
3280
3335
 
3281
- export { AssetOperation, EcencyWalletBasicTokens, EcencyWalletCurrency, private_api_exports as EcencyWalletsPrivateApi, NaiMap, PointTransactionType, Symbol2 as Symbol, buildAptTx, buildEthTx, buildExternalTx, buildPsbt, buildSolTx, buildTonTx, buildTronTx, decryptMemoWithAccounts, decryptMemoWithKeys, delay, delegateEngineToken, delegateHive, deriveHiveKey, deriveHiveKeys, deriveHiveMasterPasswordKey, deriveHiveMasterPasswordKeys, detectHiveKeyDerivation, encryptMemoWithAccounts, encryptMemoWithKeys, getAccountWalletAssetInfoQueryOptions, getAccountWalletListQueryOptions, getAllTokensListQueryOptions, getCoinGeckoPriceQueryOptions, getHbdAssetGeneralInfoQueryOptions, getHbdAssetTransactionsQueryOptions, getHiveAssetGeneralInfoQueryOptions, getHiveAssetMetricQueryOptions, getHiveAssetTransactionsQueryOptions, getHiveAssetWithdrawalRoutesQueryOptions, getHiveEngineTokenGeneralInfoQueryOptions, getHiveEngineTokenTransactionsQueryOptions, getHiveEngineTokensBalancesQueryOptions, getHiveEngineTokensMarketQueryOptions, getHiveEngineTokensMetadataQueryOptions, getHiveEngineTokensMetricsQueryOptions, getHivePowerAssetGeneralInfoQueryOptions, getHivePowerAssetTransactionsQueryOptions, getHivePowerDelegatesInfiniteQueryOptions, getHivePowerDelegatingsQueryOptions, getLarynxAssetGeneralInfoQueryOptions, getLarynxPowerAssetGeneralInfoQueryOptions, getPointsAssetGeneralInfoQueryOptions, getPointsAssetTransactionsQueryOptions, getPointsQueryOptions, getSpkAssetGeneralInfoQueryOptions, getSpkMarketsQueryOptions, getTokenOperationsQueryOptions, getWallet, isEmptyDate, lockLarynx, mnemonicToSeedBip39, parseAsset, powerDownHive, powerUpHive, powerUpLarynx, rewardSpk, signDigest, signExternalTx, signExternalTxAndBroadcast, signTx, signTxAndBroadcast, stakeEngineToken, transferEngineToken, transferHive, transferPoint, transferSpk, transferToSavingsHive, undelegateEngineToken, unstakeEngineToken, useClaimPoints, useClaimRewards, useGetExternalWalletBalanceQuery, useHiveKeysQuery, useImportWallet, useSaveWalletInformationToMetadata, useSeedPhrase, useWalletCreate, useWalletOperation, vestsToHp, withdrawVestingRouteHive };
3336
+ export { AssetOperation, EcencyWalletBasicTokens, EcencyWalletCurrency, private_api_exports as EcencyWalletsPrivateApi, NaiMap, PointTransactionType, Symbol2 as Symbol, buildAptTx, buildEthTx, buildExternalTx, buildPsbt, buildSolTx, buildTonTx, buildTronTx, decryptMemoWithAccounts, decryptMemoWithKeys, delay, delegateEngineToken, delegateHive, deriveHiveKey, deriveHiveKeys, deriveHiveMasterPasswordKey, deriveHiveMasterPasswordKeys, detectHiveKeyDerivation, encryptMemoWithAccounts, encryptMemoWithKeys, getAccountWalletAssetInfoQueryOptions, getAccountWalletListQueryOptions, getAllTokensListQueryOptions, getBoundFetch, getCoinGeckoPriceQueryOptions, getHbdAssetGeneralInfoQueryOptions, getHbdAssetTransactionsQueryOptions, getHiveAssetGeneralInfoQueryOptions, getHiveAssetMetricQueryOptions, getHiveAssetTransactionsQueryOptions, getHiveAssetWithdrawalRoutesQueryOptions, getHiveEngineTokenGeneralInfoQueryOptions, getHiveEngineTokenTransactionsQueryOptions, getHiveEngineTokensBalancesQueryOptions, getHiveEngineTokensMarketQueryOptions, getHiveEngineTokensMetadataQueryOptions, getHiveEngineTokensMetricsQueryOptions, getHivePowerAssetGeneralInfoQueryOptions, getHivePowerAssetTransactionsQueryOptions, getHivePowerDelegatesInfiniteQueryOptions, getHivePowerDelegatingsQueryOptions, getLarynxAssetGeneralInfoQueryOptions, getLarynxPowerAssetGeneralInfoQueryOptions, getPointsAssetGeneralInfoQueryOptions, getPointsAssetTransactionsQueryOptions, getPointsQueryOptions, getSpkAssetGeneralInfoQueryOptions, getSpkMarketsQueryOptions, getTokenOperationsQueryOptions, getWallet, isEmptyDate, lockLarynx, mnemonicToSeedBip39, parseAsset, powerDownHive, powerUpHive, powerUpLarynx, rewardSpk, signDigest, signExternalTx, signExternalTxAndBroadcast, signTx, signTxAndBroadcast, stakeEngineToken, transferEngineToken, transferHive, transferPoint, transferSpk, transferToSavingsHive, undelegateEngineToken, unstakeEngineToken, useClaimPoints, useClaimRewards, useGetExternalWalletBalanceQuery, useHiveKeysQuery, useImportWallet, useSaveWalletInformationToMetadata, useSeedPhrase, useWalletCreate, useWalletOperation, useWalletsCacheQuery, vestsToHp, withdrawVestingRouteHive };
3282
3337
  //# sourceMappingURL=index.mjs.map
3283
3338
  //# sourceMappingURL=index.mjs.map