@ecency/sdk 1.0.20 → 1.0.22

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,48 +1,48 @@
1
- import { useCallback as g } from "react";
2
- import { useQuery as m, queryOptions as v, useQueryClient as b, useMutation as u } from "@tanstack/react-query";
3
- import { BtcWallet as R } from "@okxweb3/coin-bitcoin";
4
- import { EthWallet as C } from "@okxweb3/coin-ethereum";
5
- import { TrxWallet as H } from "@okxweb3/coin-tron";
6
- import { TonWallet as N } from "@okxweb3/coin-ton";
7
- import { SolWallet as j } from "@okxweb3/coin-solana";
8
- import { AtomWallet as D } from "@okxweb3/coin-cosmos";
9
- import { AptosWallet as x } from "@okxweb3/coin-aptos";
10
- import L, { mnemonicToSeedSync as _ } from "bip39";
11
- import { Client as F, PrivateKey as l, cryptoUtils as B } from "@hiveio/dhive";
12
- import { LRUCache as E } from "lru-cache";
13
- import T from "hivesigner";
14
- var a = /* @__PURE__ */ ((e) => (e.BTC = "BTC", e.ETH = "ETH", e.APT = "APT", e.ATOM = "ATOM", e.TON = "TON", e.TRON = "TRX", e.SOL = "SOL", e))(a || {}), h = /* @__PURE__ */ ((e) => (e.Points = "POINTS", e.HivePower = "HP", e.Hive = "HIVE", e.HiveDollar = "HBD", e.Spk = "SPK", e))(h || {});
15
- function q(e) {
1
+ import { useMemo as K, useCallback as R } from "react";
2
+ import { useQuery as h, queryOptions as g, useQueryClient as v, useMutation as u } from "@tanstack/react-query";
3
+ import { BtcWallet as C } from "@okxweb3/coin-bitcoin";
4
+ import { EthWallet as H } from "@okxweb3/coin-ethereum";
5
+ import { TrxWallet as N } from "@okxweb3/coin-tron";
6
+ import { TonWallet as j } from "@okxweb3/coin-ton";
7
+ import { SolWallet as D } from "@okxweb3/coin-solana";
8
+ import { AtomWallet as x } from "@okxweb3/coin-cosmos";
9
+ import { AptosWallet as L } from "@okxweb3/coin-aptos";
10
+ import _, { mnemonicToSeedSync as F } from "bip39";
11
+ import { Client as B, PrivateKey as l, cryptoUtils as E } from "@hiveio/dhive";
12
+ import { LRUCache as q } from "lru-cache";
13
+ import b from "hivesigner";
14
+ var a = /* @__PURE__ */ ((e) => (e.BTC = "BTC", e.ETH = "ETH", e.APT = "APT", e.ATOM = "ATOM", e.TON = "TON", e.TRON = "TRX", e.SOL = "SOL", e))(a || {}), m = /* @__PURE__ */ ((e) => (e.Points = "POINTS", e.HivePower = "HP", e.Hive = "HIVE", e.HiveDollar = "HBD", e.Spk = "SPK", e))(m || {});
15
+ function M(e) {
16
16
  return new Promise((t) => setTimeout(t, e));
17
17
  }
18
- function P(e) {
18
+ function T(e) {
19
19
  switch (e) {
20
20
  case a.BTC:
21
- return new R();
22
- case a.ETH:
23
21
  return new C();
24
- case a.TRON:
22
+ case a.ETH:
25
23
  return new H();
26
- case a.TON:
24
+ case a.TRON:
27
25
  return new N();
28
- case a.SOL:
26
+ case a.TON:
29
27
  return new j();
30
- case a.ATOM:
28
+ case a.SOL:
31
29
  return new D();
32
- case a.APT:
30
+ case a.ATOM:
33
31
  return new x();
32
+ case a.APT:
33
+ return new L();
34
34
  default:
35
35
  return;
36
36
  }
37
37
  }
38
- function Te(e) {
39
- return _(e).toString("hex");
38
+ function Pe(e) {
39
+ return F(e).toString("hex");
40
40
  }
41
41
  const p = {
42
42
  privateApiHost: "https://ecency.com",
43
43
  storage: localStorage,
44
44
  storagePrefix: "ecency",
45
- hiveClient: new F(
45
+ hiveClient: new B(
46
46
  [
47
47
  "https://api.hive.blog",
48
48
  "https://api.deathwing.me",
@@ -64,8 +64,8 @@ const p = {
64
64
  ),
65
65
  heliusApiKey: "fb1e2935-f911-4b1d-8e1c-3863f6879d42"
66
66
  };
67
- function Pe(e, t) {
68
- return m({
67
+ function Se(e, t) {
68
+ return h({
69
69
  queryKey: ["ecency-wallets", "external-wallet-balance", e, t],
70
70
  queryFn: async () => {
71
71
  switch (e) {
@@ -106,7 +106,7 @@ function Pe(e, t) {
106
106
  const f = (await (await fetch(
107
107
  `https://fullnode.mainnet.aptoslabs.com/v1/accounts/${t}/resources`
108
108
  )).json()).find(
109
- (K) => K.type.includes("coin::CoinStore")
109
+ (k) => k.type.includes("coin::CoinStore")
110
110
  );
111
111
  return f ? parseInt(f.data.coin.value) / 1e8 : 0;
112
112
  case a.ATOM:
@@ -117,13 +117,13 @@ function Pe(e, t) {
117
117
  }
118
118
  });
119
119
  }
120
- function S(e) {
121
- return m({
120
+ function P(e) {
121
+ return h({
122
122
  queryKey: ["ecency-wallets", "seed", e],
123
- queryFn: async () => L.generateMnemonic(128)
123
+ queryFn: async () => _.generateMnemonic(128)
124
124
  });
125
125
  }
126
- const M = {
126
+ const W = {
127
127
  max: 500,
128
128
  // how long to live in ms
129
129
  ttl: 1e3 * 60 * 5,
@@ -131,12 +131,12 @@ const M = {
131
131
  allowStale: !1,
132
132
  updateAgeOnGet: !1,
133
133
  updateAgeOnHas: !1
134
- }, O = new E(M), y = Symbol("undefined"), W = (e, t) => O.set(e, t === void 0 ? y : t), Q = (e) => {
135
- const t = O.get(e);
134
+ }, S = new q(W), y = Symbol("undefined"), Q = (e, t) => S.set(e, t === void 0 ? y : t), I = (e) => {
135
+ const t = S.get(e);
136
136
  return t === y ? void 0 : t;
137
137
  };
138
- function Se(e) {
139
- return m({
138
+ function Oe(e) {
139
+ return h({
140
140
  queryKey: ["ecency-wallets", "coingecko-price", e],
141
141
  queryFn: async () => {
142
142
  let t = e;
@@ -156,7 +156,7 @@ function Se(e) {
156
156
  default:
157
157
  t = e;
158
158
  }
159
- let n = Q("gecko"), o;
159
+ let n = I("gecko"), o;
160
160
  if (n)
161
161
  o = n;
162
162
  else {
@@ -172,16 +172,16 @@ function Se(e) {
172
172
  })
173
173
  }
174
174
  )).json();
175
- W("gecko", i === void 0 ? y : i), o = i;
175
+ Q("gecko", i === void 0 ? y : i), o = i;
176
176
  }
177
177
  return 1 / +o[Object.keys(o)[0]].usd;
178
178
  },
179
179
  enabled: !!e
180
180
  });
181
181
  }
182
- function I(e) {
183
- const { data: t } = S(e);
184
- return m({
182
+ function J(e) {
183
+ const { data: t } = P(e);
184
+ return h({
185
185
  queryKey: ["ecencу-wallets", "hive-keys", e, t],
186
186
  queryFn: async () => {
187
187
  if (!t)
@@ -201,8 +201,8 @@ function I(e) {
201
201
  }
202
202
  });
203
203
  }
204
- function Oe(e, t) {
205
- return v({
204
+ function Ae(e, t) {
205
+ return g({
206
206
  queryKey: ["ecency-wallets", "points", e, t],
207
207
  queryFn: async () => await (await fetch(
208
208
  `${p.privateApiHost}/private-api/points`,
@@ -218,8 +218,8 @@ function Oe(e, t) {
218
218
  enabled: !!e
219
219
  });
220
220
  }
221
- function J(e, t) {
222
- return v({
221
+ function $(e, t) {
222
+ return g({
223
223
  queryKey: ["hive-engine", "tokens-list", e, t],
224
224
  queryFn: async () => (await (await fetch(
225
225
  `${p.privateApiHost}/private-api/engine-api`,
@@ -243,18 +243,18 @@ function J(e, t) {
243
243
  )).json()).result
244
244
  });
245
245
  }
246
- function Ae(e) {
247
- const { data: t } = m(J());
248
- return g(
246
+ function ke(e) {
247
+ const { data: t } = h($());
248
+ return K(
249
249
  () => {
250
250
  var n;
251
251
  return {
252
252
  basic: [
253
- h.Points,
254
- h.Hive,
255
- h.HivePower,
256
- h.HiveDollar,
257
- h.Spk
253
+ m.Points,
254
+ m.Hive,
255
+ m.HivePower,
256
+ m.HiveDollar,
257
+ m.Spk
258
258
  ].filter((o) => o.toLowerCase().includes(e.toLowerCase())),
259
259
  external: Object.values(a).filter(
260
260
  (o) => o.toLowerCase().includes(e.toLowerCase())
@@ -267,7 +267,7 @@ function Ae(e) {
267
267
  [t, e]
268
268
  );
269
269
  }
270
- const $ = {
270
+ const G = {
271
271
  [a.BTC]: "m/44'/0'/0'/0/0",
272
272
  // Bitcoin (BIP44)
273
273
  [a.ETH]: "m/44'/60'/0'/0/0",
@@ -283,17 +283,17 @@ const $ = {
283
283
  [a.ATOM]: "m/44'/118'/0'/0/0"
284
284
  // Cosmos (BIP44)
285
285
  };
286
- function ke(e, t) {
287
- const { data: n } = S(e), o = b(), s = u({
286
+ function Ke(e, t) {
287
+ const { data: n } = P(e), o = v(), s = u({
288
288
  mutationKey: ["ecency-wallets", "create-wallet", e, t],
289
289
  mutationFn: async () => {
290
290
  if (!n)
291
291
  throw new Error("[Ecency][Wallets] - No seed to create a wallet");
292
- const i = P(t), c = await (i == null ? void 0 : i.getDerivedPrivateKey({
292
+ const i = T(t), c = await (i == null ? void 0 : i.getDerivedPrivateKey({
293
293
  mnemonic: n,
294
- hdPath: $[t]
294
+ hdPath: G[t]
295
295
  }));
296
- await q(1e3);
296
+ await M(1e3);
297
297
  const d = await (i == null ? void 0 : i.getNewAddress({
298
298
  privateKey: c
299
299
  }));
@@ -311,17 +311,17 @@ function ke(e, t) {
311
311
  (c) => new Map(c ? Array.from(c.entries()) : []).set(i.currency, i)
312
312
  );
313
313
  }
314
- }), r = g(() => {
314
+ }), r = R(() => {
315
315
  }, []);
316
316
  return {
317
317
  createWallet: s,
318
318
  importWallet: r
319
319
  };
320
320
  }
321
- function G(e) {
322
- const { data: t } = m({
321
+ function V(e) {
322
+ const { data: t } = h({
323
323
  queryKey: ["ecency-wallets", "wallets", e]
324
- }), { data: n } = I(e);
324
+ }), { data: n } = J(e);
325
325
  return u({
326
326
  mutationKey: ["ecency-wallets", "create-account-with-wallets", e],
327
327
  mutationFn: ({ currency: o, address: s }) => fetch(p.privateApiHost + "/private-api/wallets-add", {
@@ -350,7 +350,7 @@ function G(e) {
350
350
  })
351
351
  });
352
352
  }
353
- function A() {
353
+ function O() {
354
354
  return u({
355
355
  mutationKey: ["ecency-wallets", "check-wallet-existence"],
356
356
  mutationFn: async ({ address: e, currency: t }) => (await (await fetch(
@@ -368,11 +368,11 @@ function A() {
368
368
  )).json()).length === 0
369
369
  });
370
370
  }
371
- const Ke = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
371
+ const Re = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
372
372
  __proto__: null,
373
- useCheckWalletExistence: A,
374
- useCreateAccountWithWallets: G
375
- }, Symbol.toStringTag, { value: "Module" })), V = {
373
+ useCheckWalletExistence: O,
374
+ useCreateAccountWithWallets: V
375
+ }, Symbol.toStringTag, { value: "Module" })), U = {
376
376
  [a.BTC]: ["m/84'/0'/0'/0/0"],
377
377
  [a.ETH]: ["m/84'/60'/0'/0/0"],
378
378
  // its not working for Trust, Exodus, todo: check others below
@@ -383,8 +383,8 @@ const Ke = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
383
383
  // Disabled
384
384
  [a.ATOM]: ["m/84'/118'/0'/0'/0"]
385
385
  };
386
- async function U(e, t, n) {
387
- for (const o of V[n] || [])
386
+ async function z(e, t, n) {
387
+ for (const o of U[n] || [])
388
388
  try {
389
389
  const s = await t.getDerivedPrivateKey({
390
390
  mnemonic: e,
@@ -399,17 +399,17 @@ async function U(e, t, n) {
399
399
  }
400
400
  return [];
401
401
  }
402
- function Re(e, t) {
403
- const n = b(), { mutateAsync: o } = A();
402
+ function Ce(e, t) {
403
+ const n = v(), { mutateAsync: o } = O();
404
404
  return u({
405
405
  mutationKey: ["ecency-wallets", "import-wallet", e, t],
406
406
  mutationFn: async ({ privateKeyOrSeed: s }) => {
407
- const r = P(t);
407
+ const r = T(t);
408
408
  if (!r)
409
409
  throw new Error("Cannot find token for this currency");
410
410
  const i = s.split(" ").length === 12;
411
411
  let c, d = s;
412
- if (i ? [d, c] = await U(
412
+ if (i ? [d, c] = await z(
413
413
  s,
414
414
  r,
415
415
  t
@@ -447,7 +447,7 @@ function Re(e, t) {
447
447
  }
448
448
  });
449
449
  }
450
- function z(e) {
450
+ function X(e) {
451
451
  let t = atob(e);
452
452
  if (t[0] === "{")
453
453
  return JSON.parse(t);
@@ -457,13 +457,13 @@ const w = (e) => {
457
457
  const t = p.storage.getItem(
458
458
  p.storagePrefix + "_user_" + e
459
459
  );
460
- return z(JSON.parse(t));
460
+ return X(JSON.parse(t));
461
461
  } catch (t) {
462
462
  console.error(t);
463
463
  return;
464
464
  }
465
- }, X = (e) => w(e) && w(e).accessToken, Y = (e) => w(e) && w(e).postingKey;
466
- function Z(e = [], t, n) {
465
+ }, Y = (e) => w(e) && w(e).accessToken, Z = (e) => w(e) && w(e).postingKey;
466
+ function ee(e = [], t, n) {
467
467
  return u({
468
468
  mutationKey: [...e, t],
469
469
  mutationFn: async (o) => {
@@ -471,7 +471,7 @@ function Z(e = [], t, n) {
471
471
  throw new Error(
472
472
  "[Core][Broadcast] Attempted to call broadcast API with anon user"
473
473
  );
474
- const s = Y(t);
474
+ const s = Z(t);
475
475
  if (s) {
476
476
  const i = l.fromString(s);
477
477
  return p.hiveClient.broadcast.sendOperations(
@@ -479,9 +479,9 @@ function Z(e = [], t, n) {
479
479
  i
480
480
  );
481
481
  }
482
- let r = X(t);
482
+ let r = Y(t);
483
483
  if (r)
484
- return (await new T.Client({
484
+ return (await new b.Client({
485
485
  accessToken: r
486
486
  }).broadcast(n(o))).result;
487
487
  throw new Error(
@@ -490,18 +490,22 @@ function Z(e = [], t, n) {
490
490
  }
491
491
  });
492
492
  }
493
- function ee(e) {
494
- return Z(
493
+ function te(e) {
494
+ return ee(
495
495
  ["accounts", "update"],
496
496
  e,
497
- (t) => [
497
+ ({
498
+ profile: t,
499
+ tokens: n
500
+ }) => [
498
501
  [
499
502
  "account_update2",
500
503
  {
501
504
  account: e,
502
505
  json_metadata: "",
503
506
  posting_json_metadata: JSON.stringify({
504
- profile: { ...t, version: 2 }
507
+ profile: { ...t, version: 2 },
508
+ tokens: n
505
509
  }),
506
510
  extensions: []
507
511
  }
@@ -509,24 +513,24 @@ function ee(e) {
509
513
  ]
510
514
  );
511
515
  }
512
- function Ce(e) {
513
- const { mutateAsync: t } = ee(e);
516
+ function He(e) {
517
+ const { mutateAsync: t } = te(e);
514
518
  return u({
515
519
  mutationKey: ["ecency-wallets", "save-wallet-to-metadata", e],
516
520
  mutationFn: ({
517
521
  wallets: n
518
- }) => t(
519
- Array.from(n.entries() ?? []).reduce(
520
- (o, [s, r]) => ({
521
- ...o,
522
- [s]: r.address
523
- }),
524
- {}
525
- )
526
- )
522
+ }) => t({
523
+ profile: {},
524
+ tokens: Array.from(n.entries() ?? []).map(([o, s]) => ({
525
+ symbol: o,
526
+ meta: {
527
+ address: s.address
528
+ }
529
+ }))
530
+ })
527
531
  });
528
532
  }
529
- function He(e) {
533
+ function Ne(e) {
530
534
  return u({
531
535
  mutationKey: ["operations", "sign", e],
532
536
  mutationFn: ({
@@ -536,14 +540,14 @@ function He(e) {
536
540
  if (!e)
537
541
  throw new Error("[Operations][Sign] – cannot sign op with anon user");
538
542
  let o;
539
- return n.split(" ").length === 12 ? o = l.fromLogin(e, n, "active") : B.isWif(n) ? o = l.fromString(n) : o = l.from(n), p.hiveClient.broadcast.sendOperations(
543
+ return n.split(" ").length === 12 ? o = l.fromLogin(e, n, "active") : E.isWif(n) ? o = l.fromString(n) : o = l.from(n), p.hiveClient.broadcast.sendOperations(
540
544
  [t],
541
545
  o
542
546
  );
543
547
  }
544
548
  });
545
549
  }
546
- const te = (e, t, n, o = null) => new Promise((s, r) => {
550
+ const ne = (e, t, n, o = null) => new Promise((s, r) => {
547
551
  var i;
548
552
  (i = window.hive_keychain) == null || i.requestBroadcast(
549
553
  e,
@@ -555,7 +559,7 @@ const te = (e, t, n, o = null) => new Promise((s, r) => {
555
559
  o
556
560
  );
557
561
  });
558
- function Ne(e, t = "Active") {
562
+ function je(e, t = "Active") {
559
563
  return u({
560
564
  mutationKey: ["operations", "sign-keychain", e],
561
565
  mutationFn: ({ operation: n }) => {
@@ -563,35 +567,35 @@ function Ne(e, t = "Active") {
563
567
  throw new Error(
564
568
  "[SDK][Keychain] – cannot sign operation with anon user"
565
569
  );
566
- return te(e, [n], t);
570
+ return ne(e, [n], t);
567
571
  }
568
572
  });
569
573
  }
570
- function je(e = "/") {
574
+ function De(e = "/") {
571
575
  return u({
572
576
  mutationKey: ["operations", "sign-hivesigner", e],
573
- mutationFn: async ({ operation: t }) => T.sendOperation(t, { callback: e }, () => {
577
+ mutationFn: async ({ operation: t }) => b.sendOperation(t, { callback: e }, () => {
574
578
  })
575
579
  });
576
580
  }
577
581
  export {
578
- h as EcencyWalletBasicTokens,
582
+ m as EcencyWalletBasicTokens,
579
583
  a as EcencyWalletCurrency,
580
- Ke as EcencyWalletsPrivateApi,
581
- q as delay,
582
- Oe as getAccountPointsQueryOptions,
583
- P as getWallet,
584
- Te as mnemonicToSeedBip39,
585
- ee as useAccountUpdate,
586
- Se as useCoinGeckoPriceQuery,
587
- Ae as useGetAllTokensListQuery,
588
- Pe as useGetExternalWalletBalanceQuery,
589
- I as useHiveKeysQuery,
590
- Re as useImportWallet,
591
- Ce as useSaveWalletInformationToMetadata,
592
- S as useSeedPhrase,
593
- je as useSignOperationByHivesigner,
594
- He as useSignOperationByKey,
595
- Ne as useSignOperationByKeychain,
596
- ke as useWalletCreate
584
+ Re as EcencyWalletsPrivateApi,
585
+ M as delay,
586
+ Ae as getAccountPointsQueryOptions,
587
+ T as getWallet,
588
+ Pe as mnemonicToSeedBip39,
589
+ te as useAccountUpdate,
590
+ Oe as useCoinGeckoPriceQuery,
591
+ ke as useGetAllTokensListQuery,
592
+ Se as useGetExternalWalletBalanceQuery,
593
+ J as useHiveKeysQuery,
594
+ Ce as useImportWallet,
595
+ He as useSaveWalletInformationToMetadata,
596
+ P as useSeedPhrase,
597
+ De as useSignOperationByHivesigner,
598
+ Ne as useSignOperationByKey,
599
+ je as useSignOperationByKeychain,
600
+ Ke as useWalletCreate
597
601
  };
@@ -1 +1,9 @@
1
- export declare function useAccountUpdate(username: string): import('@tanstack/react-query').UseMutationResult<any, Error, any, unknown>;
1
+ export declare function useAccountUpdate(username: string): import('@tanstack/react-query').UseMutationResult<any, Error, {
2
+ profile: Record<string, any>;
3
+ tokens: {
4
+ symbol: string;
5
+ meta: {
6
+ address: string;
7
+ };
8
+ }[];
9
+ }, unknown>;
@@ -1,2 +1,9 @@
1
1
  import { EcencyWalletBasicTokens } from '../enums';
2
- export declare function useGetAccountWalletListQuery(username: string): import('@tanstack/react-query').UseQueryResult<EcencyWalletBasicTokens[], Error>;
2
+ export declare function getAccountWalletListQueryOptions(username: string): import('@tanstack/query-core').OmitKeyof<import('@tanstack/react-query').UseQueryOptions<EcencyWalletBasicTokens[], Error, EcencyWalletBasicTokens[], string[]>, "queryFn"> & {
3
+ queryFn?: import('@tanstack/query-core').QueryFunction<EcencyWalletBasicTokens[], string[], never> | undefined;
4
+ } & {
5
+ queryKey: string[] & {
6
+ [dataTagSymbol]: EcencyWalletBasicTokens[];
7
+ [dataTagErrorSymbol]: Error;
8
+ };
9
+ };
@@ -1,5 +1,5 @@
1
1
  import { EcencyWalletBasicTokens, EcencyWalletCurrency } from '../enums';
2
- export declare function useGetAllTokensListQuery(query: string): () => {
2
+ export declare function useGetAllTokensListQuery(query: string): {
3
3
  basic: EcencyWalletBasicTokens[];
4
4
  external: EcencyWalletCurrency[];
5
5
  layer2: string[];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ecency/sdk",
3
3
  "private": false,
4
- "version": "1.0.20",
4
+ "version": "1.0.22",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "main": "./dist/ecency-sdk.umd.js",