@ecency/wallets 1.2.13 → 1.2.15
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 +231 -169
- package/dist/index.d.ts +1 -0
- package/dist/modules/assets/index.d.ts +1 -0
- package/dist/modules/assets/points/index.d.ts +3 -0
- package/dist/modules/assets/points/mutations/claim-points.d.ts +2 -0
- package/dist/modules/assets/points/mutations/index.d.ts +1 -0
- package/dist/modules/assets/points/queries/get-points-query-options.d.ts +20 -0
- package/dist/modules/assets/points/queries/index.d.ts +1 -0
- package/dist/modules/assets/points/types/index.d.ts +2 -0
- package/dist/modules/assets/points/types/points-response.d.ts +4 -0
- package/dist/modules/assets/points/types/points.d.ts +4 -0
- package/package.json +2 -2
package/dist/ecency-sdk.es.js
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import { useMemo as S, useCallback as
|
|
2
|
-
import { useQuery as
|
|
1
|
+
import { useMemo as S, useCallback as R } from "react";
|
|
2
|
+
import { useQuery as m, queryOptions as h, useQueryClient as T, useMutation as y } from "@tanstack/react-query";
|
|
3
3
|
import { BtcWallet as k } from "@okxweb3/coin-bitcoin";
|
|
4
|
-
import { EthWallet as
|
|
5
|
-
import { TrxWallet as
|
|
4
|
+
import { EthWallet as C } from "@okxweb3/coin-ethereum";
|
|
5
|
+
import { TrxWallet as H } from "@okxweb3/coin-tron";
|
|
6
6
|
import { TonWallet as K } from "@okxweb3/coin-ton";
|
|
7
7
|
import { SolWallet as N } from "@okxweb3/coin-solana";
|
|
8
8
|
import { AtomWallet as D } from "@okxweb3/coin-cosmos";
|
|
9
|
-
import { AptosWallet as
|
|
10
|
-
import
|
|
11
|
-
import { CONFIG as
|
|
12
|
-
import { LRUCache as
|
|
13
|
-
import { PrivateKey as
|
|
14
|
-
var
|
|
15
|
-
function
|
|
9
|
+
import { AptosWallet as j } from "@okxweb3/coin-aptos";
|
|
10
|
+
import L from "bip39";
|
|
11
|
+
import { CONFIG as l, getHiveEngineTokensListQueryOptions as F, useAccountUpdate as x, EcencyAnalytics as q, getAccessToken as E } from "@ecency/sdk";
|
|
12
|
+
import { LRUCache as M } from "lru-cache";
|
|
13
|
+
import { PrivateKey as d } from "@hiveio/dhive";
|
|
14
|
+
var n = /* @__PURE__ */ ((e) => (e.BTC = "BTC", e.ETH = "ETH", e.APT = "APT", e.ATOM = "ATOM", e.TON = "TON", e.TRON = "TRX", e.SOL = "SOL", e))(n || {}), u = /* @__PURE__ */ ((e) => (e.Points = "POINTS", e.HivePower = "HP", e.Hive = "HIVE", e.HiveDollar = "HBD", e.Spk = "SPK", e))(u || {});
|
|
15
|
+
function _(e) {
|
|
16
16
|
return new Promise((t) => setTimeout(t, e));
|
|
17
17
|
}
|
|
18
|
-
function
|
|
18
|
+
function P(e) {
|
|
19
19
|
switch (e) {
|
|
20
|
-
case
|
|
20
|
+
case n.BTC:
|
|
21
21
|
return new k();
|
|
22
|
-
case
|
|
23
|
-
return new H();
|
|
24
|
-
case o.TRON:
|
|
22
|
+
case n.ETH:
|
|
25
23
|
return new C();
|
|
26
|
-
case
|
|
24
|
+
case n.TRON:
|
|
25
|
+
return new H();
|
|
26
|
+
case n.TON:
|
|
27
27
|
return new K();
|
|
28
|
-
case
|
|
28
|
+
case n.SOL:
|
|
29
29
|
return new N();
|
|
30
|
-
case
|
|
30
|
+
case n.ATOM:
|
|
31
31
|
return new D();
|
|
32
|
-
case
|
|
33
|
-
return new
|
|
32
|
+
case n.APT:
|
|
33
|
+
return new j();
|
|
34
34
|
default:
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
function
|
|
39
|
-
return
|
|
38
|
+
function we(e, t) {
|
|
39
|
+
return m({
|
|
40
40
|
queryKey: ["ecency-wallets", "external-wallet-balance", e, t],
|
|
41
41
|
queryFn: async () => {
|
|
42
42
|
switch (e) {
|
|
43
|
-
case
|
|
44
|
-
const
|
|
43
|
+
case n.BTC:
|
|
44
|
+
const s = await (await fetch(
|
|
45
45
|
`https://mempool.space/api/address/${t}`
|
|
46
46
|
)).json();
|
|
47
|
-
return (
|
|
48
|
-
case
|
|
47
|
+
return (s.chain_stats.funded_txo_sum - s.chain_stats.spent_txo_sum) / 1e8;
|
|
48
|
+
case n.ETH:
|
|
49
49
|
return +(await (await fetch(
|
|
50
50
|
`https://api.ethplorer.io/getAddressInfo/${t}?apiKey=freekey`
|
|
51
51
|
)).json()).ETH.balance;
|
|
52
|
-
case
|
|
52
|
+
case n.SOL:
|
|
53
53
|
return (await (await fetch(
|
|
54
|
-
`https://rpc.helius.xyz/?api-key=${
|
|
54
|
+
`https://rpc.helius.xyz/?api-key=${l.heliusApiKey}`,
|
|
55
55
|
{
|
|
56
56
|
method: "POST",
|
|
57
57
|
body: JSON.stringify({
|
|
@@ -65,22 +65,22 @@ function me(e, t) {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
)).json()).result.value / 1e9;
|
|
68
|
-
case
|
|
68
|
+
case n.TRON:
|
|
69
69
|
return (await (await fetch(
|
|
70
70
|
`https://api.trongrid.io/v1/accounts/${t}`
|
|
71
71
|
)).json()).data[0].balance / 1e6;
|
|
72
|
-
case
|
|
72
|
+
case n.TON:
|
|
73
73
|
return (await (await fetch(
|
|
74
74
|
`https://tonapi.io/v1/blockchain/getAccount?account=${t}`
|
|
75
75
|
)).json()).balance / 1e9;
|
|
76
|
-
case
|
|
76
|
+
case n.APT:
|
|
77
77
|
const f = (await (await fetch(
|
|
78
78
|
`https://fullnode.mainnet.aptoslabs.com/v1/accounts/${t}/resources`
|
|
79
79
|
)).json()).find(
|
|
80
|
-
(
|
|
80
|
+
(A) => A.type.includes("coin::CoinStore")
|
|
81
81
|
);
|
|
82
82
|
return f ? parseInt(f.data.coin.value) / 1e8 : 0;
|
|
83
|
-
case
|
|
83
|
+
case n.ATOM:
|
|
84
84
|
return +(await (await fetch(
|
|
85
85
|
`https://rest.cosmos.directory/cosmoshub/auth/accounts/${t}`
|
|
86
86
|
)).json()).result.value.coins[0].amount / 1e6;
|
|
@@ -89,12 +89,12 @@ function me(e, t) {
|
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
91
|
function b(e) {
|
|
92
|
-
return
|
|
92
|
+
return m({
|
|
93
93
|
queryKey: ["ecency-wallets", "seed", e],
|
|
94
|
-
queryFn: async () =>
|
|
94
|
+
queryFn: async () => L.generateMnemonic(128)
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
|
-
const
|
|
97
|
+
const Q = {
|
|
98
98
|
max: 500,
|
|
99
99
|
// how long to live in ms
|
|
100
100
|
ttl: 1e3 * 60 * 5,
|
|
@@ -102,36 +102,36 @@ const F = {
|
|
|
102
102
|
allowStale: !1,
|
|
103
103
|
updateAgeOnGet: !1,
|
|
104
104
|
updateAgeOnHas: !1
|
|
105
|
-
}, g = new
|
|
105
|
+
}, g = new M(Q), w = Symbol("undefined"), W = (e, t) => g.set(e, t === void 0 ? w : t), I = (e) => {
|
|
106
106
|
const t = g.get(e);
|
|
107
|
-
return t ===
|
|
107
|
+
return t === w ? void 0 : t;
|
|
108
108
|
};
|
|
109
|
-
function
|
|
110
|
-
return
|
|
109
|
+
function fe(e) {
|
|
110
|
+
return m({
|
|
111
111
|
queryKey: ["ecency-wallets", "coingecko-price", e],
|
|
112
112
|
queryFn: async () => {
|
|
113
113
|
let t = e;
|
|
114
114
|
switch (e) {
|
|
115
|
-
case
|
|
115
|
+
case n.BTC:
|
|
116
116
|
t = "binance-wrapped-btc";
|
|
117
117
|
break;
|
|
118
|
-
case
|
|
118
|
+
case n.ETH:
|
|
119
119
|
t = "ethereum";
|
|
120
120
|
break;
|
|
121
|
-
case
|
|
121
|
+
case n.SOL:
|
|
122
122
|
t = "solana";
|
|
123
123
|
break;
|
|
124
|
-
case
|
|
124
|
+
case n.TON:
|
|
125
125
|
t = "trx";
|
|
126
126
|
break;
|
|
127
127
|
default:
|
|
128
128
|
t = e;
|
|
129
129
|
}
|
|
130
|
-
let
|
|
131
|
-
if (
|
|
132
|
-
|
|
130
|
+
let o = I("gecko"), s;
|
|
131
|
+
if (o)
|
|
132
|
+
s = o;
|
|
133
133
|
else {
|
|
134
|
-
const
|
|
134
|
+
const i = await (await fetch(
|
|
135
135
|
"https://api.coingecko.com/api/v3/simple/price",
|
|
136
136
|
{
|
|
137
137
|
method: "POST",
|
|
@@ -143,41 +143,41 @@ function we(e) {
|
|
|
143
143
|
})
|
|
144
144
|
}
|
|
145
145
|
)).json();
|
|
146
|
-
|
|
146
|
+
W("gecko", i === void 0 ? w : i), s = i;
|
|
147
147
|
}
|
|
148
|
-
return 1 / +
|
|
148
|
+
return 1 / +s[Object.keys(s)[0]].usd;
|
|
149
149
|
},
|
|
150
150
|
enabled: !!e
|
|
151
151
|
});
|
|
152
152
|
}
|
|
153
|
-
function
|
|
153
|
+
function B(e) {
|
|
154
154
|
const { data: t } = b(e);
|
|
155
|
-
return
|
|
155
|
+
return m({
|
|
156
156
|
queryKey: ["ecencу-wallets", "hive-keys", e, t],
|
|
157
157
|
staleTime: 1 / 0,
|
|
158
158
|
queryFn: async () => {
|
|
159
159
|
if (!t)
|
|
160
160
|
throw new Error("[Ecency][Wallets] - no seed to create Hive account");
|
|
161
|
-
const
|
|
161
|
+
const o = d.fromLogin(e, t, "owner"), s = d.fromLogin(e, t, "active"), a = d.fromLogin(e, t, "posting"), c = d.fromLogin(e, t, "memo");
|
|
162
162
|
return {
|
|
163
163
|
username: e,
|
|
164
|
-
owner:
|
|
165
|
-
active:
|
|
166
|
-
posting:
|
|
164
|
+
owner: o.toString(),
|
|
165
|
+
active: s.toString(),
|
|
166
|
+
posting: a.toString(),
|
|
167
167
|
memo: c.toString(),
|
|
168
|
-
ownerPubkey:
|
|
169
|
-
activePubkey:
|
|
170
|
-
postingPubkey:
|
|
168
|
+
ownerPubkey: o.createPublic().toString(),
|
|
169
|
+
activePubkey: s.createPublic().toString(),
|
|
170
|
+
postingPubkey: a.createPublic().toString(),
|
|
171
171
|
memoPubkey: c.createPublic().toString()
|
|
172
172
|
};
|
|
173
173
|
}
|
|
174
174
|
});
|
|
175
175
|
}
|
|
176
|
-
function
|
|
177
|
-
return
|
|
176
|
+
function he(e, t) {
|
|
177
|
+
return h({
|
|
178
178
|
queryKey: ["ecency-wallets", "points", e, t],
|
|
179
179
|
queryFn: async () => await (await fetch(
|
|
180
|
-
`${
|
|
180
|
+
`${l.privateApiHost}/private-api/points`,
|
|
181
181
|
{
|
|
182
182
|
method: "POST",
|
|
183
183
|
body: JSON.stringify({
|
|
@@ -190,11 +190,11 @@ function de(e, t) {
|
|
|
190
190
|
enabled: !!e
|
|
191
191
|
});
|
|
192
192
|
}
|
|
193
|
-
function
|
|
194
|
-
const { data: t } =
|
|
193
|
+
function Te(e) {
|
|
194
|
+
const { data: t } = m(F());
|
|
195
195
|
return S(
|
|
196
196
|
() => {
|
|
197
|
-
var
|
|
197
|
+
var o;
|
|
198
198
|
return {
|
|
199
199
|
basic: [
|
|
200
200
|
u.Points,
|
|
@@ -202,93 +202,93 @@ function ye(e) {
|
|
|
202
202
|
u.HivePower,
|
|
203
203
|
u.HiveDollar,
|
|
204
204
|
u.Spk
|
|
205
|
-
].filter((
|
|
206
|
-
external: Object.values(
|
|
207
|
-
(
|
|
205
|
+
].filter((s) => s.toLowerCase().includes(e.toLowerCase())),
|
|
206
|
+
external: Object.values(n).filter(
|
|
207
|
+
(s) => s.toLowerCase().includes(e.toLowerCase())
|
|
208
208
|
),
|
|
209
|
-
layer2: ((
|
|
210
|
-
(
|
|
209
|
+
layer2: ((o = t == null ? void 0 : t.map(({ symbol: s }) => s)) == null ? void 0 : o.filter(
|
|
210
|
+
(s) => s.toLowerCase().includes(e.toLowerCase())
|
|
211
211
|
)) ?? []
|
|
212
212
|
};
|
|
213
213
|
},
|
|
214
214
|
[t, e]
|
|
215
215
|
);
|
|
216
216
|
}
|
|
217
|
-
const
|
|
218
|
-
[
|
|
217
|
+
const $ = {
|
|
218
|
+
[n.BTC]: "m/44'/0'/0'/0/0",
|
|
219
219
|
// Bitcoin (BIP44)
|
|
220
|
-
[
|
|
220
|
+
[n.ETH]: "m/44'/60'/0'/0/0",
|
|
221
221
|
// Ethereum (BIP44)
|
|
222
|
-
[
|
|
222
|
+
[n.SOL]: "m/44'/501'/0'/0'",
|
|
223
223
|
// Solana (BIP44)
|
|
224
|
-
[
|
|
224
|
+
[n.TON]: "m/44'/607'/0'",
|
|
225
225
|
// TON (BIP44)
|
|
226
|
-
[
|
|
226
|
+
[n.TRON]: "m/44'/195'/0'/0/0",
|
|
227
227
|
// Tron (BIP44)
|
|
228
|
-
[
|
|
228
|
+
[n.APT]: "m/44'/637'/0'/0'/0'",
|
|
229
229
|
// Aptos (BIP44)
|
|
230
|
-
[
|
|
230
|
+
[n.ATOM]: "m/44'/118'/0'/0/0"
|
|
231
231
|
// Cosmos (BIP44)
|
|
232
232
|
};
|
|
233
|
-
function
|
|
234
|
-
const { data:
|
|
233
|
+
function Pe(e, t) {
|
|
234
|
+
const { data: o } = b(e), s = T(), a = y({
|
|
235
235
|
mutationKey: ["ecency-wallets", "create-wallet", e, t],
|
|
236
236
|
mutationFn: async () => {
|
|
237
|
-
if (!
|
|
237
|
+
if (!o)
|
|
238
238
|
throw new Error("[Ecency][Wallets] - No seed to create a wallet");
|
|
239
|
-
const
|
|
240
|
-
mnemonic:
|
|
241
|
-
hdPath:
|
|
239
|
+
const i = P(t), r = await (i == null ? void 0 : i.getDerivedPrivateKey({
|
|
240
|
+
mnemonic: o,
|
|
241
|
+
hdPath: $[t]
|
|
242
242
|
}));
|
|
243
|
-
await
|
|
244
|
-
const
|
|
245
|
-
privateKey:
|
|
243
|
+
await _(1e3);
|
|
244
|
+
const p = await (i == null ? void 0 : i.getNewAddress({
|
|
245
|
+
privateKey: r
|
|
246
246
|
}));
|
|
247
247
|
return {
|
|
248
|
-
privateKey:
|
|
249
|
-
address:
|
|
250
|
-
publicKey:
|
|
248
|
+
privateKey: r,
|
|
249
|
+
address: p.address,
|
|
250
|
+
publicKey: p.publicKey,
|
|
251
251
|
username: e,
|
|
252
252
|
currency: t
|
|
253
253
|
};
|
|
254
254
|
},
|
|
255
|
-
onSuccess: (
|
|
256
|
-
|
|
257
|
-
["ecency-wallets", "wallets",
|
|
258
|
-
(
|
|
255
|
+
onSuccess: (i) => {
|
|
256
|
+
s.setQueryData(
|
|
257
|
+
["ecency-wallets", "wallets", i.username],
|
|
258
|
+
(r) => new Map(r ? Array.from(r.entries()) : []).set(i.currency, i)
|
|
259
259
|
);
|
|
260
260
|
}
|
|
261
|
-
}), c =
|
|
261
|
+
}), c = R(() => {
|
|
262
262
|
}, []);
|
|
263
263
|
return {
|
|
264
|
-
createWallet:
|
|
264
|
+
createWallet: a,
|
|
265
265
|
importWallet: c
|
|
266
266
|
};
|
|
267
267
|
}
|
|
268
|
-
function
|
|
269
|
-
const { data: t } =
|
|
268
|
+
function J(e) {
|
|
269
|
+
const { data: t } = m({
|
|
270
270
|
queryKey: ["ecency-wallets", "wallets", e]
|
|
271
|
-
}), { data:
|
|
272
|
-
return
|
|
271
|
+
}), { data: o } = B(e);
|
|
272
|
+
return y({
|
|
273
273
|
mutationKey: ["ecency-wallets", "create-account-with-wallets", e],
|
|
274
|
-
mutationFn: ({ currency:
|
|
274
|
+
mutationFn: ({ currency: s, address: a }) => fetch(l.privateApiHost + "/private-api/wallets-add", {
|
|
275
275
|
method: "POST",
|
|
276
276
|
headers: {
|
|
277
277
|
"Content-Type": "application/json"
|
|
278
278
|
},
|
|
279
279
|
body: JSON.stringify({
|
|
280
280
|
username: e,
|
|
281
|
-
token:
|
|
282
|
-
address:
|
|
281
|
+
token: s,
|
|
282
|
+
address: a,
|
|
283
283
|
meta: {
|
|
284
|
-
ownerPublicKey:
|
|
285
|
-
activePublicKey:
|
|
286
|
-
postingPublicKey:
|
|
287
|
-
memoPublicKey:
|
|
284
|
+
ownerPublicKey: o == null ? void 0 : o.ownerPubkey,
|
|
285
|
+
activePublicKey: o == null ? void 0 : o.activePubkey,
|
|
286
|
+
postingPublicKey: o == null ? void 0 : o.postingPubkey,
|
|
287
|
+
memoPublicKey: o == null ? void 0 : o.memoPubkey,
|
|
288
288
|
...Array.from((t == null ? void 0 : t.entries()) ?? []).reduce(
|
|
289
|
-
(c, [
|
|
289
|
+
(c, [i, r]) => ({
|
|
290
290
|
...c,
|
|
291
|
-
[
|
|
291
|
+
[i]: r.address
|
|
292
292
|
}),
|
|
293
293
|
{}
|
|
294
294
|
)
|
|
@@ -297,11 +297,11 @@ function B(e) {
|
|
|
297
297
|
})
|
|
298
298
|
});
|
|
299
299
|
}
|
|
300
|
-
function
|
|
301
|
-
return
|
|
300
|
+
function v() {
|
|
301
|
+
return y({
|
|
302
302
|
mutationKey: ["ecency-wallets", "check-wallet-existence"],
|
|
303
303
|
mutationFn: async ({ address: e, currency: t }) => (await (await fetch(
|
|
304
|
-
|
|
304
|
+
l.privateApiHost + "/private-api/wallets-exist",
|
|
305
305
|
{
|
|
306
306
|
method: "POST",
|
|
307
307
|
headers: {
|
|
@@ -315,77 +315,77 @@ function P() {
|
|
|
315
315
|
)).json()).length === 0
|
|
316
316
|
});
|
|
317
317
|
}
|
|
318
|
-
const
|
|
318
|
+
const be = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
319
319
|
__proto__: null,
|
|
320
|
-
useCheckWalletExistence:
|
|
321
|
-
useCreateAccountWithWallets:
|
|
322
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
323
|
-
[
|
|
324
|
-
[
|
|
320
|
+
useCheckWalletExistence: v,
|
|
321
|
+
useCreateAccountWithWallets: J
|
|
322
|
+
}, Symbol.toStringTag, { value: "Module" })), G = {
|
|
323
|
+
[n.BTC]: ["m/84'/0'/0'/0/0"],
|
|
324
|
+
[n.ETH]: ["m/84'/60'/0'/0/0"],
|
|
325
325
|
// its not working for Trust, Exodus, todo: check others below
|
|
326
|
-
[
|
|
327
|
-
[
|
|
328
|
-
[
|
|
329
|
-
[
|
|
326
|
+
[n.SOL]: ["m/84'/501'/0'/0/0"],
|
|
327
|
+
[n.TRON]: ["m/44'/195'/0'/0'/0'"],
|
|
328
|
+
[n.APT]: ["m/84'/637'/0'/0/0"],
|
|
329
|
+
[n.TON]: [],
|
|
330
330
|
// Disabled
|
|
331
|
-
[
|
|
331
|
+
[n.ATOM]: ["m/84'/118'/0'/0'/0"]
|
|
332
332
|
};
|
|
333
|
-
async function
|
|
334
|
-
for (const
|
|
333
|
+
async function V(e, t, o) {
|
|
334
|
+
for (const s of G[o] || [])
|
|
335
335
|
try {
|
|
336
|
-
const
|
|
336
|
+
const a = await t.getDerivedPrivateKey({
|
|
337
337
|
mnemonic: e,
|
|
338
|
-
hdPath:
|
|
338
|
+
hdPath: s
|
|
339
339
|
}), c = await t.getNewAddress({
|
|
340
|
-
privateKey:
|
|
341
|
-
addressType:
|
|
340
|
+
privateKey: a,
|
|
341
|
+
addressType: o === n.BTC ? "segwit_native" : void 0
|
|
342
342
|
});
|
|
343
|
-
return [
|
|
343
|
+
return [a.toString(), c.address];
|
|
344
344
|
} catch {
|
|
345
345
|
return [];
|
|
346
346
|
}
|
|
347
347
|
return [];
|
|
348
348
|
}
|
|
349
|
-
function
|
|
350
|
-
const
|
|
351
|
-
return
|
|
349
|
+
function ge(e, t) {
|
|
350
|
+
const o = T(), { mutateAsync: s } = v();
|
|
351
|
+
return y({
|
|
352
352
|
mutationKey: ["ecency-wallets", "import-wallet", e, t],
|
|
353
|
-
mutationFn: async ({ privateKeyOrSeed:
|
|
354
|
-
const c =
|
|
353
|
+
mutationFn: async ({ privateKeyOrSeed: a }) => {
|
|
354
|
+
const c = P(t);
|
|
355
355
|
if (!c)
|
|
356
356
|
throw new Error("Cannot find token for this currency");
|
|
357
|
-
const
|
|
358
|
-
let
|
|
359
|
-
if (
|
|
360
|
-
|
|
357
|
+
const i = a.split(" ").length === 12;
|
|
358
|
+
let r, p = a;
|
|
359
|
+
if (i ? [p, r] = await V(
|
|
360
|
+
a,
|
|
361
361
|
c,
|
|
362
362
|
t
|
|
363
|
-
) :
|
|
364
|
-
privateKey:
|
|
365
|
-
})).address, !
|
|
363
|
+
) : r = (await c.getNewAddress({
|
|
364
|
+
privateKey: a
|
|
365
|
+
})).address, !r || !a)
|
|
366
366
|
throw new Error(
|
|
367
367
|
"Private key/seed phrase isn't matching with public key or token"
|
|
368
368
|
);
|
|
369
|
-
if (!await
|
|
370
|
-
address:
|
|
369
|
+
if (!await s({
|
|
370
|
+
address: r,
|
|
371
371
|
currency: t
|
|
372
372
|
}))
|
|
373
373
|
throw new Error(
|
|
374
374
|
"This wallet has already in use by Hive account. Please, try another one"
|
|
375
375
|
);
|
|
376
376
|
return {
|
|
377
|
-
privateKey:
|
|
378
|
-
address:
|
|
377
|
+
privateKey: p,
|
|
378
|
+
address: r,
|
|
379
379
|
publicKey: ""
|
|
380
380
|
};
|
|
381
381
|
},
|
|
382
|
-
onSuccess: ({ privateKey:
|
|
383
|
-
|
|
382
|
+
onSuccess: ({ privateKey: a, publicKey: c, address: i }) => {
|
|
383
|
+
o.setQueryData(
|
|
384
384
|
["ecency-wallets", "wallets", e],
|
|
385
|
-
(
|
|
386
|
-
privateKey:
|
|
385
|
+
(r) => new Map(r ? Array.from(r.entries()) : []).set(t, {
|
|
386
|
+
privateKey: a,
|
|
387
387
|
publicKey: c,
|
|
388
|
-
address:
|
|
388
|
+
address: i,
|
|
389
389
|
username: e,
|
|
390
390
|
currency: t,
|
|
391
391
|
custom: !0
|
|
@@ -394,35 +394,97 @@ function Te(e, t) {
|
|
|
394
394
|
}
|
|
395
395
|
});
|
|
396
396
|
}
|
|
397
|
-
function
|
|
398
|
-
const { mutateAsync: t } =
|
|
399
|
-
return
|
|
397
|
+
function ve(e) {
|
|
398
|
+
const { mutateAsync: t } = x(e);
|
|
399
|
+
return y({
|
|
400
400
|
mutationKey: ["ecency-wallets", "save-wallet-to-metadata", e],
|
|
401
401
|
mutationFn: ({
|
|
402
|
-
wallets:
|
|
402
|
+
wallets: o
|
|
403
403
|
}) => t({
|
|
404
404
|
profile: {},
|
|
405
|
-
tokens: Array.from(
|
|
406
|
-
symbol:
|
|
405
|
+
tokens: Array.from(o.entries() ?? []).map(([s, a]) => ({
|
|
406
|
+
symbol: s,
|
|
407
407
|
type: "CHAIN",
|
|
408
408
|
meta: {
|
|
409
|
-
address:
|
|
409
|
+
address: a.address
|
|
410
410
|
}
|
|
411
411
|
}))
|
|
412
412
|
})
|
|
413
413
|
});
|
|
414
414
|
}
|
|
415
|
+
function z(e) {
|
|
416
|
+
return h({
|
|
417
|
+
queryKey: ["assets", "points", e],
|
|
418
|
+
queryFn: async () => {
|
|
419
|
+
if (!e)
|
|
420
|
+
throw new Error(
|
|
421
|
+
"[SDK][Wallets][Assets][Points][Query] – username wasn`t provided"
|
|
422
|
+
);
|
|
423
|
+
const o = await (await fetch(
|
|
424
|
+
l.privateApiHost + "/private-api/points",
|
|
425
|
+
{
|
|
426
|
+
method: "POST",
|
|
427
|
+
headers: {
|
|
428
|
+
"Content-Type": "application/json"
|
|
429
|
+
},
|
|
430
|
+
body: JSON.stringify({ username: e })
|
|
431
|
+
}
|
|
432
|
+
)).json();
|
|
433
|
+
return {
|
|
434
|
+
points: o.points,
|
|
435
|
+
uPoints: o.unclaimed_points
|
|
436
|
+
};
|
|
437
|
+
},
|
|
438
|
+
staleTime: 6e4,
|
|
439
|
+
refetchInterval: 9e4,
|
|
440
|
+
refetchOnMount: !0,
|
|
441
|
+
enabled: !!e
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
function Oe(e, t, o) {
|
|
445
|
+
const { mutateAsync: s } = q.useRecordActivity(
|
|
446
|
+
e,
|
|
447
|
+
"points-claimed"
|
|
448
|
+
);
|
|
449
|
+
return y({
|
|
450
|
+
mutationFn: async () => {
|
|
451
|
+
if (!e)
|
|
452
|
+
throw new Error(
|
|
453
|
+
"[SDK][Wallets][Assets][Points][Claim] – username wasn`t provided"
|
|
454
|
+
);
|
|
455
|
+
return fetch(l.privateApiHost + "/private-api/points-claim", {
|
|
456
|
+
method: "POST",
|
|
457
|
+
headers: {
|
|
458
|
+
"Content-Type": "application/json"
|
|
459
|
+
},
|
|
460
|
+
body: JSON.stringify({ code: E(e) })
|
|
461
|
+
});
|
|
462
|
+
},
|
|
463
|
+
onError: o,
|
|
464
|
+
onSuccess: () => {
|
|
465
|
+
s(), l.queryClient.setQueryData(
|
|
466
|
+
z(e).queryKey,
|
|
467
|
+
(a) => a && {
|
|
468
|
+
points: (parseFloat(a.points) + parseFloat(a.uPoints)).toFixed(3),
|
|
469
|
+
uPoints: "0"
|
|
470
|
+
}
|
|
471
|
+
), t == null || t();
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
}
|
|
415
475
|
export {
|
|
416
476
|
u as EcencyWalletBasicTokens,
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
477
|
+
n as EcencyWalletCurrency,
|
|
478
|
+
be as EcencyWalletsPrivateApi,
|
|
479
|
+
he as getAccountPointsQueryOptions,
|
|
480
|
+
z as getPointsQueryOptions,
|
|
481
|
+
Oe as useClaimPoints,
|
|
482
|
+
fe as useCoinGeckoPriceQuery,
|
|
483
|
+
Te as useGetAllTokensListQuery,
|
|
484
|
+
we as useGetExternalWalletBalanceQuery,
|
|
485
|
+
B as useHiveKeysQuery,
|
|
486
|
+
ge as useImportWallet,
|
|
487
|
+
ve as useSaveWalletInformationToMetadata,
|
|
426
488
|
b as useSeedPhrase,
|
|
427
|
-
|
|
489
|
+
Pe as useWalletCreate
|
|
428
490
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './points';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { useMutation } from '@tanstack/react-query';
|
|
2
|
+
export declare function useClaimPoints(username: string | undefined, onSuccess?: () => void, onError?: Parameters<typeof useMutation>["0"]["onError"]): import('@tanstack/react-query').UseMutationResult<Response, unknown, unknown, unknown>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './claim-points';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare function getPointsQueryOptions(username?: string): import('@tanstack/query-core').OmitKeyof<import('@tanstack/react-query').UseQueryOptions<{
|
|
2
|
+
readonly points: any;
|
|
3
|
+
readonly uPoints: any;
|
|
4
|
+
}, Error, {
|
|
5
|
+
readonly points: any;
|
|
6
|
+
readonly uPoints: any;
|
|
7
|
+
}, (string | undefined)[]>, "queryFn"> & {
|
|
8
|
+
queryFn?: import('@tanstack/query-core').QueryFunction<{
|
|
9
|
+
readonly points: any;
|
|
10
|
+
readonly uPoints: any;
|
|
11
|
+
}, (string | undefined)[], never> | undefined;
|
|
12
|
+
} & {
|
|
13
|
+
queryKey: (string | undefined)[] & {
|
|
14
|
+
[dataTagSymbol]: {
|
|
15
|
+
readonly points: any;
|
|
16
|
+
readonly uPoints: any;
|
|
17
|
+
};
|
|
18
|
+
[dataTagErrorSymbol]: Error;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './get-points-query-options';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecency/wallets",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.15",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "./dist/ecency-sdk.umd.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"preview": "vite preview"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@ecency/sdk": "1.0.
|
|
20
|
+
"@ecency/sdk": "^1.0.40",
|
|
21
21
|
"@hiveio/dhive": "^1.3.2",
|
|
22
22
|
"@tanstack/react-query": "^5.74.4",
|
|
23
23
|
"@types/node": "^22.13.8",
|