@ecency/wallets 1.4.2 → 1.4.6

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.cjs CHANGED
@@ -16,7 +16,6 @@ var crypto = require('@hiveio/dhive/lib/crypto');
16
16
  var memo = require('@hiveio/dhive/lib/memo');
17
17
  var dayjs = require('dayjs');
18
18
  var hs = require('hivesigner');
19
- var react = require('react');
20
19
  var R = require('remeda');
21
20
 
22
21
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -237,7 +236,7 @@ function getCoinGeckoPriceQueryOptions(currency) {
237
236
  let curr = currency;
238
237
  switch (currency) {
239
238
  case "BTC" /* BTC */:
240
- curr = "binance-wrapped-btc";
239
+ curr = "bitcoin";
241
240
  break;
242
241
  case "ETH" /* ETH */:
243
242
  curr = "ethereum";
@@ -554,6 +553,18 @@ function buildExternalTx(currency, tx) {
554
553
  }
555
554
  }
556
555
 
556
+ // src/modules/wallets/utils/get-bound-fetch.ts
557
+ var cachedFetch;
558
+ function getBoundFetch() {
559
+ if (!cachedFetch) {
560
+ if (typeof globalThis.fetch !== "function") {
561
+ throw new Error("[Ecency][Wallets] - global fetch is not available");
562
+ }
563
+ cachedFetch = globalThis.fetch.bind(globalThis);
564
+ }
565
+ return cachedFetch;
566
+ }
567
+
557
568
  // src/modules/wallets/queries/use-hive-keys-query.ts
558
569
  function useHiveKeysQuery(username) {
559
570
  const { data: seed } = useSeedPhrase(username);
@@ -2248,6 +2259,7 @@ function useClaimPoints(username, onSuccess, onError) {
2248
2259
  username,
2249
2260
  "points-claimed"
2250
2261
  );
2262
+ const fetchApi = getBoundFetch();
2251
2263
  return reactQuery.useMutation({
2252
2264
  mutationFn: async () => {
2253
2265
  if (!username) {
@@ -2255,7 +2267,7 @@ function useClaimPoints(username, onSuccess, onError) {
2255
2267
  "[SDK][Wallets][Assets][Points][Claim] \u2013 username wasn`t provided"
2256
2268
  );
2257
2269
  }
2258
- return fetch(sdk.CONFIG.privateApiHost + "/private-api/points-claim", {
2270
+ return fetchApi(sdk.CONFIG.privateApiHost + "/private-api/points-claim", {
2259
2271
  method: "POST",
2260
2272
  headers: {
2261
2273
  "Content-Type": "application/json"
@@ -2948,6 +2960,19 @@ function getTokenOperationsQueryOptions(token, username, isForOwner = false) {
2948
2960
  }
2949
2961
  });
2950
2962
  }
2963
+ function useWalletsCacheQuery(username) {
2964
+ const queryClient = reactQuery.useQueryClient();
2965
+ const queryKey = ["ecency-wallets", "wallets", username];
2966
+ const getCachedWallets = () => queryClient.getQueryData(queryKey);
2967
+ const createEmptyWalletMap = () => /* @__PURE__ */ new Map();
2968
+ return reactQuery.useQuery({
2969
+ queryKey,
2970
+ enabled: Boolean(username),
2971
+ initialData: () => getCachedWallets() ?? createEmptyWalletMap(),
2972
+ queryFn: async () => getCachedWallets() ?? createEmptyWalletMap(),
2973
+ staleTime: Infinity
2974
+ });
2975
+ }
2951
2976
  var PATHS = {
2952
2977
  ["BTC" /* BTC */]: "m/44'/0'/0'/0/0",
2953
2978
  // Bitcoin (BIP44)
@@ -3000,8 +3025,8 @@ function useWalletCreate(username, currency) {
3000
3025
  );
3001
3026
  }
3002
3027
  });
3003
- const importWallet = react.useCallback(() => {
3004
- }, []);
3028
+ const importWallet = () => {
3029
+ };
3005
3030
  return {
3006
3031
  createWallet,
3007
3032
  importWallet
@@ -3012,16 +3037,16 @@ function useWalletCreate(username, currency) {
3012
3037
  var private_api_exports = {};
3013
3038
  __export(private_api_exports, {
3014
3039
  useCheckWalletExistence: () => useCheckWalletExistence,
3015
- useCreateAccountWithWallets: () => useCreateAccountWithWallets
3040
+ useCreateAccountWithWallets: () => useCreateAccountWithWallets,
3041
+ useUpdateAccountWithWallets: () => useUpdateAccountWithWallets
3016
3042
  });
3017
3043
  function useCreateAccountWithWallets(username) {
3018
- const { data } = reactQuery.useQuery({
3019
- queryKey: ["ecency-wallets", "wallets", username]
3020
- });
3044
+ const { data } = useWalletsCacheQuery(username);
3021
3045
  const { data: hiveKeys } = useHiveKeysQuery(username);
3046
+ const fetchApi = getBoundFetch();
3022
3047
  return reactQuery.useMutation({
3023
3048
  mutationKey: ["ecency-wallets", "create-account-with-wallets", username],
3024
- mutationFn: ({ currency, address }) => fetch(sdk.CONFIG.privateApiHost + "/private-api/wallets-add", {
3049
+ mutationFn: ({ currency, address }) => fetchApi(sdk.CONFIG.privateApiHost + "/private-api/wallets-add", {
3025
3050
  method: "POST",
3026
3051
  headers: {
3027
3052
  "Content-Type": "application/json"
@@ -3069,6 +3094,39 @@ function useCheckWalletExistence() {
3069
3094
  }
3070
3095
  });
3071
3096
  }
3097
+ function useUpdateAccountWithWallets(username) {
3098
+ const fetchApi = getBoundFetch();
3099
+ return reactQuery.useMutation({
3100
+ mutationKey: ["ecency-wallets", "create-account-with-wallets", username],
3101
+ mutationFn: async ({ tokens, hiveKeys }) => {
3102
+ const entries = Object.entries(tokens).filter(([, address]) => Boolean(address));
3103
+ if (entries.length === 0) {
3104
+ return new Response(null, { status: 204 });
3105
+ }
3106
+ const [primaryToken, primaryAddress] = entries[0] ?? ["", ""];
3107
+ return fetchApi(sdk.CONFIG.privateApiHost + "/private-api/wallets-add", {
3108
+ method: "POST",
3109
+ headers: {
3110
+ "Content-Type": "application/json"
3111
+ },
3112
+ body: JSON.stringify({
3113
+ username,
3114
+ code: sdk.getAccessToken(username),
3115
+ token: primaryToken,
3116
+ address: primaryAddress,
3117
+ status: 3,
3118
+ meta: {
3119
+ ...Object.fromEntries(entries),
3120
+ ownerPublicKey: hiveKeys.ownerPublicKey,
3121
+ activePublicKey: hiveKeys.activePublicKey,
3122
+ postingPublicKey: hiveKeys.postingPublicKey,
3123
+ memoPublicKey: hiveKeys.memoPublicKey
3124
+ }
3125
+ })
3126
+ });
3127
+ }
3128
+ });
3129
+ }
3072
3130
 
3073
3131
  // src/modules/wallets/functions/get-keys-from-seed.ts
3074
3132
  var HD_PATHS = {
@@ -3196,18 +3254,15 @@ function useSaveWalletInformationToMetadata(username, options2) {
3196
3254
  const profileChainTokens = getGroupedChainTokens(
3197
3255
  accountData.profile?.tokens
3198
3256
  );
3199
- console.log("profile tokens are ", profileChainTokens);
3200
3257
  const payloadTokens = tokens.map(({ currency, type, privateKey, username: username2, ...meta }) => ({
3201
3258
  symbol: currency,
3202
- type: type ?? Object.values(EcencyWalletCurrency).includes(currency) ? "CHAIN" : void 0,
3259
+ type: type ?? (Object.values(EcencyWalletCurrency).includes(currency) ? "CHAIN" : void 0),
3203
3260
  meta
3204
3261
  })) ?? [];
3205
3262
  const payloadChainTokens = getGroupedChainTokens(payloadTokens, true);
3206
3263
  const payloadNonChainTokens = payloadTokens.filter(
3207
3264
  ({ type, symbol }) => type !== "CHAIN" && !Object.values(EcencyWalletCurrency).includes(symbol)
3208
3265
  );
3209
- console.log("payload tokens are ", payloadChainTokens);
3210
- console.log("payload non-chain tokens are ", payloadNonChainTokens);
3211
3266
  const mergedChainTokens = R__namespace.pipe(
3212
3267
  profileChainTokens,
3213
3268
  R__namespace.mergeDeep(payloadChainTokens),
@@ -3334,6 +3389,7 @@ exports.encryptMemoWithKeys = encryptMemoWithKeys;
3334
3389
  exports.getAccountWalletAssetInfoQueryOptions = getAccountWalletAssetInfoQueryOptions;
3335
3390
  exports.getAccountWalletListQueryOptions = getAccountWalletListQueryOptions;
3336
3391
  exports.getAllTokensListQueryOptions = getAllTokensListQueryOptions;
3392
+ exports.getBoundFetch = getBoundFetch;
3337
3393
  exports.getCoinGeckoPriceQueryOptions = getCoinGeckoPriceQueryOptions;
3338
3394
  exports.getHbdAssetGeneralInfoQueryOptions = getHbdAssetGeneralInfoQueryOptions;
3339
3395
  exports.getHbdAssetTransactionsQueryOptions = getHbdAssetTransactionsQueryOptions;
@@ -3390,6 +3446,7 @@ exports.useSaveWalletInformationToMetadata = useSaveWalletInformationToMetadata;
3390
3446
  exports.useSeedPhrase = useSeedPhrase;
3391
3447
  exports.useWalletCreate = useWalletCreate;
3392
3448
  exports.useWalletOperation = useWalletOperation;
3449
+ exports.useWalletsCacheQuery = useWalletsCacheQuery;
3393
3450
  exports.vestsToHp = vestsToHp;
3394
3451
  exports.withdrawVestingRouteHive = withdrawVestingRouteHive;
3395
3452
  //# sourceMappingURL=index.cjs.map