@ecency/sdk 1.0.19 → 1.0.20

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