@ecency/sdk 1.0.24 → 1.0.25

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,45 +1,68 @@
1
- import { useMemo as K, useCallback as C } from "react";
2
- import { useQuery as w, queryOptions as f, useQueryClient as v, useMutation as l } from "@tanstack/react-query";
3
- import { BtcWallet as R } 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 _ } 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 F } from "@okxweb3/coin-aptos";
10
- import L from "bip39";
11
- import { Client as x, PrivateKey as u, cryptoUtils as E } from "@hiveio/dhive";
12
- import { LRUCache as q } from "lru-cache";
13
- import b from "hivesigner";
14
- var a = /* @__PURE__ */ ((t) => (t.BTC = "BTC", t.ETH = "ETH", t.APT = "APT", t.ATOM = "ATOM", t.TON = "TON", t.TRON = "TRX", t.SOL = "SOL", t))(a || {}), d = /* @__PURE__ */ ((t) => (t.Points = "POINTS", t.HivePower = "HP", t.Hive = "HIVE", t.HiveDollar = "HBD", t.Spk = "SPK", t))(d || {});
15
- function B(t) {
16
- return new Promise((e) => setTimeout(e, t));
1
+ var C = Object.defineProperty;
2
+ var R = (e, t, n) => t in e ? C(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var v = (e, t, n) => R(e, typeof t != "symbol" ? t + "" : t, n);
4
+ import { useMemo as H, useCallback as N } from "react";
5
+ import { useQuery as w, queryOptions as f, useQueryClient as b, useMutation as l } from "@tanstack/react-query";
6
+ import { BtcWallet as _ } from "@okxweb3/coin-bitcoin";
7
+ import { EthWallet as j } from "@okxweb3/coin-ethereum";
8
+ import { TrxWallet as D } from "@okxweb3/coin-tron";
9
+ import { TonWallet as F } from "@okxweb3/coin-ton";
10
+ import { SolWallet as E } from "@okxweb3/coin-solana";
11
+ import { AtomWallet as L } from "@okxweb3/coin-cosmos";
12
+ import { AptosWallet as x } from "@okxweb3/coin-aptos";
13
+ import q from "bip39";
14
+ import { Client as M, PrivateKey as u, cryptoUtils as B } from "@hiveio/dhive";
15
+ import { LRUCache as I } from "lru-cache";
16
+ import T from "hivesigner";
17
+ 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 || {}), d = /* @__PURE__ */ ((e) => (e.Points = "POINTS", e.HivePower = "HP", e.Hive = "HIVE", e.HiveDollar = "HBD", e.Spk = "SPK", e))(d || {});
18
+ function Q(e) {
19
+ return new Promise((t) => setTimeout(t, e));
17
20
  }
18
- function T(t) {
19
- switch (t) {
21
+ function P(e) {
22
+ switch (e) {
20
23
  case a.BTC:
21
- return new R();
24
+ return new _();
22
25
  case a.ETH:
23
- return new H();
26
+ return new j();
24
27
  case a.TRON:
25
- return new N();
28
+ return new D();
26
29
  case a.TON:
27
- return new _();
30
+ return new F();
28
31
  case a.SOL:
29
- return new j();
32
+ return new E();
30
33
  case a.ATOM:
31
- return new D();
34
+ return new L();
32
35
  case a.APT:
33
- return new F();
36
+ return new x();
34
37
  default:
35
38
  return;
36
39
  }
37
40
  }
41
+ class W {
42
+ constructor() {
43
+ v(this, "length", 0);
44
+ }
45
+ clear() {
46
+ throw new Error("Method not implemented.");
47
+ }
48
+ getItem(t) {
49
+ return this[t];
50
+ }
51
+ key(t) {
52
+ return Object.keys(this)[t];
53
+ }
54
+ removeItem(t) {
55
+ delete this[t];
56
+ }
57
+ setItem(t, n) {
58
+ this[t] = n;
59
+ }
60
+ }
38
61
  const p = {
39
62
  privateApiHost: "https://ecency.com",
40
- storage: localStorage,
63
+ storage: typeof window > "u" ? new W() : window.localStorage,
41
64
  storagePrefix: "ecency",
42
- hiveClient: new x(
65
+ hiveClient: new M(
43
66
  [
44
67
  "https://api.hive.blog",
45
68
  "https://api.deathwing.me",
@@ -61,19 +84,19 @@ const p = {
61
84
  ),
62
85
  heliusApiKey: "fb1e2935-f911-4b1d-8e1c-3863f6879d42"
63
86
  };
64
- function Tt(t, e) {
87
+ function ke(e, t) {
65
88
  return w({
66
- queryKey: ["ecency-wallets", "external-wallet-balance", t, e],
89
+ queryKey: ["ecency-wallets", "external-wallet-balance", e, t],
67
90
  queryFn: async () => {
68
- switch (t) {
91
+ switch (e) {
69
92
  case a.BTC:
70
93
  const o = await (await fetch(
71
- `https://mempool.space/api/address/${e}`
94
+ `https://mempool.space/api/address/${t}`
72
95
  )).json();
73
96
  return (o.chain_stats.funded_txo_sum - o.chain_stats.spent_txo_sum) / 1e8;
74
97
  case a.ETH:
75
98
  return +(await (await fetch(
76
- `https://api.ethplorer.io/getAddressInfo/${e}?apiKey=freekey`
99
+ `https://api.ethplorer.io/getAddressInfo/${t}?apiKey=freekey`
77
100
  )).json()).ETH.balance;
78
101
  case a.SOL:
79
102
  return (await (await fetch(
@@ -84,7 +107,7 @@ function Tt(t, e) {
84
107
  jsonrpc: "2.0",
85
108
  id: "1",
86
109
  method: "getBalance",
87
- params: [e]
110
+ params: [t]
88
111
  }),
89
112
  headers: {
90
113
  "Content-Type": "application/json"
@@ -93,34 +116,34 @@ function Tt(t, e) {
93
116
  )).json()).result.value / 1e9;
94
117
  case a.TRON:
95
118
  return (await (await fetch(
96
- `https://api.trongrid.io/v1/accounts/${e}`
119
+ `https://api.trongrid.io/v1/accounts/${t}`
97
120
  )).json()).data[0].balance / 1e6;
98
121
  case a.TON:
99
122
  return (await (await fetch(
100
- `https://tonapi.io/v1/blockchain/getAccount?account=${e}`
123
+ `https://tonapi.io/v1/blockchain/getAccount?account=${t}`
101
124
  )).json()).balance / 1e9;
102
125
  case a.APT:
103
126
  const g = (await (await fetch(
104
- `https://fullnode.mainnet.aptoslabs.com/v1/accounts/${e}/resources`
127
+ `https://fullnode.mainnet.aptoslabs.com/v1/accounts/${t}/resources`
105
128
  )).json()).find(
106
- (k) => k.type.includes("coin::CoinStore")
129
+ (K) => K.type.includes("coin::CoinStore")
107
130
  );
108
131
  return g ? parseInt(g.data.coin.value) / 1e8 : 0;
109
132
  case a.ATOM:
110
133
  return +(await (await fetch(
111
- `https://rest.cosmos.directory/cosmoshub/auth/accounts/${e}`
134
+ `https://rest.cosmos.directory/cosmoshub/auth/accounts/${t}`
112
135
  )).json()).result.value.coins[0].amount / 1e6;
113
136
  }
114
137
  }
115
138
  });
116
139
  }
117
- function P(t) {
140
+ function O(e) {
118
141
  return w({
119
- queryKey: ["ecency-wallets", "seed", t],
120
- queryFn: async () => L.generateMnemonic(128)
142
+ queryKey: ["ecency-wallets", "seed", e],
143
+ queryFn: async () => q.generateMnemonic(128)
121
144
  });
122
145
  }
123
- const M = {
146
+ const J = {
124
147
  max: 500,
125
148
  // how long to live in ms
126
149
  ttl: 1e3 * 60 * 5,
@@ -128,96 +151,96 @@ const M = {
128
151
  allowStale: !1,
129
152
  updateAgeOnGet: !1,
130
153
  updateAgeOnHas: !1
131
- }, O = new q(M), m = Symbol("undefined"), Q = (t, e) => O.set(t, e === void 0 ? m : e), W = (t) => {
132
- const e = O.get(t);
133
- return e === m ? void 0 : e;
154
+ }, S = new I(J), m = Symbol("undefined"), $ = (e, t) => S.set(e, t === void 0 ? m : t), G = (e) => {
155
+ const t = S.get(e);
156
+ return t === m ? void 0 : t;
134
157
  };
135
- function Pt(t) {
158
+ function Ke(e) {
136
159
  return w({
137
- queryKey: ["ecency-wallets", "coingecko-price", t],
160
+ queryKey: ["ecency-wallets", "coingecko-price", e],
138
161
  queryFn: async () => {
139
- let e = t;
140
- switch (t) {
162
+ let t = e;
163
+ switch (e) {
141
164
  case a.BTC:
142
- e = "binance-wrapped-btc";
165
+ t = "binance-wrapped-btc";
143
166
  break;
144
167
  case a.ETH:
145
- e = "ethereum";
168
+ t = "ethereum";
146
169
  break;
147
170
  case a.SOL:
148
- e = "solana";
171
+ t = "solana";
149
172
  break;
150
173
  case a.TON:
151
- e = "trx";
174
+ t = "trx";
152
175
  break;
153
176
  default:
154
- e = t;
177
+ t = e;
155
178
  }
156
- let n = W("gecko"), o;
179
+ let n = G("gecko"), o;
157
180
  if (n)
158
181
  o = n;
159
182
  else {
160
- const i = await (await fetch(
183
+ const r = await (await fetch(
161
184
  "https://api.coingecko.com/api/v3/simple/price",
162
185
  {
163
186
  method: "POST",
164
187
  body: JSON.stringify({
165
188
  params: {
166
- ids: [e],
189
+ ids: [t],
167
190
  vs_currencies: "usd"
168
191
  }
169
192
  })
170
193
  }
171
194
  )).json();
172
- Q("gecko", i === void 0 ? m : i), o = i;
195
+ $("gecko", r === void 0 ? m : r), o = r;
173
196
  }
174
197
  return 1 / +o[Object.keys(o)[0]].usd;
175
198
  },
176
- enabled: !!t
199
+ enabled: !!e
177
200
  });
178
201
  }
179
- function I(t) {
180
- const { data: e } = P(t);
202
+ function U(e) {
203
+ const { data: t } = O(e);
181
204
  return w({
182
- queryKey: ["ecencу-wallets", "hive-keys", t, e],
205
+ queryKey: ["ecencу-wallets", "hive-keys", e, t],
183
206
  queryFn: async () => {
184
- if (!e)
207
+ if (!t)
185
208
  throw new Error("[Ecency][Wallets] - no seed to create Hive account");
186
- const n = u.fromLogin(t, e, "owner"), o = u.fromLogin(t, e, "active"), s = u.fromLogin(t, e, "posting"), r = u.fromLogin(t, e, "memo");
209
+ const n = u.fromLogin(e, t, "owner"), o = u.fromLogin(e, t, "active"), s = u.fromLogin(e, t, "posting"), i = u.fromLogin(e, t, "memo");
187
210
  return {
188
- username: t,
211
+ username: e,
189
212
  owner: n.toString(),
190
213
  active: o.toString(),
191
214
  posting: s.toString(),
192
- memo: r.toString(),
215
+ memo: i.toString(),
193
216
  ownerPubkey: n.createPublic().toString(),
194
217
  activePubkey: o.createPublic().toString(),
195
218
  postingPubkey: s.createPublic().toString(),
196
- memoPubkey: r.createPublic().toString()
219
+ memoPubkey: i.createPublic().toString()
197
220
  };
198
221
  }
199
222
  });
200
223
  }
201
- function Ot(t, e) {
224
+ function Ce(e, t) {
202
225
  return f({
203
- queryKey: ["ecency-wallets", "points", t, e],
226
+ queryKey: ["ecency-wallets", "points", e, t],
204
227
  queryFn: async () => await (await fetch(
205
228
  `${p.privateApiHost}/private-api/points`,
206
229
  {
207
230
  method: "POST",
208
231
  body: JSON.stringify({
209
- username: t.replace("@", "")
232
+ username: e.replace("@", "")
210
233
  })
211
234
  }
212
235
  )).json(),
213
236
  staleTime: 3e4,
214
237
  refetchOnMount: !0,
215
- enabled: !!t
238
+ enabled: !!e
216
239
  });
217
240
  }
218
- function J(t, e) {
241
+ function V(e, t) {
219
242
  return f({
220
- queryKey: ["hive-engine", "tokens-list", t, e],
243
+ queryKey: ["hive-engine", "tokens-list", e, t],
221
244
  queryFn: async () => (await (await fetch(
222
245
  `${p.privateApiHost}/private-api/engine-api`,
223
246
  {
@@ -229,8 +252,8 @@ function J(t, e) {
229
252
  contract: "market",
230
253
  table: "metrics",
231
254
  query: {
232
- symbol: e,
233
- account: t
255
+ symbol: t,
256
+ account: e
234
257
  }
235
258
  },
236
259
  id: 1
@@ -240,9 +263,9 @@ function J(t, e) {
240
263
  )).json()).result
241
264
  });
242
265
  }
243
- function St(t) {
244
- const { data: e } = w(J());
245
- return K(
266
+ function Re(e) {
267
+ const { data: t } = w(V());
268
+ return H(
246
269
  () => {
247
270
  var n;
248
271
  return {
@@ -252,19 +275,19 @@ function St(t) {
252
275
  d.HivePower,
253
276
  d.HiveDollar,
254
277
  d.Spk
255
- ].filter((o) => o.toLowerCase().includes(t.toLowerCase())),
278
+ ].filter((o) => o.toLowerCase().includes(e.toLowerCase())),
256
279
  external: Object.values(a).filter(
257
- (o) => o.toLowerCase().includes(t.toLowerCase())
280
+ (o) => o.toLowerCase().includes(e.toLowerCase())
258
281
  ),
259
- layer2: ((n = e == null ? void 0 : e.map(({ symbol: o }) => o)) == null ? void 0 : n.filter(
260
- (o) => o.toLowerCase().includes(t.toLowerCase())
282
+ layer2: ((n = t == null ? void 0 : t.map(({ symbol: o }) => o)) == null ? void 0 : n.filter(
283
+ (o) => o.toLowerCase().includes(e.toLowerCase())
261
284
  )) ?? []
262
285
  };
263
286
  },
264
- [e, t]
287
+ [t, e]
265
288
  );
266
289
  }
267
- const $ = {
290
+ const z = {
268
291
  [a.BTC]: "m/44'/0'/0'/0/0",
269
292
  // Bitcoin (BIP44)
270
293
  [a.ETH]: "m/44'/60'/0'/0/0",
@@ -280,54 +303,54 @@ const $ = {
280
303
  [a.ATOM]: "m/44'/118'/0'/0/0"
281
304
  // Cosmos (BIP44)
282
305
  };
283
- function At(t, e) {
284
- const { data: n } = P(t), o = v(), s = l({
285
- mutationKey: ["ecency-wallets", "create-wallet", t, e],
306
+ function He(e, t) {
307
+ const { data: n } = O(e), o = b(), s = l({
308
+ mutationKey: ["ecency-wallets", "create-wallet", e, t],
286
309
  mutationFn: async () => {
287
310
  if (!n)
288
311
  throw new Error("[Ecency][Wallets] - No seed to create a wallet");
289
- const i = T(e), c = await (i == null ? void 0 : i.getDerivedPrivateKey({
312
+ const r = P(t), c = await (r == null ? void 0 : r.getDerivedPrivateKey({
290
313
  mnemonic: n,
291
- hdPath: $[e]
314
+ hdPath: z[t]
292
315
  }));
293
- await B(1e3);
294
- const h = await (i == null ? void 0 : i.getNewAddress({
316
+ await Q(1e3);
317
+ const h = await (r == null ? void 0 : r.getNewAddress({
295
318
  privateKey: c
296
319
  }));
297
320
  return {
298
321
  privateKey: c,
299
322
  address: h.address,
300
323
  publicKey: h.publicKey,
301
- username: t,
302
- currency: e
324
+ username: e,
325
+ currency: t
303
326
  };
304
327
  },
305
- onSuccess: (i) => {
328
+ onSuccess: (r) => {
306
329
  o.setQueryData(
307
- ["ecency-wallets", "wallets", i.username],
308
- (c) => new Map(c ? Array.from(c.entries()) : []).set(i.currency, i)
330
+ ["ecency-wallets", "wallets", r.username],
331
+ (c) => new Map(c ? Array.from(c.entries()) : []).set(r.currency, r)
309
332
  );
310
333
  }
311
- }), r = C(() => {
334
+ }), i = N(() => {
312
335
  }, []);
313
336
  return {
314
337
  createWallet: s,
315
- importWallet: r
338
+ importWallet: i
316
339
  };
317
340
  }
318
- function G(t) {
319
- const { data: e } = w({
320
- queryKey: ["ecency-wallets", "wallets", t]
321
- }), { data: n } = I(t);
341
+ function X(e) {
342
+ const { data: t } = w({
343
+ queryKey: ["ecency-wallets", "wallets", e]
344
+ }), { data: n } = U(e);
322
345
  return l({
323
- mutationKey: ["ecency-wallets", "create-account-with-wallets", t],
346
+ mutationKey: ["ecency-wallets", "create-account-with-wallets", e],
324
347
  mutationFn: ({ currency: o, address: s }) => fetch(p.privateApiHost + "/private-api/wallets-add", {
325
348
  method: "POST",
326
349
  headers: {
327
350
  "Content-Type": "application/json"
328
351
  },
329
352
  body: JSON.stringify({
330
- username: t,
353
+ username: e,
331
354
  token: o,
332
355
  address: s,
333
356
  meta: {
@@ -335,10 +358,10 @@ function G(t) {
335
358
  activePublicKey: n == null ? void 0 : n.activePubkey,
336
359
  postingPublicKey: n == null ? void 0 : n.postingPubkey,
337
360
  memoPublicKey: n == null ? void 0 : n.memoPubkey,
338
- ...Array.from((e == null ? void 0 : e.entries()) ?? []).reduce(
339
- (r, [i, c]) => ({
340
- ...r,
341
- [i]: c.address
361
+ ...Array.from((t == null ? void 0 : t.entries()) ?? []).reduce(
362
+ (i, [r, c]) => ({
363
+ ...i,
364
+ [r]: c.address
342
365
  }),
343
366
  {}
344
367
  )
@@ -347,10 +370,10 @@ function G(t) {
347
370
  })
348
371
  });
349
372
  }
350
- function S() {
373
+ function A() {
351
374
  return l({
352
375
  mutationKey: ["ecency-wallets", "check-wallet-existence"],
353
- mutationFn: async ({ address: t, currency: e }) => (await (await fetch(
376
+ mutationFn: async ({ address: e, currency: t }) => (await (await fetch(
354
377
  p.privateApiHost + "/private-api/wallets-exist",
355
378
  {
356
379
  method: "POST",
@@ -358,18 +381,18 @@ function S() {
358
381
  "Content-Type": "application/json"
359
382
  },
360
383
  body: JSON.stringify({
361
- address: t,
362
- token: e
384
+ address: e,
385
+ token: t
363
386
  })
364
387
  }
365
388
  )).json()).length === 0
366
389
  });
367
390
  }
368
- const kt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
391
+ const Ne = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
369
392
  __proto__: null,
370
- useCheckWalletExistence: S,
371
- useCreateAccountWithWallets: G
372
- }, Symbol.toStringTag, { value: "Module" })), U = {
393
+ useCheckWalletExistence: A,
394
+ useCreateAccountWithWallets: X
395
+ }, Symbol.toStringTag, { value: "Module" })), Y = {
373
396
  [a.BTC]: ["m/84'/0'/0'/0/0"],
374
397
  [a.ETH]: ["m/84'/60'/0'/0/0"],
375
398
  // its not working for Trust, Exodus, todo: check others below
@@ -380,37 +403,37 @@ const kt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
380
403
  // Disabled
381
404
  [a.ATOM]: ["m/84'/118'/0'/0'/0"]
382
405
  };
383
- async function V(t, e, n) {
384
- for (const o of U[n] || [])
406
+ async function Z(e, t, n) {
407
+ for (const o of Y[n] || [])
385
408
  try {
386
- const s = await e.getDerivedPrivateKey({
387
- mnemonic: t,
409
+ const s = await t.getDerivedPrivateKey({
410
+ mnemonic: e,
388
411
  hdPath: o
389
- }), r = await e.getNewAddress({
412
+ }), i = await t.getNewAddress({
390
413
  privateKey: s,
391
414
  addressType: n === a.BTC ? "segwit_native" : void 0
392
415
  });
393
- return [s.toString(), r.address];
416
+ return [s.toString(), i.address];
394
417
  } catch {
395
418
  return [];
396
419
  }
397
420
  return [];
398
421
  }
399
- function Kt(t, e) {
400
- const n = v(), { mutateAsync: o } = S();
422
+ function _e(e, t) {
423
+ const n = b(), { mutateAsync: o } = A();
401
424
  return l({
402
- mutationKey: ["ecency-wallets", "import-wallet", t, e],
425
+ mutationKey: ["ecency-wallets", "import-wallet", e, t],
403
426
  mutationFn: async ({ privateKeyOrSeed: s }) => {
404
- const r = T(e);
405
- if (!r)
427
+ const i = P(t);
428
+ if (!i)
406
429
  throw new Error("Cannot find token for this currency");
407
- const i = s.split(" ").length === 12;
430
+ const r = s.split(" ").length === 12;
408
431
  let c, h = s;
409
- if (i ? [h, c] = await V(
432
+ if (r ? [h, c] = await Z(
410
433
  s,
411
- r,
412
- e
413
- ) : c = (await r.getNewAddress({
434
+ i,
435
+ t
436
+ ) : c = (await i.getNewAddress({
414
437
  privateKey: s
415
438
  })).address, !c || !s)
416
439
  throw new Error(
@@ -418,7 +441,7 @@ function Kt(t, e) {
418
441
  );
419
442
  if (!await o({
420
443
  address: c,
421
- currency: e
444
+ currency: t
422
445
  }))
423
446
  throw new Error(
424
447
  "This wallet has already in use by Hive account. Please, try another one"
@@ -429,57 +452,57 @@ function Kt(t, e) {
429
452
  publicKey: ""
430
453
  };
431
454
  },
432
- onSuccess: ({ privateKey: s, publicKey: r, address: i }) => {
455
+ onSuccess: ({ privateKey: s, publicKey: i, address: r }) => {
433
456
  n.setQueryData(
434
- ["ecency-wallets", "wallets", t],
435
- (c) => new Map(c ? Array.from(c.entries()) : []).set(e, {
457
+ ["ecency-wallets", "wallets", e],
458
+ (c) => new Map(c ? Array.from(c.entries()) : []).set(t, {
436
459
  privateKey: s,
437
- publicKey: r,
438
- address: i,
439
- username: t,
440
- currency: e,
460
+ publicKey: i,
461
+ address: r,
462
+ username: e,
463
+ currency: t,
441
464
  custom: !0
442
465
  })
443
466
  );
444
467
  }
445
468
  });
446
469
  }
447
- function z(t) {
448
- let e = atob(t);
449
- if (e[0] === "{")
450
- return JSON.parse(e);
470
+ function ee(e) {
471
+ let t = atob(e);
472
+ if (t[0] === "{")
473
+ return JSON.parse(t);
451
474
  }
452
- const y = (t) => {
475
+ const y = (e) => {
453
476
  try {
454
- const e = p.storage.getItem(
455
- p.storagePrefix + "_user_" + t
477
+ const t = p.storage.getItem(
478
+ p.storagePrefix + "_user_" + e
456
479
  );
457
- return z(JSON.parse(e));
458
- } catch (e) {
459
- console.error(e);
480
+ return ee(JSON.parse(t));
481
+ } catch (t) {
482
+ console.error(t);
460
483
  return;
461
484
  }
462
- }, X = (t) => y(t) && y(t).accessToken, Y = (t) => y(t) && y(t).postingKey;
463
- function Z(t = [], e, n) {
485
+ }, te = (e) => y(e) && y(e).accessToken, ne = (e) => y(e) && y(e).postingKey;
486
+ function oe(e = [], t, n) {
464
487
  return l({
465
- mutationKey: [...t, e],
488
+ mutationKey: [...e, t],
466
489
  mutationFn: async (o) => {
467
- if (!e)
490
+ if (!t)
468
491
  throw new Error(
469
492
  "[Core][Broadcast] Attempted to call broadcast API with anon user"
470
493
  );
471
- const s = Y(e);
494
+ const s = ne(t);
472
495
  if (s) {
473
- const i = u.fromString(s);
496
+ const r = u.fromString(s);
474
497
  return p.hiveClient.broadcast.sendOperations(
475
498
  n(o),
476
- i
499
+ r
477
500
  );
478
501
  }
479
- let r = X(e);
480
- if (r)
481
- return (await new b.Client({
482
- accessToken: r
502
+ let i = te(t);
503
+ if (i)
504
+ return (await new T.Client({
505
+ accessToken: i
483
506
  }).broadcast(n(o))).result;
484
507
  throw new Error(
485
508
  "[SDK][Broadcast] – cannot broadcast w/o posting key or token"
@@ -487,21 +510,21 @@ function Z(t = [], e, n) {
487
510
  }
488
511
  });
489
512
  }
490
- function tt(t) {
491
- return Z(
513
+ function ae(e) {
514
+ return oe(
492
515
  ["accounts", "update"],
493
- t,
516
+ e,
494
517
  ({
495
- profile: e,
518
+ profile: t,
496
519
  tokens: n
497
520
  }) => [
498
521
  [
499
522
  "account_update2",
500
523
  {
501
- account: t,
524
+ account: e,
502
525
  json_metadata: "",
503
526
  posting_json_metadata: JSON.stringify({
504
- profile: { ...e, version: 2 },
527
+ profile: { ...t, version: 2 },
505
528
  tokens: n
506
529
  }),
507
530
  extensions: []
@@ -510,31 +533,31 @@ function tt(t) {
510
533
  ]
511
534
  );
512
535
  }
513
- function Ct(t) {
536
+ function je(e) {
514
537
  return f({
515
- queryKey: ["get-account-full", t],
538
+ queryKey: ["get-account-full", e],
516
539
  queryFn: async () => {
517
- if (!t)
540
+ if (!e)
518
541
  throw new Error("[SDK] Username is empty");
519
- const e = await p.hiveClient.database.getAccounts([t]);
520
- if (!e[0])
542
+ const t = await p.hiveClient.database.getAccounts([e]);
543
+ if (!t[0])
521
544
  throw new Error("[SDK] No account with given username");
522
- const n = JSON.parse(e[0].posting_json_metadata).profile;
545
+ const n = JSON.parse(t[0].posting_json_metadata).profile;
523
546
  let o;
524
547
  try {
525
548
  o = await p.hiveClient.database.call(
526
549
  "get_follow_count",
527
- [t]
550
+ [e]
528
551
  );
529
552
  } catch {
530
553
  }
531
554
  const s = await p.hiveClient.call(
532
555
  "condenser_api",
533
556
  "get_account_reputations",
534
- [t, 1]
557
+ [e, 1]
535
558
  );
536
559
  return {
537
- ...e,
560
+ ...t,
538
561
  follow_stats: o,
539
562
  reputation: s[0].reputation,
540
563
  profile: {
@@ -543,29 +566,29 @@ function Ct(t) {
543
566
  }
544
567
  };
545
568
  },
546
- enabled: !!t,
569
+ enabled: !!e,
547
570
  staleTime: 6e4
548
571
  });
549
572
  }
550
- function Rt(t, e = 5, n = []) {
573
+ function De(e, t = 5, n = []) {
551
574
  return f({
552
- queryKey: ["accounts", "search", t, n],
553
- enabled: !!t,
575
+ queryKey: ["accounts", "search", e, n],
576
+ enabled: !!e,
554
577
  queryFn: async () => (await p.hiveClient.database.call(
555
578
  "lookup_accounts",
556
- [t, e]
579
+ [e, t]
557
580
  )).filter(
558
581
  (s) => n.length > 0 ? !n.includes(s) : !0
559
582
  )
560
583
  });
561
584
  }
562
- function Ht(t) {
563
- const { mutateAsync: e } = tt(t);
585
+ function Fe(e) {
586
+ const { mutateAsync: t } = ae(e);
564
587
  return l({
565
- mutationKey: ["ecency-wallets", "save-wallet-to-metadata", t],
588
+ mutationKey: ["ecency-wallets", "save-wallet-to-metadata", e],
566
589
  mutationFn: ({
567
590
  wallets: n
568
- }) => e({
591
+ }) => t({
569
592
  profile: {},
570
593
  tokens: Array.from(n.entries() ?? []).map(([o, s]) => ({
571
594
  symbol: o,
@@ -577,71 +600,71 @@ function Ht(t) {
577
600
  })
578
601
  });
579
602
  }
580
- function Nt(t) {
603
+ function Ee(e) {
581
604
  return l({
582
- mutationKey: ["operations", "sign", t],
605
+ mutationKey: ["operations", "sign", e],
583
606
  mutationFn: ({
584
- operation: e,
607
+ operation: t,
585
608
  keyOrSeed: n
586
609
  }) => {
587
- if (!t)
610
+ if (!e)
588
611
  throw new Error("[Operations][Sign] – cannot sign op with anon user");
589
612
  let o;
590
- return n.split(" ").length === 12 ? o = u.fromLogin(t, n, "active") : E.isWif(n) ? o = u.fromString(n) : o = u.from(n), p.hiveClient.broadcast.sendOperations(
591
- [e],
613
+ return n.split(" ").length === 12 ? o = u.fromLogin(e, n, "active") : B.isWif(n) ? o = u.fromString(n) : o = u.from(n), p.hiveClient.broadcast.sendOperations(
614
+ [t],
592
615
  o
593
616
  );
594
617
  }
595
618
  });
596
619
  }
597
- const et = (t, e, n, o = null) => new Promise((s, r) => {
598
- var i;
599
- (i = window.hive_keychain) == null || i.requestBroadcast(
600
- t,
620
+ const se = (e, t, n, o = null) => new Promise((s, i) => {
621
+ var r;
622
+ (r = window.hive_keychain) == null || r.requestBroadcast(
601
623
  e,
624
+ t,
602
625
  n,
603
626
  (c) => {
604
- c.success || r({ message: "Operation cancelled" }), s(c);
627
+ c.success || i({ message: "Operation cancelled" }), s(c);
605
628
  },
606
629
  o
607
630
  );
608
631
  });
609
- function _t(t, e = "Active") {
632
+ function Le(e, t = "Active") {
610
633
  return l({
611
- mutationKey: ["operations", "sign-keychain", t],
634
+ mutationKey: ["operations", "sign-keychain", e],
612
635
  mutationFn: ({ operation: n }) => {
613
- if (!t)
636
+ if (!e)
614
637
  throw new Error(
615
638
  "[SDK][Keychain] – cannot sign operation with anon user"
616
639
  );
617
- return et(t, [n], e);
640
+ return se(e, [n], t);
618
641
  }
619
642
  });
620
643
  }
621
- function jt(t = "/") {
644
+ function xe(e = "/") {
622
645
  return l({
623
- mutationKey: ["operations", "sign-hivesigner", t],
624
- mutationFn: async ({ operation: e }) => b.sendOperation(e, { callback: t }, () => {
646
+ mutationKey: ["operations", "sign-hivesigner", e],
647
+ mutationFn: async ({ operation: t }) => T.sendOperation(t, { callback: e }, () => {
625
648
  })
626
649
  });
627
650
  }
628
651
  export {
629
652
  d as EcencyWalletBasicTokens,
630
653
  a as EcencyWalletCurrency,
631
- kt as EcencyWalletsPrivateApi,
632
- Ct as getAccountFullQueryOptions,
633
- Ot as getAccountPointsQueryOptions,
634
- Rt as getSearchAccountsByUsernameQueryOptions,
635
- tt as useAccountUpdate,
636
- Pt as useCoinGeckoPriceQuery,
637
- St as useGetAllTokensListQuery,
638
- Tt as useGetExternalWalletBalanceQuery,
639
- I as useHiveKeysQuery,
640
- Kt as useImportWallet,
641
- Ht as useSaveWalletInformationToMetadata,
642
- P as useSeedPhrase,
643
- jt as useSignOperationByHivesigner,
644
- Nt as useSignOperationByKey,
645
- _t as useSignOperationByKeychain,
646
- At as useWalletCreate
654
+ Ne as EcencyWalletsPrivateApi,
655
+ je as getAccountFullQueryOptions,
656
+ Ce as getAccountPointsQueryOptions,
657
+ De as getSearchAccountsByUsernameQueryOptions,
658
+ ae as useAccountUpdate,
659
+ Ke as useCoinGeckoPriceQuery,
660
+ Re as useGetAllTokensListQuery,
661
+ ke as useGetExternalWalletBalanceQuery,
662
+ U as useHiveKeysQuery,
663
+ _e as useImportWallet,
664
+ Fe as useSaveWalletInformationToMetadata,
665
+ O as useSeedPhrase,
666
+ xe as useSignOperationByHivesigner,
667
+ Ee as useSignOperationByKey,
668
+ Le as useSignOperationByKeychain,
669
+ He as useWalletCreate
647
670
  };
@@ -0,0 +1,9 @@
1
+ export declare class MockStorage implements Storage {
2
+ [name: string]: any;
3
+ length: number;
4
+ clear(): void;
5
+ getItem(key: string): string | null;
6
+ key(index: number): string | null;
7
+ removeItem(key: string): void;
8
+ setItem(key: string, value: string): void;
9
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ecency/sdk",
3
3
  "private": false,
4
- "version": "1.0.24",
4
+ "version": "1.0.25",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "main": "./dist/ecency-sdk.umd.js",