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