@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.
package/dist/ecency-sdk.es.js
CHANGED
@@ -1,45 +1,68 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
import {
|
5
|
-
import {
|
6
|
-
import {
|
7
|
-
import {
|
8
|
-
import {
|
9
|
-
import {
|
10
|
-
import
|
11
|
-
import {
|
12
|
-
import {
|
13
|
-
import
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
19
|
-
switch (
|
21
|
+
function P(e) {
|
22
|
+
switch (e) {
|
20
23
|
case a.BTC:
|
21
|
-
return new
|
24
|
+
return new _();
|
22
25
|
case a.ETH:
|
23
|
-
return new
|
26
|
+
return new j();
|
24
27
|
case a.TRON:
|
25
|
-
return new
|
28
|
+
return new D();
|
26
29
|
case a.TON:
|
27
|
-
return new
|
30
|
+
return new F();
|
28
31
|
case a.SOL:
|
29
|
-
return new
|
32
|
+
return new E();
|
30
33
|
case a.ATOM:
|
31
|
-
return new
|
34
|
+
return new L();
|
32
35
|
case a.APT:
|
33
|
-
return new
|
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
|
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
|
87
|
+
function ke(e, t) {
|
65
88
|
return w({
|
66
|
-
queryKey: ["ecency-wallets", "external-wallet-balance",
|
89
|
+
queryKey: ["ecency-wallets", "external-wallet-balance", e, t],
|
67
90
|
queryFn: async () => {
|
68
|
-
switch (
|
91
|
+
switch (e) {
|
69
92
|
case a.BTC:
|
70
93
|
const o = await (await fetch(
|
71
|
-
`https://mempool.space/api/address/${
|
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/${
|
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: [
|
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/${
|
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=${
|
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/${
|
127
|
+
`https://fullnode.mainnet.aptoslabs.com/v1/accounts/${t}/resources`
|
105
128
|
)).json()).find(
|
106
|
-
(
|
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/${
|
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
|
140
|
+
function O(e) {
|
118
141
|
return w({
|
119
|
-
queryKey: ["ecency-wallets", "seed",
|
120
|
-
queryFn: async () =>
|
142
|
+
queryKey: ["ecency-wallets", "seed", e],
|
143
|
+
queryFn: async () => q.generateMnemonic(128)
|
121
144
|
});
|
122
145
|
}
|
123
|
-
const
|
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
|
-
},
|
132
|
-
const
|
133
|
-
return
|
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
|
158
|
+
function Ke(e) {
|
136
159
|
return w({
|
137
|
-
queryKey: ["ecency-wallets", "coingecko-price",
|
160
|
+
queryKey: ["ecency-wallets", "coingecko-price", e],
|
138
161
|
queryFn: async () => {
|
139
|
-
let
|
140
|
-
switch (
|
162
|
+
let t = e;
|
163
|
+
switch (e) {
|
141
164
|
case a.BTC:
|
142
|
-
|
165
|
+
t = "binance-wrapped-btc";
|
143
166
|
break;
|
144
167
|
case a.ETH:
|
145
|
-
|
168
|
+
t = "ethereum";
|
146
169
|
break;
|
147
170
|
case a.SOL:
|
148
|
-
|
171
|
+
t = "solana";
|
149
172
|
break;
|
150
173
|
case a.TON:
|
151
|
-
|
174
|
+
t = "trx";
|
152
175
|
break;
|
153
176
|
default:
|
154
|
-
|
177
|
+
t = e;
|
155
178
|
}
|
156
|
-
let n =
|
179
|
+
let n = G("gecko"), o;
|
157
180
|
if (n)
|
158
181
|
o = n;
|
159
182
|
else {
|
160
|
-
const
|
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: [
|
189
|
+
ids: [t],
|
167
190
|
vs_currencies: "usd"
|
168
191
|
}
|
169
192
|
})
|
170
193
|
}
|
171
194
|
)).json();
|
172
|
-
|
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: !!
|
199
|
+
enabled: !!e
|
177
200
|
});
|
178
201
|
}
|
179
|
-
function
|
180
|
-
const { data:
|
202
|
+
function U(e) {
|
203
|
+
const { data: t } = O(e);
|
181
204
|
return w({
|
182
|
-
queryKey: ["ecencу-wallets", "hive-keys",
|
205
|
+
queryKey: ["ecencу-wallets", "hive-keys", e, t],
|
183
206
|
queryFn: async () => {
|
184
|
-
if (!
|
207
|
+
if (!t)
|
185
208
|
throw new Error("[Ecency][Wallets] - no seed to create Hive account");
|
186
|
-
const n = u.fromLogin(
|
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:
|
211
|
+
username: e,
|
189
212
|
owner: n.toString(),
|
190
213
|
active: o.toString(),
|
191
214
|
posting: s.toString(),
|
192
|
-
memo:
|
215
|
+
memo: i.toString(),
|
193
216
|
ownerPubkey: n.createPublic().toString(),
|
194
217
|
activePubkey: o.createPublic().toString(),
|
195
218
|
postingPubkey: s.createPublic().toString(),
|
196
|
-
memoPubkey:
|
219
|
+
memoPubkey: i.createPublic().toString()
|
197
220
|
};
|
198
221
|
}
|
199
222
|
});
|
200
223
|
}
|
201
|
-
function
|
224
|
+
function Ce(e, t) {
|
202
225
|
return f({
|
203
|
-
queryKey: ["ecency-wallets", "points",
|
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:
|
232
|
+
username: e.replace("@", "")
|
210
233
|
})
|
211
234
|
}
|
212
235
|
)).json(),
|
213
236
|
staleTime: 3e4,
|
214
237
|
refetchOnMount: !0,
|
215
|
-
enabled: !!
|
238
|
+
enabled: !!e
|
216
239
|
});
|
217
240
|
}
|
218
|
-
function
|
241
|
+
function V(e, t) {
|
219
242
|
return f({
|
220
|
-
queryKey: ["hive-engine", "tokens-list",
|
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:
|
233
|
-
account:
|
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
|
244
|
-
const { data:
|
245
|
-
return
|
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(
|
278
|
+
].filter((o) => o.toLowerCase().includes(e.toLowerCase())),
|
256
279
|
external: Object.values(a).filter(
|
257
|
-
(o) => o.toLowerCase().includes(
|
280
|
+
(o) => o.toLowerCase().includes(e.toLowerCase())
|
258
281
|
),
|
259
|
-
layer2: ((n =
|
260
|
-
(o) => o.toLowerCase().includes(
|
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
|
-
[
|
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
|
284
|
-
const { data: n } =
|
285
|
-
mutationKey: ["ecency-wallets", "create-wallet",
|
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
|
312
|
+
const r = P(t), c = await (r == null ? void 0 : r.getDerivedPrivateKey({
|
290
313
|
mnemonic: n,
|
291
|
-
hdPath:
|
314
|
+
hdPath: z[t]
|
292
315
|
}));
|
293
|
-
await
|
294
|
-
const h = await (
|
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:
|
302
|
-
currency:
|
324
|
+
username: e,
|
325
|
+
currency: t
|
303
326
|
};
|
304
327
|
},
|
305
|
-
onSuccess: (
|
328
|
+
onSuccess: (r) => {
|
306
329
|
o.setQueryData(
|
307
|
-
["ecency-wallets", "wallets",
|
308
|
-
(c) => new Map(c ? Array.from(c.entries()) : []).set(
|
330
|
+
["ecency-wallets", "wallets", r.username],
|
331
|
+
(c) => new Map(c ? Array.from(c.entries()) : []).set(r.currency, r)
|
309
332
|
);
|
310
333
|
}
|
311
|
-
}),
|
334
|
+
}), i = N(() => {
|
312
335
|
}, []);
|
313
336
|
return {
|
314
337
|
createWallet: s,
|
315
|
-
importWallet:
|
338
|
+
importWallet: i
|
316
339
|
};
|
317
340
|
}
|
318
|
-
function
|
319
|
-
const { data:
|
320
|
-
queryKey: ["ecency-wallets", "wallets",
|
321
|
-
}), { data: n } =
|
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",
|
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:
|
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((
|
339
|
-
(
|
340
|
-
...
|
341
|
-
[
|
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
|
373
|
+
function A() {
|
351
374
|
return l({
|
352
375
|
mutationKey: ["ecency-wallets", "check-wallet-existence"],
|
353
|
-
mutationFn: async ({ address:
|
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:
|
362
|
-
token:
|
384
|
+
address: e,
|
385
|
+
token: t
|
363
386
|
})
|
364
387
|
}
|
365
388
|
)).json()).length === 0
|
366
389
|
});
|
367
390
|
}
|
368
|
-
const
|
391
|
+
const Ne = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
369
392
|
__proto__: null,
|
370
|
-
useCheckWalletExistence:
|
371
|
-
useCreateAccountWithWallets:
|
372
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
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
|
384
|
-
for (const o of
|
406
|
+
async function Z(e, t, n) {
|
407
|
+
for (const o of Y[n] || [])
|
385
408
|
try {
|
386
|
-
const s = await
|
387
|
-
mnemonic:
|
409
|
+
const s = await t.getDerivedPrivateKey({
|
410
|
+
mnemonic: e,
|
388
411
|
hdPath: o
|
389
|
-
}),
|
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(),
|
416
|
+
return [s.toString(), i.address];
|
394
417
|
} catch {
|
395
418
|
return [];
|
396
419
|
}
|
397
420
|
return [];
|
398
421
|
}
|
399
|
-
function
|
400
|
-
const n =
|
422
|
+
function _e(e, t) {
|
423
|
+
const n = b(), { mutateAsync: o } = A();
|
401
424
|
return l({
|
402
|
-
mutationKey: ["ecency-wallets", "import-wallet",
|
425
|
+
mutationKey: ["ecency-wallets", "import-wallet", e, t],
|
403
426
|
mutationFn: async ({ privateKeyOrSeed: s }) => {
|
404
|
-
const
|
405
|
-
if (!
|
427
|
+
const i = P(t);
|
428
|
+
if (!i)
|
406
429
|
throw new Error("Cannot find token for this currency");
|
407
|
-
const
|
430
|
+
const r = s.split(" ").length === 12;
|
408
431
|
let c, h = s;
|
409
|
-
if (
|
432
|
+
if (r ? [h, c] = await Z(
|
410
433
|
s,
|
411
|
-
|
412
|
-
|
413
|
-
) : c = (await
|
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:
|
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:
|
455
|
+
onSuccess: ({ privateKey: s, publicKey: i, address: r }) => {
|
433
456
|
n.setQueryData(
|
434
|
-
["ecency-wallets", "wallets",
|
435
|
-
(c) => new Map(c ? Array.from(c.entries()) : []).set(
|
457
|
+
["ecency-wallets", "wallets", e],
|
458
|
+
(c) => new Map(c ? Array.from(c.entries()) : []).set(t, {
|
436
459
|
privateKey: s,
|
437
|
-
publicKey:
|
438
|
-
address:
|
439
|
-
username:
|
440
|
-
currency:
|
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
|
448
|
-
let
|
449
|
-
if (
|
450
|
-
return JSON.parse(
|
470
|
+
function ee(e) {
|
471
|
+
let t = atob(e);
|
472
|
+
if (t[0] === "{")
|
473
|
+
return JSON.parse(t);
|
451
474
|
}
|
452
|
-
const y = (
|
475
|
+
const y = (e) => {
|
453
476
|
try {
|
454
|
-
const
|
455
|
-
p.storagePrefix + "_user_" +
|
477
|
+
const t = p.storage.getItem(
|
478
|
+
p.storagePrefix + "_user_" + e
|
456
479
|
);
|
457
|
-
return
|
458
|
-
} catch (
|
459
|
-
console.error(
|
480
|
+
return ee(JSON.parse(t));
|
481
|
+
} catch (t) {
|
482
|
+
console.error(t);
|
460
483
|
return;
|
461
484
|
}
|
462
|
-
},
|
463
|
-
function
|
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: [...
|
488
|
+
mutationKey: [...e, t],
|
466
489
|
mutationFn: async (o) => {
|
467
|
-
if (!
|
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 =
|
494
|
+
const s = ne(t);
|
472
495
|
if (s) {
|
473
|
-
const
|
496
|
+
const r = u.fromString(s);
|
474
497
|
return p.hiveClient.broadcast.sendOperations(
|
475
498
|
n(o),
|
476
|
-
|
499
|
+
r
|
477
500
|
);
|
478
501
|
}
|
479
|
-
let
|
480
|
-
if (
|
481
|
-
return (await new
|
482
|
-
accessToken:
|
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
|
491
|
-
return
|
513
|
+
function ae(e) {
|
514
|
+
return oe(
|
492
515
|
["accounts", "update"],
|
493
|
-
|
516
|
+
e,
|
494
517
|
({
|
495
|
-
profile:
|
518
|
+
profile: t,
|
496
519
|
tokens: n
|
497
520
|
}) => [
|
498
521
|
[
|
499
522
|
"account_update2",
|
500
523
|
{
|
501
|
-
account:
|
524
|
+
account: e,
|
502
525
|
json_metadata: "",
|
503
526
|
posting_json_metadata: JSON.stringify({
|
504
|
-
profile: { ...
|
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
|
536
|
+
function je(e) {
|
514
537
|
return f({
|
515
|
-
queryKey: ["get-account-full",
|
538
|
+
queryKey: ["get-account-full", e],
|
516
539
|
queryFn: async () => {
|
517
|
-
if (!
|
540
|
+
if (!e)
|
518
541
|
throw new Error("[SDK] Username is empty");
|
519
|
-
const
|
520
|
-
if (!
|
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(
|
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
|
-
[
|
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
|
-
[
|
557
|
+
[e, 1]
|
535
558
|
);
|
536
559
|
return {
|
537
|
-
...
|
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: !!
|
569
|
+
enabled: !!e,
|
547
570
|
staleTime: 6e4
|
548
571
|
});
|
549
572
|
}
|
550
|
-
function
|
573
|
+
function De(e, t = 5, n = []) {
|
551
574
|
return f({
|
552
|
-
queryKey: ["accounts", "search",
|
553
|
-
enabled: !!
|
575
|
+
queryKey: ["accounts", "search", e, n],
|
576
|
+
enabled: !!e,
|
554
577
|
queryFn: async () => (await p.hiveClient.database.call(
|
555
578
|
"lookup_accounts",
|
556
|
-
[
|
579
|
+
[e, t]
|
557
580
|
)).filter(
|
558
581
|
(s) => n.length > 0 ? !n.includes(s) : !0
|
559
582
|
)
|
560
583
|
});
|
561
584
|
}
|
562
|
-
function
|
563
|
-
const { mutateAsync:
|
585
|
+
function Fe(e) {
|
586
|
+
const { mutateAsync: t } = ae(e);
|
564
587
|
return l({
|
565
|
-
mutationKey: ["ecency-wallets", "save-wallet-to-metadata",
|
588
|
+
mutationKey: ["ecency-wallets", "save-wallet-to-metadata", e],
|
566
589
|
mutationFn: ({
|
567
590
|
wallets: n
|
568
|
-
}) =>
|
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
|
603
|
+
function Ee(e) {
|
581
604
|
return l({
|
582
|
-
mutationKey: ["operations", "sign",
|
605
|
+
mutationKey: ["operations", "sign", e],
|
583
606
|
mutationFn: ({
|
584
|
-
operation:
|
607
|
+
operation: t,
|
585
608
|
keyOrSeed: n
|
586
609
|
}) => {
|
587
|
-
if (!
|
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(
|
591
|
-
[
|
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
|
598
|
-
var
|
599
|
-
(
|
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 ||
|
627
|
+
c.success || i({ message: "Operation cancelled" }), s(c);
|
605
628
|
},
|
606
629
|
o
|
607
630
|
);
|
608
631
|
});
|
609
|
-
function
|
632
|
+
function Le(e, t = "Active") {
|
610
633
|
return l({
|
611
|
-
mutationKey: ["operations", "sign-keychain",
|
634
|
+
mutationKey: ["operations", "sign-keychain", e],
|
612
635
|
mutationFn: ({ operation: n }) => {
|
613
|
-
if (!
|
636
|
+
if (!e)
|
614
637
|
throw new Error(
|
615
638
|
"[SDK][Keychain] – cannot sign operation with anon user"
|
616
639
|
);
|
617
|
-
return
|
640
|
+
return se(e, [n], t);
|
618
641
|
}
|
619
642
|
});
|
620
643
|
}
|
621
|
-
function
|
644
|
+
function xe(e = "/") {
|
622
645
|
return l({
|
623
|
-
mutationKey: ["operations", "sign-hivesigner",
|
624
|
-
mutationFn: async ({ operation:
|
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
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
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
|
+
}
|