@otoplo/wallet-common 0.1.15 → 0.2.1
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/index.js +554 -581
- package/dist/index.js.map +1 -1
- package/dist/types/persistence/datastore/db.d.ts +5 -4
- package/dist/types/persistence/datastore/db.d.ts.map +1 -1
- package/dist/types/persistence/wallet-db.d.ts +10 -19
- package/dist/types/persistence/wallet-db.d.ts.map +1 -1
- package/dist/types/services/asset.d.ts +5 -9
- package/dist/types/services/asset.d.ts.map +1 -1
- package/dist/types/services/cache.d.ts +4 -2
- package/dist/types/services/cache.d.ts.map +1 -1
- package/dist/types/services/wallet.d.ts +2 -1
- package/dist/types/services/wallet.d.ts.map +1 -1
- package/dist/types/state/hooks.d.ts +2 -1
- package/dist/types/state/hooks.d.ts.map +1 -1
- package/dist/types/state/slices/market.d.ts +54 -0
- package/dist/types/state/slices/market.d.ts.map +1 -0
- package/dist/types/state/slices/status.d.ts +0 -27
- package/dist/types/state/slices/status.d.ts.map +1 -1
- package/dist/types/state/slices/wallet.d.ts +21 -220
- package/dist/types/state/slices/wallet.d.ts.map +1 -1
- package/dist/types/state/store.d.ts +3 -0
- package/dist/types/state/store.d.ts.map +1 -1
- package/dist/types/types/db.types.d.ts +16 -11
- package/dist/types/types/db.types.d.ts.map +1 -1
- package/dist/types/types/wallet.types.d.ts +39 -14
- package/dist/types/types/wallet.types.d.ts.map +1 -1
- package/dist/types/utils/asset.d.ts +3 -6
- package/dist/types/utils/asset.d.ts.map +1 -1
- package/dist/types/utils/common.d.ts +0 -1
- package/dist/types/utils/common.d.ts.map +1 -1
- package/dist/types/utils/enums.d.ts +0 -4
- package/dist/types/utils/enums.d.ts.map +1 -1
- package/dist/types/utils/index.d.ts +1 -1
- package/dist/types/utils/index.d.ts.map +1 -1
- package/dist/types/utils/{price.d.ts → market.d.ts} +19 -13
- package/dist/types/utils/market.d.ts.map +1 -0
- package/package.json +4 -5
- package/src/persistence/datastore/db.ts +5 -4
- package/src/persistence/wallet-db.ts +26 -30
- package/src/services/asset.ts +69 -162
- package/src/services/cache.ts +12 -2
- package/src/services/wallet.ts +23 -21
- package/src/state/hooks.ts +3 -1
- package/src/state/slices/market.ts +47 -0
- package/src/state/slices/status.ts +2 -31
- package/src/state/slices/wallet.ts +8 -13
- package/src/state/store.ts +3 -0
- package/src/types/db.types.ts +17 -12
- package/src/types/wallet.types.ts +40 -16
- package/src/utils/asset.ts +12 -52
- package/src/utils/common.ts +0 -6
- package/src/utils/enums.ts +0 -5
- package/src/utils/index.ts +1 -1
- package/src/utils/market.ts +97 -0
- package/dist/types/utils/price.d.ts.map +0 -1
- package/src/utils/price.ts +0 -46
package/dist/index.js
CHANGED
|
@@ -1,70 +1,69 @@
|
|
|
1
|
-
import { AddressType as
|
|
2
|
-
import
|
|
3
|
-
import { ElectrumClient as
|
|
4
|
-
import { mnemonicToSeedSync as
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return k.defaultNetwork == k.testnet;
|
|
1
|
+
import { AddressType as O, Networks as E, Address as I, CommonUtils as $, BufferUtils as m, HDPrivateKey as J, TransactionBuilder as j, Transaction as x, UnitUtils as z, Script as b, Opcode as A, Hash as _, ScriptOpcode as L, BNExtended as F, Output as we, TxSigner as q, SighashType as X, ScriptFactory as Ae, OutputSighashType as Y, BufferWriter as ve } from "libnexa-ts";
|
|
2
|
+
import B from "js-big-decimal";
|
|
3
|
+
import { ElectrumClient as be, TransportScheme as H, ConnectionStatus as Se } from "@otoplo/electrum-client";
|
|
4
|
+
import { mnemonicToSeedSync as ke, generateMnemonic as Te, validateMnemonic as Ie } from "@scure/bip39";
|
|
5
|
+
import { DAppProvider as xe } from "wallet-comms-sdk";
|
|
6
|
+
import { wordlist as se } from "@scure/bip39/wordlists/english.js";
|
|
7
|
+
import { createSlice as S, createAsyncThunk as Ne, createSelector as W } from "@reduxjs/toolkit";
|
|
8
|
+
import { useSelector as Me } from "react-redux";
|
|
9
|
+
const w = -1, Z = 9223372036854775807n, Ee = 274710, yt = "0014461ad25081cb0119d034385ff154c8d3ad6bdd76";
|
|
10
|
+
function C() {
|
|
11
|
+
return E.defaultNetwork == E.testnet;
|
|
13
12
|
}
|
|
14
|
-
function
|
|
15
|
-
return
|
|
13
|
+
function wt(a) {
|
|
14
|
+
return C() ? a == "508c843a4b98fb25f57cf9ebafb245a5c16468f06519cdd467059a91e7b79d52" : a == "edc7144fe1ba4edd0edf35d7eea90f6cb1dba42314aa85da8207e97c5339c801";
|
|
16
15
|
}
|
|
17
|
-
function
|
|
18
|
-
return
|
|
16
|
+
function R(a, e = O.PayToScriptTemplate) {
|
|
17
|
+
return I.isValid(a, E.defaultNetwork, e);
|
|
19
18
|
}
|
|
20
|
-
function
|
|
21
|
-
return `https://${
|
|
19
|
+
function At() {
|
|
20
|
+
return `https://${C() ? "testnet-" : ""}explorer.nexa.org`;
|
|
22
21
|
}
|
|
23
|
-
function
|
|
22
|
+
function G() {
|
|
24
23
|
return Math.floor(Date.now() / 1e3);
|
|
25
24
|
}
|
|
26
|
-
function
|
|
25
|
+
function vt(a, e) {
|
|
27
26
|
const t = (e - a) * 2, s = /* @__PURE__ */ new Date();
|
|
28
27
|
return s.setMinutes(s.getMinutes() + t), s.toLocaleDateString();
|
|
29
28
|
}
|
|
30
|
-
function
|
|
29
|
+
function M(a) {
|
|
31
30
|
return !a || a.length === 0;
|
|
32
31
|
}
|
|
33
|
-
function
|
|
32
|
+
function bt(a, e = 0) {
|
|
34
33
|
if (!a || a.length <= e)
|
|
35
34
|
return a || "";
|
|
36
35
|
const t = "...", s = Math.floor((e - t.length) / 2), n = a.slice(0, s), i = a.slice(a.length - s);
|
|
37
36
|
return n + t + i;
|
|
38
37
|
}
|
|
39
|
-
function
|
|
38
|
+
function St(a) {
|
|
40
39
|
return a.length === 0 ? "" : a.charAt(0).toUpperCase() + a.substring(1);
|
|
41
40
|
}
|
|
42
|
-
function
|
|
43
|
-
return $.isHexa(a) ?
|
|
41
|
+
function ae(a) {
|
|
42
|
+
return $.isHexa(a) ? m.hexToBuffer(a) : I.fromString(a).data;
|
|
44
43
|
}
|
|
45
|
-
function
|
|
46
|
-
return $.isHexa(a) ? a :
|
|
44
|
+
function v(a) {
|
|
45
|
+
return $.isHexa(a) ? a : m.bufferToHex(ae(a));
|
|
47
46
|
}
|
|
48
|
-
function
|
|
49
|
-
return $.isHexa(a) ? new
|
|
47
|
+
function kt(a) {
|
|
48
|
+
return $.isHexa(a) ? new I(ae(a), E.defaultNetwork, O.GroupIdAddress).toString() : a;
|
|
50
49
|
}
|
|
51
|
-
function
|
|
50
|
+
function U(a) {
|
|
52
51
|
return a == null || a === "" ? "" : BigInt(a) <= 0n ? "0" : a.toString();
|
|
53
52
|
}
|
|
54
|
-
function
|
|
53
|
+
function Q(a) {
|
|
55
54
|
let e = BigInt(0), t = BigInt(0);
|
|
56
55
|
return a.forEach((s) => {
|
|
57
56
|
e += BigInt(s.confirmed), t += BigInt(s.unconfirmed);
|
|
58
57
|
}), { confirmed: e.toString(), unconfirmed: t.toString() };
|
|
59
58
|
}
|
|
60
|
-
function
|
|
59
|
+
function K(a) {
|
|
61
60
|
const e = {};
|
|
62
61
|
return a.forEach((t) => {
|
|
63
62
|
for (const s in t)
|
|
64
63
|
e[s] ? (e[s].confirmed = (BigInt(e[s].confirmed) + BigInt(t[s].confirmed)).toString(), e[s].unconfirmed = (BigInt(e[s].unconfirmed) + BigInt(t[s].unconfirmed)).toString()) : e[s] = { confirmed: BigInt(t[s].confirmed).toString(), unconfirmed: BigInt(t[s].unconfirmed).toString() };
|
|
65
64
|
}), e;
|
|
66
65
|
}
|
|
67
|
-
const
|
|
66
|
+
const ne = {
|
|
68
67
|
// Images
|
|
69
68
|
//'.svg': { media: 'image', mime: 'image/svg+xml' },
|
|
70
69
|
".gif": { media: "image", mime: "image/gif" },
|
|
@@ -87,32 +86,28 @@ const le = {
|
|
|
87
86
|
".wav": { media: "audio", mime: "audio/wav" },
|
|
88
87
|
".m4a": { media: "audio", mime: "audio/mp4" }
|
|
89
88
|
};
|
|
90
|
-
function
|
|
89
|
+
function Tt(a) {
|
|
91
90
|
const e = a.lastIndexOf(".");
|
|
92
91
|
if (e === -1) return "unknown";
|
|
93
92
|
const t = a.slice(e).toLowerCase();
|
|
94
|
-
return
|
|
93
|
+
return ne[t]?.media ?? "unknown";
|
|
95
94
|
}
|
|
96
|
-
function
|
|
95
|
+
function It(a) {
|
|
97
96
|
const e = a.lastIndexOf(".");
|
|
98
97
|
if (e === -1) return "application/octet-stream";
|
|
99
98
|
const t = a.slice(e).toLowerCase();
|
|
100
|
-
return
|
|
99
|
+
return ne[t]?.mime ?? "application/octet-stream";
|
|
101
100
|
}
|
|
102
|
-
function
|
|
101
|
+
function xt(a) {
|
|
103
102
|
return new Promise((e) => setTimeout(e, a));
|
|
104
103
|
}
|
|
105
|
-
function
|
|
106
|
-
let e =
|
|
104
|
+
function Nt(a) {
|
|
105
|
+
let e = B.getPrettyValue(a);
|
|
107
106
|
return e.match(/\./) && (e = e.replace(/\.?0+$/, "")), e;
|
|
108
107
|
}
|
|
109
|
-
|
|
110
|
-
const s = U.multiply(a, e), n = U.round(s, 2, U.RoundingModes.HALF_DOWN);
|
|
111
|
-
return t ? He(n) : n;
|
|
112
|
-
}
|
|
113
|
-
class Ut {
|
|
108
|
+
class Mt {
|
|
114
109
|
getPrefix() {
|
|
115
|
-
return
|
|
110
|
+
return C() ? "testnet-" : "";
|
|
116
111
|
}
|
|
117
112
|
async getEncryptedSeed() {
|
|
118
113
|
return this.getValue("seed");
|
|
@@ -169,7 +164,7 @@ class Ut {
|
|
|
169
164
|
}
|
|
170
165
|
async getRequireAuth() {
|
|
171
166
|
const e = await this.getValue("auth");
|
|
172
|
-
return
|
|
167
|
+
return M(e) || e === "true";
|
|
173
168
|
}
|
|
174
169
|
async setRequireAuth(e) {
|
|
175
170
|
await this.setValue("auth", JSON.stringify(e));
|
|
@@ -179,7 +174,7 @@ class Ut {
|
|
|
179
174
|
return e ? Number(e) : void 0;
|
|
180
175
|
}
|
|
181
176
|
async setReleaseNotesTime(e) {
|
|
182
|
-
|
|
177
|
+
M(e) ? await this.removeValue("show-notes") : await this.setValue("show-notes", e);
|
|
183
178
|
}
|
|
184
179
|
async getIsTestnet() {
|
|
185
180
|
return await this.getValue("testnet") === "1";
|
|
@@ -195,8 +190,8 @@ class Ut {
|
|
|
195
190
|
await this.setValue("auto-lock", `${e}`);
|
|
196
191
|
}
|
|
197
192
|
}
|
|
198
|
-
var
|
|
199
|
-
class
|
|
193
|
+
var h = /* @__PURE__ */ ((a) => (a[a.MAIN = 0] = "MAIN", a[a.VAULT = 1] = "VAULT", a[a.DAPP = 2] = "DAPP", a))(h || {}), y = /* @__PURE__ */ ((a) => (a[a.RECEIVE = 0] = "RECEIVE", a[a.CHANGE = 1] = "CHANGE", a))(y || {}), N = /* @__PURE__ */ ((a) => (a.SignMessage = "signMessage", a.AddToken = "addToken", a.SignTransaction = "signTransaction", a.SendTransaction = "sendTransaction", a))(N || {});
|
|
194
|
+
class Et {
|
|
200
195
|
store;
|
|
201
196
|
updateCallback;
|
|
202
197
|
constructor(e) {
|
|
@@ -240,22 +235,28 @@ class Dt {
|
|
|
240
235
|
const s = {
|
|
241
236
|
accountId: e,
|
|
242
237
|
tokenIdHex: t.tokenIdHex,
|
|
243
|
-
type:
|
|
244
|
-
addedTime:
|
|
238
|
+
type: "token",
|
|
239
|
+
addedTime: G()
|
|
245
240
|
};
|
|
246
|
-
await this.store.
|
|
241
|
+
await this.store.upsertToken(t), await this.saveAsset(s), this.notify({ type: "token_refresh" });
|
|
247
242
|
}
|
|
248
|
-
async getLocalTokens(e) {
|
|
249
|
-
return this.store.getTokens(e);
|
|
243
|
+
async getLocalTokens(e, t, s) {
|
|
244
|
+
return this.store.getTokens(e, t, s);
|
|
250
245
|
}
|
|
251
246
|
async getToken(e) {
|
|
252
247
|
return this.store.getToken(e);
|
|
253
248
|
}
|
|
254
249
|
async deleteToken(e, t) {
|
|
255
|
-
await this.removeAsset(e, t), await this.store.countAssetsById(t) == 0 && await this.store.deleteToken(t), this.notify({ type: "
|
|
250
|
+
await this.removeAsset(e, t), await this.store.countAssetsById(t) == 0 && await this.store.deleteToken(t), this.notify({ type: "token_refresh" });
|
|
256
251
|
}
|
|
257
|
-
async saveNft(e, t) {
|
|
258
|
-
|
|
252
|
+
async saveNft(e, t, s) {
|
|
253
|
+
const n = {
|
|
254
|
+
accountId: e,
|
|
255
|
+
tokenIdHex: t.tokenIdHex,
|
|
256
|
+
type: "nft",
|
|
257
|
+
addedTime: s
|
|
258
|
+
};
|
|
259
|
+
await this.store.upsertNft(t), await this.saveAsset(n), this.notify({ type: "nft_refresh" });
|
|
259
260
|
}
|
|
260
261
|
async getLocalNfts(e, t, s) {
|
|
261
262
|
return this.store.getNfts(e, t, s);
|
|
@@ -263,24 +264,21 @@ class Dt {
|
|
|
263
264
|
async getLocalNft(e) {
|
|
264
265
|
return this.store.getNft(e);
|
|
265
266
|
}
|
|
266
|
-
async deleteNft(e, t
|
|
267
|
-
await this.removeAsset(e, t), await this.store.countAssetsById(t) == 0 &&
|
|
267
|
+
async deleteNft(e, t) {
|
|
268
|
+
await this.removeAsset(e, t), await this.store.countAssetsById(t) == 0 && await this.store.deleteNft(t), this.notify({ type: "nft_refresh" });
|
|
268
269
|
}
|
|
269
270
|
async countLocalNfts(e) {
|
|
270
271
|
return this.store.countNfts(e);
|
|
271
272
|
}
|
|
272
|
-
async
|
|
273
|
-
return this.store.
|
|
273
|
+
async getAssets(e, t) {
|
|
274
|
+
return this.store.getAssets(e, t);
|
|
274
275
|
}
|
|
275
|
-
async saveAsset(e
|
|
276
|
-
await this.store.upsertAsset(e)
|
|
276
|
+
async saveAsset(e) {
|
|
277
|
+
await this.store.upsertAsset(e);
|
|
277
278
|
}
|
|
278
279
|
async removeAsset(e, t) {
|
|
279
280
|
return this.store.deleteAsset(e, t);
|
|
280
281
|
}
|
|
281
|
-
async isAssetExistForAccount(e, t) {
|
|
282
|
-
return this.store.isAssetExistForAccount(e, t);
|
|
283
|
-
}
|
|
284
282
|
async saveAccount(e) {
|
|
285
283
|
const t = {
|
|
286
284
|
id: e.id,
|
|
@@ -297,7 +295,7 @@ class Dt {
|
|
|
297
295
|
async getAccounts() {
|
|
298
296
|
return (await this.store.getAccounts()).map((t) => ({
|
|
299
297
|
...t,
|
|
300
|
-
type:
|
|
298
|
+
type: h.DAPP,
|
|
301
299
|
balance: JSON.parse(t.balance),
|
|
302
300
|
tokensBalance: JSON.parse(t.tokensBalance)
|
|
303
301
|
}));
|
|
@@ -333,7 +331,7 @@ class Dt {
|
|
|
333
331
|
async getReceiveAddresses() {
|
|
334
332
|
return (await this.store.getReceiveAddresses()).map((t) => ({
|
|
335
333
|
...t,
|
|
336
|
-
type:
|
|
334
|
+
type: h.MAIN,
|
|
337
335
|
balance: JSON.parse(t.balance),
|
|
338
336
|
tokensBalance: JSON.parse(t.tokensBalance)
|
|
339
337
|
}));
|
|
@@ -341,7 +339,7 @@ class Dt {
|
|
|
341
339
|
async getChangeAddresses() {
|
|
342
340
|
return (await this.store.getChangeAddresses()).map((t) => ({
|
|
343
341
|
...t,
|
|
344
|
-
type:
|
|
342
|
+
type: h.MAIN,
|
|
345
343
|
balance: JSON.parse(t.balance),
|
|
346
344
|
tokensBalance: JSON.parse(t.tokensBalance)
|
|
347
345
|
}));
|
|
@@ -352,7 +350,7 @@ class Dt {
|
|
|
352
350
|
async getVaults() {
|
|
353
351
|
return (await this.store.getVaults()).map((t) => ({
|
|
354
352
|
...t,
|
|
355
|
-
type:
|
|
353
|
+
type: h.VAULT,
|
|
356
354
|
balance: JSON.parse(t.balance),
|
|
357
355
|
tokensBalance: JSON.parse(t.tokensBalance)
|
|
358
356
|
}));
|
|
@@ -370,7 +368,7 @@ class Dt {
|
|
|
370
368
|
return this.store.upsertVault(t);
|
|
371
369
|
}
|
|
372
370
|
}
|
|
373
|
-
class
|
|
371
|
+
class Ct {
|
|
374
372
|
walletDb;
|
|
375
373
|
tokens = /* @__PURE__ */ new Map();
|
|
376
374
|
nfts = /* @__PURE__ */ new Map();
|
|
@@ -380,26 +378,32 @@ class Vt {
|
|
|
380
378
|
clear() {
|
|
381
379
|
this.tokens.clear(), this.nfts.clear();
|
|
382
380
|
}
|
|
383
|
-
|
|
384
|
-
|
|
381
|
+
hasToken(e) {
|
|
382
|
+
return e = v(e), this.tokens.has(e);
|
|
383
|
+
}
|
|
384
|
+
hasNft(e) {
|
|
385
|
+
return e = v(e), this.nfts.has(e);
|
|
386
|
+
}
|
|
387
|
+
async getToken(e) {
|
|
388
|
+
if (e = v(e), this.tokens.has(e))
|
|
385
389
|
return this.tokens.get(e);
|
|
386
390
|
const t = await this.walletDb.getToken(e);
|
|
387
391
|
return t && this.tokens.set(e, t), t;
|
|
388
392
|
}
|
|
389
|
-
async
|
|
390
|
-
if (e =
|
|
393
|
+
async getNft(e) {
|
|
394
|
+
if (e = v(e), this.nfts.has(e))
|
|
391
395
|
return this.nfts.get(e);
|
|
392
396
|
const t = await this.walletDb.getLocalNft(e);
|
|
393
397
|
return t && this.nfts.set(e, t), t;
|
|
394
398
|
}
|
|
395
399
|
removeToken(e) {
|
|
396
|
-
this.tokens.delete(
|
|
400
|
+
this.tokens.delete(v(e));
|
|
397
401
|
}
|
|
398
402
|
removeNft(e) {
|
|
399
|
-
this.nfts.delete(
|
|
403
|
+
this.nfts.delete(v(e));
|
|
400
404
|
}
|
|
401
405
|
}
|
|
402
|
-
class
|
|
406
|
+
class ie {
|
|
403
407
|
kvStore;
|
|
404
408
|
client;
|
|
405
409
|
constructor(e) {
|
|
@@ -475,7 +479,7 @@ class he {
|
|
|
475
479
|
}
|
|
476
480
|
async connect(e) {
|
|
477
481
|
try {
|
|
478
|
-
e || (e = await this.getCurrentInstance()), this.client = new
|
|
482
|
+
e || (e = await this.getCurrentInstance()), this.client = new be("com.otoplo.wallet", "1.4.3", e.host, e.port, e.scheme, 45 * 1e3, 10 * 1e3), await this.client.connect();
|
|
479
483
|
} catch (t) {
|
|
480
484
|
throw t instanceof Error ? console.info(t.message) : console.error(t), t;
|
|
481
485
|
}
|
|
@@ -498,7 +502,7 @@ class he {
|
|
|
498
502
|
const t = Date.now();
|
|
499
503
|
return new Promise((s, n) => {
|
|
500
504
|
const i = () => {
|
|
501
|
-
if (this.client?.connectionStatus ==
|
|
505
|
+
if (this.client?.connectionStatus == Se.CONNECTED)
|
|
502
506
|
return s();
|
|
503
507
|
if (Date.now() - t > e)
|
|
504
508
|
return n(new Error("Rostrum Connection timeout"));
|
|
@@ -509,25 +513,25 @@ class he {
|
|
|
509
513
|
}
|
|
510
514
|
async getCurrentInstance() {
|
|
511
515
|
const e = await this.kvStore.getRostrumParams();
|
|
512
|
-
return e ||
|
|
516
|
+
return e || ie.getPredefinedInstances()[0];
|
|
513
517
|
}
|
|
514
518
|
static getPredefinedInstances() {
|
|
515
|
-
return
|
|
519
|
+
return C() ? [
|
|
516
520
|
{
|
|
517
|
-
scheme:
|
|
521
|
+
scheme: H.WSS,
|
|
518
522
|
host: "testnet-electrum.nexa.org",
|
|
519
523
|
port: 30004,
|
|
520
524
|
label: "NexaOrg"
|
|
521
525
|
}
|
|
522
526
|
] : [
|
|
523
527
|
{
|
|
524
|
-
scheme:
|
|
528
|
+
scheme: H.WSS,
|
|
525
529
|
host: "rostrum.otoplo.com",
|
|
526
530
|
port: 443,
|
|
527
531
|
label: "Otoplo"
|
|
528
532
|
},
|
|
529
533
|
{
|
|
530
|
-
scheme:
|
|
534
|
+
scheme: H.WSS,
|
|
531
535
|
host: "electrum.nexa.org",
|
|
532
536
|
port: 20004,
|
|
533
537
|
label: "NexaOrg"
|
|
@@ -535,10 +539,10 @@ class he {
|
|
|
535
539
|
];
|
|
536
540
|
}
|
|
537
541
|
}
|
|
538
|
-
function
|
|
542
|
+
function k(a, e, t) {
|
|
539
543
|
return `${a}'/${e}/${t}`;
|
|
540
544
|
}
|
|
541
|
-
function
|
|
545
|
+
function Ce(a) {
|
|
542
546
|
const e = a.split("/");
|
|
543
547
|
return {
|
|
544
548
|
account: parseInt(e[0].replace("'", "")),
|
|
@@ -546,210 +550,154 @@ function Ke(a) {
|
|
|
546
550
|
index: parseInt(e[2])
|
|
547
551
|
};
|
|
548
552
|
}
|
|
549
|
-
class
|
|
553
|
+
class Pt {
|
|
550
554
|
seed;
|
|
551
555
|
masterKey;
|
|
552
556
|
accountKeys = /* @__PURE__ */ new Map();
|
|
553
557
|
walletKeys = /* @__PURE__ */ new Map();
|
|
554
558
|
init(e) {
|
|
555
|
-
this.seed = typeof e == "string" ?
|
|
559
|
+
this.seed = typeof e == "string" ? ke(e) : e, this.masterKey = J.fromSeed(this.seed).deriveChild(44, !0).deriveChild(29223, !0);
|
|
556
560
|
}
|
|
557
561
|
reset() {
|
|
558
562
|
if (!this.seed)
|
|
559
563
|
throw new Error("KeysManager not initialized");
|
|
560
|
-
this.masterKey =
|
|
564
|
+
this.masterKey = J.fromSeed(this.seed).deriveChild(44, !0).deriveChild(29223, !0), this.accountKeys.clear(), this.walletKeys.clear();
|
|
561
565
|
}
|
|
562
566
|
getAccountKey(e) {
|
|
563
567
|
let t = this.accountKeys.get(e);
|
|
564
568
|
return t || (t = this.masterKey.deriveChild(e, !0), this.accountKeys.set(e, t)), t;
|
|
565
569
|
}
|
|
566
570
|
getKey(e) {
|
|
567
|
-
const t = typeof e == "string" ? e :
|
|
571
|
+
const t = typeof e == "string" ? e : k(e.account, e.type, e.index);
|
|
568
572
|
let s = this.walletKeys.get(t);
|
|
569
573
|
if (!s) {
|
|
570
|
-
const { account: n, type: i, index: o } = typeof e == "string" ?
|
|
574
|
+
const { account: n, type: i, index: o } = typeof e == "string" ? Ce(e) : e;
|
|
571
575
|
s = this.getAccountKey(n).deriveChild(i, !1).deriveChild(o, !1), this.walletKeys.set(t, s);
|
|
572
576
|
}
|
|
573
577
|
return s;
|
|
574
578
|
}
|
|
575
579
|
}
|
|
576
|
-
function
|
|
577
|
-
return {
|
|
578
|
-
name: "NiftyArt",
|
|
579
|
-
ticker: "NIFTY",
|
|
580
|
-
iconUrl: "https://niftyart.cash/td/niftyicon.svg",
|
|
581
|
-
parentGroup: "",
|
|
582
|
-
token: T() ? "nexatest:tq8r37lcjlqazz7vuvug84q2ev50573hesrnxkv9y6hvhhl5k5qqqnmyf79mx" : "nexa:tr9v70v4s9s6jfwz32ts60zqmmkp50lqv7t0ux620d50xa7dhyqqqcg6kdm6f",
|
|
583
|
-
tokenIdHex: T() ? "0e38fbf897c1d10bcce33883d40acb28fa7a37cc0733598526aecbdff4b50000" : "cacf3d958161a925c28a970d3c40deec1a3fe06796fe1b4a7b68f377cdb90000",
|
|
584
|
-
decimals: 0
|
|
585
|
-
};
|
|
586
|
-
}
|
|
587
|
-
function Ht(a) {
|
|
588
|
-
return Z(Ge() + a, "raw");
|
|
589
|
-
}
|
|
590
|
-
function q(a) {
|
|
591
|
-
try {
|
|
592
|
-
const e = H(a);
|
|
593
|
-
return O.isSubgroup(e) ? y.bufferToHex(e.subarray(0, 32)) === fe().tokenIdHex : !1;
|
|
594
|
-
} catch {
|
|
595
|
-
return !1;
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
function Le(a) {
|
|
599
|
-
return a = Y(a), Z(a, "json");
|
|
600
|
-
}
|
|
601
|
-
function Fe(a) {
|
|
602
|
-
return a = Y(a), Z(a, "raw");
|
|
603
|
-
}
|
|
604
|
-
function ce(a, e) {
|
|
580
|
+
function Bt(a, e) {
|
|
605
581
|
return a && typeof a == "string" ? a.startsWith("http") ? a.replace("http://", "https://") : a.startsWith("ipfs://") ? a : `${new URL(e).origin}${a}` : "";
|
|
606
582
|
}
|
|
607
|
-
function
|
|
608
|
-
return a ?
|
|
583
|
+
function Ot(a) {
|
|
584
|
+
return a ? Pe(a) : null;
|
|
609
585
|
}
|
|
610
|
-
function
|
|
586
|
+
function Pe(a, e = "https://ipfs.nebula.markets/") {
|
|
611
587
|
return a?.startsWith("ipfs://") ? e + a.substring(7) : a;
|
|
612
588
|
}
|
|
613
|
-
function
|
|
614
|
-
return
|
|
589
|
+
function Be(a) {
|
|
590
|
+
return Oe(`${re()}/metadata/${a}`, "json");
|
|
591
|
+
}
|
|
592
|
+
function _t(a, e) {
|
|
593
|
+
return `${re()}/assets/${a}/${e}`;
|
|
594
|
+
}
|
|
595
|
+
function re() {
|
|
596
|
+
return `https://${C() ? "testapi" : "api"}.otoplo.com`;
|
|
615
597
|
}
|
|
616
|
-
async function
|
|
598
|
+
async function Oe(a, e) {
|
|
617
599
|
try {
|
|
618
600
|
const t = await fetch(a);
|
|
619
601
|
if (!t.ok)
|
|
620
602
|
throw new Error(`Failed to perform GET. status: ${t.status}`);
|
|
621
|
-
if (e
|
|
622
|
-
const s = await t.arrayBuffer();
|
|
623
|
-
return new Uint8Array(s);
|
|
624
|
-
} else
|
|
625
|
-
return await t.json();
|
|
603
|
+
if (e !== "raw") return await t.json();
|
|
626
604
|
} catch (t) {
|
|
627
605
|
throw new Error(`Unexpected Error: ${t}`);
|
|
628
606
|
}
|
|
629
607
|
}
|
|
630
|
-
class
|
|
608
|
+
class Ut {
|
|
631
609
|
walletDb;
|
|
632
|
-
rostrumService;
|
|
633
610
|
walletCache;
|
|
634
|
-
constructor(e, t
|
|
635
|
-
this.walletDb = e, this.
|
|
611
|
+
constructor(e, t) {
|
|
612
|
+
this.walletDb = e, this.walletCache = t;
|
|
636
613
|
}
|
|
637
|
-
async
|
|
614
|
+
async getAssetInfo(e) {
|
|
638
615
|
try {
|
|
639
|
-
if (
|
|
640
|
-
const
|
|
641
|
-
|
|
642
|
-
|
|
616
|
+
if (this.walletCache.hasToken(e)) {
|
|
617
|
+
const t = await this.walletCache.getToken(e);
|
|
618
|
+
return {
|
|
619
|
+
type: "token",
|
|
620
|
+
parent: t.parent,
|
|
621
|
+
token: t.token,
|
|
622
|
+
tokenIdHex: t.tokenIdHex,
|
|
623
|
+
data: {
|
|
624
|
+
name: t.name,
|
|
625
|
+
ticker: t.ticker,
|
|
626
|
+
decimals: t.decimals,
|
|
627
|
+
iconUrl: t.iconUrl
|
|
628
|
+
}
|
|
629
|
+
};
|
|
643
630
|
}
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
631
|
+
if (this.walletCache.hasNft(e)) {
|
|
632
|
+
const t = await this.walletCache.getNft(e);
|
|
633
|
+
return {
|
|
634
|
+
type: "nft",
|
|
635
|
+
parent: t.parent,
|
|
636
|
+
token: t.token,
|
|
637
|
+
tokenIdHex: t.tokenIdHex,
|
|
638
|
+
data: {
|
|
639
|
+
name: t.name,
|
|
640
|
+
series: t.series,
|
|
641
|
+
collection: t.collection,
|
|
642
|
+
author: t.author,
|
|
643
|
+
public: t.public,
|
|
644
|
+
front: t.front,
|
|
645
|
+
back: t.back
|
|
659
646
|
}
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
return {
|
|
664
|
-
token: s.group,
|
|
665
|
-
tokenIdHex: s.token_id_hex,
|
|
666
|
-
decimals: s.decimal_places ?? 0,
|
|
667
|
-
parentGroup: i,
|
|
668
|
-
name: s.name ?? "",
|
|
669
|
-
ticker: s.ticker ?? "",
|
|
670
|
-
iconUrl: o
|
|
671
|
-
};
|
|
672
|
-
} catch (s) {
|
|
673
|
-
console.error(s);
|
|
674
|
-
return;
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
async isNftToken(e) {
|
|
678
|
-
try {
|
|
679
|
-
if (q(e) || await this.walletCache.getNftById(e) || (await this.rostrumService.getTokenGenesis(e)).op_return_id == I.NRC3)
|
|
680
|
-
return !0;
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
return await Be(e);
|
|
681
650
|
} catch (t) {
|
|
682
651
|
console.error(t);
|
|
652
|
+
return;
|
|
683
653
|
}
|
|
684
|
-
return !1;
|
|
685
|
-
}
|
|
686
|
-
async getAssetInfo(e) {
|
|
687
|
-
let t = await this.getTokenInfo(e);
|
|
688
|
-
return t || await this.isNftToken(e) && (t = {
|
|
689
|
-
token: re(e),
|
|
690
|
-
tokenIdHex: b(e),
|
|
691
|
-
decimals: 0
|
|
692
|
-
}), t;
|
|
693
654
|
}
|
|
694
655
|
async handleNftReceive(e, t, s) {
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
656
|
+
const n = await this.getAssetInfo(t);
|
|
657
|
+
if (n && n.type == "nft") {
|
|
658
|
+
const i = {
|
|
659
|
+
token: n.token,
|
|
660
|
+
tokenIdHex: n.tokenIdHex,
|
|
661
|
+
parent: n.parent,
|
|
662
|
+
...n.data
|
|
701
663
|
};
|
|
702
|
-
await this.walletDb.
|
|
703
|
-
return;
|
|
664
|
+
await this.walletDb.saveNft(e, i, s);
|
|
704
665
|
}
|
|
705
|
-
const i = await this.rostrumService.getTokenGenesis(t);
|
|
706
|
-
if (i.op_return_id == I.NRC3) {
|
|
707
|
-
const o = H(t);
|
|
708
|
-
if (O.isSubgroup(o)) {
|
|
709
|
-
const r = new S(o.subarray(0, 32), k.defaultNetwork, E.GroupIdAddress).toString(), c = await this.rostrumService.getTokenGenesis(r);
|
|
710
|
-
c?.op_return_id == I.NRC2 && await this.saveNft(e, t, i.document_url ?? "", r, s, c?.name ?? "");
|
|
711
|
-
}
|
|
712
|
-
} else q(t) && await this.saveNft(e, t, "nifty", fe().token, s, "");
|
|
713
666
|
}
|
|
714
|
-
async
|
|
715
|
-
if (s)
|
|
716
|
-
try {
|
|
717
|
-
const r = {
|
|
718
|
-
accountId: e,
|
|
719
|
-
tokenIdHex: t,
|
|
720
|
-
type: R.NFT,
|
|
721
|
-
addedTime: i
|
|
722
|
-
}, c = {
|
|
723
|
-
parentGroup: n,
|
|
724
|
-
token: re(t),
|
|
725
|
-
tokenIdHex: t,
|
|
726
|
-
source: s,
|
|
727
|
-
collection: o
|
|
728
|
-
};
|
|
729
|
-
await this.walletDb.saveNft(r, c);
|
|
730
|
-
} catch (r) {
|
|
731
|
-
console.error("failed to save NFT", r);
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
async fetchAndSaveTokens(e, t) {
|
|
667
|
+
async syncTokens(e, t) {
|
|
735
668
|
for (const s in t) {
|
|
736
|
-
const n =
|
|
737
|
-
n &&
|
|
669
|
+
const n = t[s];
|
|
670
|
+
if (n && BigInt(n.confirmed) + BigInt(n.unconfirmed) > 0n) {
|
|
671
|
+
const i = await this.getAssetInfo(s);
|
|
672
|
+
if (i && i.type == "token") {
|
|
673
|
+
const o = {
|
|
674
|
+
token: i.token,
|
|
675
|
+
tokenIdHex: i.tokenIdHex,
|
|
676
|
+
parent: i.parent,
|
|
677
|
+
...i.data
|
|
678
|
+
};
|
|
679
|
+
await this.walletDb.saveToken(e, o);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
738
682
|
}
|
|
739
683
|
}
|
|
740
684
|
async syncNfts(e, t) {
|
|
741
|
-
const s = Object.keys(t), n = await this.walletDb.
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
for (const r of
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
const d = b(r), u = c && BigInt(c.confirmed) + BigInt(c.unconfirmed) > 0n, l = n?.some((p) => p.tokenIdHex == d);
|
|
748
|
-
!u && !l || u && l || !await this.isNftToken(d) || (!u && l ? await i(d) : await this.handleNftReceive(e, d, X()));
|
|
685
|
+
const s = Object.keys(t), n = await this.walletDb.getAssets(e, "nft"), i = n?.filter((o) => !s.includes(o.tokenIdHex)) ?? [];
|
|
686
|
+
for (const o of i)
|
|
687
|
+
await this.deleteNft(e, o.tokenIdHex);
|
|
688
|
+
for (const [o, r] of Object.entries(t)) {
|
|
689
|
+
const c = v(o), d = r && BigInt(r.confirmed) + BigInt(r.unconfirmed) > 0n, u = n?.some((l) => l.tokenIdHex == c);
|
|
690
|
+
!d && !u || d && u || (!d && u ? await this.deleteNft(e, c) : await this.handleNftReceive(e, c, G()));
|
|
749
691
|
}
|
|
750
692
|
}
|
|
693
|
+
async deleteToken(e, t) {
|
|
694
|
+
await this.walletDb.deleteToken(e, t), this.walletCache.removeToken(t);
|
|
695
|
+
}
|
|
696
|
+
async deleteNft(e, t) {
|
|
697
|
+
await this.walletDb.deleteNft(e, t), this.walletCache.removeNft(t);
|
|
698
|
+
}
|
|
751
699
|
}
|
|
752
|
-
class
|
|
700
|
+
class Dt {
|
|
753
701
|
rostrumService;
|
|
754
702
|
keyManager;
|
|
755
703
|
walletDb;
|
|
@@ -768,7 +716,7 @@ class Ft {
|
|
|
768
716
|
return { txs: i, lastHeight: s };
|
|
769
717
|
}
|
|
770
718
|
async fetchVaultTransactions(e) {
|
|
771
|
-
const t = await this.rostrumService.getTransactionsHistory(e,
|
|
719
|
+
const t = await this.rostrumService.getTransactionsHistory(e, Ee), s = [];
|
|
772
720
|
for (const n of t) {
|
|
773
721
|
const i = this.classifyTransaction(n.tx_hash, [e]);
|
|
774
722
|
s.push(i);
|
|
@@ -797,23 +745,23 @@ class Ft {
|
|
|
797
745
|
async classifyTransaction(e, t) {
|
|
798
746
|
const s = await this.rostrumService.getTransaction(e), n = [], i = [], o = [], r = [];
|
|
799
747
|
for (const l of s.vin) {
|
|
800
|
-
const
|
|
748
|
+
const p = {
|
|
801
749
|
address: l.addresses[0],
|
|
802
750
|
nexaAmount: l.value_satoshi.toString(),
|
|
803
751
|
assetId: l.token_id_hex ?? "",
|
|
804
|
-
assetAmount:
|
|
752
|
+
assetAmount: U(l.groupQuantity)
|
|
805
753
|
};
|
|
806
|
-
t.includes(
|
|
754
|
+
t.includes(p.address) ? n.push(p) : i.push(p);
|
|
807
755
|
}
|
|
808
756
|
for (const l of s.vout) {
|
|
809
|
-
if (
|
|
810
|
-
const
|
|
757
|
+
if (M(l.scriptPubKey.addresses)) continue;
|
|
758
|
+
const p = {
|
|
811
759
|
address: l.scriptPubKey.addresses[0],
|
|
812
760
|
nexaAmount: l.value_satoshi.toString(),
|
|
813
761
|
assetId: l.scriptPubKey.token_id_hex ?? "",
|
|
814
|
-
assetAmount:
|
|
762
|
+
assetAmount: U(l.scriptPubKey.groupQuantity)
|
|
815
763
|
};
|
|
816
|
-
t.includes(
|
|
764
|
+
t.includes(p.address) ? o.push(p) : r.push(p);
|
|
817
765
|
}
|
|
818
766
|
let c;
|
|
819
767
|
n.length === 0 ? c = "receive" : o.length === 0 ? c = "send" : i.length === 0 && r.length === 0 ? c = "self" : i.length === 0 && r.length > 0 ? c = "send" : i.length > 0 && r.length === 0 ? c = "receive" : c = "swap";
|
|
@@ -823,7 +771,7 @@ class Ft {
|
|
|
823
771
|
// Will be set in classifyAndSaveTransaction
|
|
824
772
|
txId: s.txid,
|
|
825
773
|
txIdem: s.txidem,
|
|
826
|
-
time: d ? s.time :
|
|
774
|
+
time: d ? s.time : G(),
|
|
827
775
|
height: d ? s.height : 0,
|
|
828
776
|
type: c,
|
|
829
777
|
fee: s.fee_satoshi.toString(),
|
|
@@ -839,72 +787,72 @@ class Ft {
|
|
|
839
787
|
r && u.feePerByte(r);
|
|
840
788
|
let l = /* @__PURE__ */ new Map();
|
|
841
789
|
o && (l = await this.populateTokenInputsAndChange(u, e, s, o, BigInt(n)));
|
|
842
|
-
const
|
|
843
|
-
return l.forEach((
|
|
790
|
+
const p = await this.populateNexaInputsAndChange(u, e, s, d);
|
|
791
|
+
return l.forEach((f, P) => p.set(P, f)), await this.finalizeTransaction(u, Array.from(p.values()));
|
|
844
792
|
}
|
|
845
793
|
async buildAndSignConsolidateTransaction(e, t, s) {
|
|
846
794
|
const n = {
|
|
847
795
|
isConsolidate: !0,
|
|
848
796
|
templateData: s
|
|
849
|
-
}, i = new
|
|
797
|
+
}, i = new j(), o = await this.populateNexaInputsAndChange(i, e, t, n);
|
|
850
798
|
return this.finalizeTransaction(i, Array.from(o.values()));
|
|
851
799
|
}
|
|
852
800
|
prepareTransaction(e, t, s, n) {
|
|
853
|
-
if (!
|
|
801
|
+
if (!R(e) && !R(e, O.PayToPublicKeyHash))
|
|
854
802
|
throw new Error("Invalid Address.");
|
|
855
|
-
if (s && BigInt(t) < 1n || !s && parseInt(t) <
|
|
803
|
+
if (s && BigInt(t) < 1n || !s && parseInt(t) < x.DUST_AMOUNT)
|
|
856
804
|
throw new Error("The amount is too low.");
|
|
857
|
-
if (s && BigInt(t) >
|
|
805
|
+
if (s && BigInt(t) > Z || !s && parseInt(t) > x.MAX_MONEY)
|
|
858
806
|
throw new Error("The amount is too high.");
|
|
859
|
-
const i = new
|
|
807
|
+
const i = new j();
|
|
860
808
|
if (n && i.addData(n), s) {
|
|
861
|
-
if (!
|
|
809
|
+
if (!R(s, O.GroupIdAddress))
|
|
862
810
|
throw new Error("Invalid Token ID");
|
|
863
|
-
if (
|
|
811
|
+
if (I.getOutputType(e) === 0)
|
|
864
812
|
throw new Error("Token must be sent to script template address");
|
|
865
|
-
i.to(e,
|
|
813
|
+
i.to(e, x.DUST_AMOUNT, s, BigInt(t));
|
|
866
814
|
} else
|
|
867
815
|
i.to(e, t);
|
|
868
816
|
return i;
|
|
869
817
|
}
|
|
870
818
|
async populateNexaInputsAndChange(e, t, s, n) {
|
|
871
819
|
const i = t.filter((d) => BigInt(d.balance.confirmed) + BigInt(d.balance.unconfirmed) > 0n);
|
|
872
|
-
if (
|
|
820
|
+
if (M(i))
|
|
873
821
|
throw new Error("Not enough Nexa balance.");
|
|
874
822
|
const o = /* @__PURE__ */ new Map(), r = n.isConsolidate ? 0 : Number(e.transaction.outputs.find((d) => d.value > 0n).value);
|
|
875
823
|
for (const d of i) {
|
|
876
824
|
const u = await this.rostrumService.getNexaUtxos(d.address);
|
|
877
825
|
for (const l of u) {
|
|
878
|
-
const
|
|
826
|
+
const p = {
|
|
879
827
|
outpoint: l.outpoint_hash,
|
|
880
828
|
address: d.address,
|
|
881
829
|
satoshis: l.value,
|
|
882
830
|
templateData: n.templateData
|
|
883
831
|
};
|
|
884
|
-
if (e.from(
|
|
885
|
-
const
|
|
886
|
-
o.set(d.address,
|
|
832
|
+
if (e.from(p), !o.has(d.address)) {
|
|
833
|
+
const f = this.keyManager.getKey(d.keyPath);
|
|
834
|
+
o.set(d.address, f.privateKey);
|
|
887
835
|
}
|
|
888
836
|
if (n.isConsolidate) {
|
|
889
837
|
if (e.change(s), e.transaction.inputs.length > this.MAX_INPUTS_OUTPUTS)
|
|
890
838
|
return o;
|
|
891
839
|
} else {
|
|
892
|
-
const
|
|
893
|
-
if (
|
|
840
|
+
const f = e.transaction;
|
|
841
|
+
if (f.inputs.length > this.MAX_INPUTS_OUTPUTS)
|
|
894
842
|
throw new Error("Too many inputs. Consider consolidate transactions or reduce the send amount.");
|
|
895
|
-
const
|
|
896
|
-
if (
|
|
843
|
+
const P = f.getUnspentValue();
|
|
844
|
+
if (P < 0n)
|
|
897
845
|
continue;
|
|
898
|
-
if (
|
|
899
|
-
const
|
|
900
|
-
return
|
|
846
|
+
if (P == 0n && n.feeFromAmount) {
|
|
847
|
+
const D = f.estimateRequiredFee();
|
|
848
|
+
return f.updateOutputAmount(0, r - D), o;
|
|
901
849
|
}
|
|
902
850
|
if (e.change(s), n.feeFromAmount) {
|
|
903
|
-
const
|
|
904
|
-
let
|
|
905
|
-
|
|
851
|
+
const D = f.getChangeOutput();
|
|
852
|
+
let V = f.estimateRequiredFee();
|
|
853
|
+
f.updateOutputAmount(0, r - V), !D && f.getChangeOutput() && (V = f.estimateRequiredFee(), f.updateOutputAmount(0, r - V));
|
|
906
854
|
}
|
|
907
|
-
if (
|
|
855
|
+
if (f.getUnspentValue() < f.estimateRequiredFee())
|
|
908
856
|
continue;
|
|
909
857
|
return o;
|
|
910
858
|
}
|
|
@@ -917,39 +865,39 @@ class Ft {
|
|
|
917
865
|
}
|
|
918
866
|
const c = {
|
|
919
867
|
errorMsg: "Not enough Nexa balance.",
|
|
920
|
-
amount:
|
|
921
|
-
fee:
|
|
868
|
+
amount: z.formatNEXA(e.transaction.outputs[0].value),
|
|
869
|
+
fee: z.formatNEXA(e.transaction.estimateRequiredFee())
|
|
922
870
|
};
|
|
923
871
|
throw new Error(JSON.stringify(c));
|
|
924
872
|
}
|
|
925
873
|
async populateTokenInputsAndChange(e, t, s, n, i) {
|
|
926
|
-
const o =
|
|
927
|
-
if (
|
|
874
|
+
const o = v(n), r = t.filter((u) => Object.keys(u.tokensBalance).includes(o));
|
|
875
|
+
if (M(r))
|
|
928
876
|
throw new Error("Not enough token balance.");
|
|
929
877
|
const c = /* @__PURE__ */ new Map();
|
|
930
878
|
let d = 0n;
|
|
931
879
|
for (const u of r) {
|
|
932
880
|
const l = await this.rostrumService.getTokenUtxos(u.address, n);
|
|
933
|
-
for (const
|
|
934
|
-
if (!(BigInt(
|
|
881
|
+
for (const p of l)
|
|
882
|
+
if (!(BigInt(p.token_amount) < 0n)) {
|
|
935
883
|
if (e.from({
|
|
936
|
-
outpoint:
|
|
884
|
+
outpoint: p.outpoint_hash,
|
|
937
885
|
address: u.address,
|
|
938
|
-
satoshis:
|
|
939
|
-
groupId:
|
|
940
|
-
groupAmount: BigInt(
|
|
941
|
-
}), d = d + BigInt(
|
|
942
|
-
const
|
|
943
|
-
c.set(u.address,
|
|
886
|
+
satoshis: p.value,
|
|
887
|
+
groupId: p.group,
|
|
888
|
+
groupAmount: BigInt(p.token_amount)
|
|
889
|
+
}), d = d + BigInt(p.token_amount), !c.has(u.address)) {
|
|
890
|
+
const f = this.keyManager.getKey(u.keyPath);
|
|
891
|
+
c.set(u.address, f.privateKey);
|
|
944
892
|
}
|
|
945
|
-
if (d >
|
|
893
|
+
if (d > Z)
|
|
946
894
|
throw new Error("Token inputs exceeded max amount. Consider sending in small chunks");
|
|
947
895
|
if (e.transaction.inputs.length > this.MAX_INPUTS_OUTPUTS)
|
|
948
896
|
throw new Error("Too many inputs. Consider consolidating transactions or reduce the send amount.");
|
|
949
897
|
if (d == i)
|
|
950
898
|
return c;
|
|
951
899
|
if (d > i)
|
|
952
|
-
return e.to(s,
|
|
900
|
+
return e.to(s, x.DUST_AMOUNT, n, d - i), c;
|
|
953
901
|
}
|
|
954
902
|
}
|
|
955
903
|
throw new Error("Not enough token balance");
|
|
@@ -968,13 +916,13 @@ class Ft {
|
|
|
968
916
|
return JSON.stringify(t, null, 2);
|
|
969
917
|
}
|
|
970
918
|
}
|
|
971
|
-
function
|
|
972
|
-
return
|
|
919
|
+
function Vt(a = 12) {
|
|
920
|
+
return Te(se, a === 24 ? 256 : 128);
|
|
973
921
|
}
|
|
974
|
-
function
|
|
975
|
-
return
|
|
922
|
+
function _e(a) {
|
|
923
|
+
return Ie(a, se);
|
|
976
924
|
}
|
|
977
|
-
async function
|
|
925
|
+
async function oe(a, e) {
|
|
978
926
|
const t = await crypto.subtle.importKey(
|
|
979
927
|
"raw",
|
|
980
928
|
new Uint8Array(a),
|
|
@@ -998,19 +946,19 @@ async function pe(a, e) {
|
|
|
998
946
|
["encrypt", "decrypt"]
|
|
999
947
|
);
|
|
1000
948
|
}
|
|
1001
|
-
async function
|
|
1002
|
-
const t =
|
|
949
|
+
async function Ht(a, e) {
|
|
950
|
+
const t = m.utf8ToBuffer(e), s = m.getRandomBuffer(16), n = m.getRandomBuffer(12), i = m.utf8ToBuffer(a), o = await oe(t, s), r = await crypto.subtle.encrypt(
|
|
1003
951
|
{
|
|
1004
952
|
name: "AES-GCM",
|
|
1005
953
|
iv: new Uint8Array(n)
|
|
1006
954
|
},
|
|
1007
955
|
o,
|
|
1008
956
|
new Uint8Array(i)
|
|
1009
|
-
), c =
|
|
1010
|
-
return
|
|
957
|
+
), c = m.concat([s, n, new Uint8Array(r)]);
|
|
958
|
+
return m.bufferToBase64(c);
|
|
1011
959
|
}
|
|
1012
|
-
async function
|
|
1013
|
-
const t =
|
|
960
|
+
async function Ue(a, e) {
|
|
961
|
+
const t = m.utf8ToBuffer(e), s = m.base64ToBuffer(a), n = s.slice(0, 16), i = s.slice(16, 28), o = s.slice(28), r = await oe(t, n), c = await crypto.subtle.decrypt(
|
|
1014
962
|
{
|
|
1015
963
|
name: "AES-GCM",
|
|
1016
964
|
iv: i
|
|
@@ -1018,13 +966,13 @@ async function qe(a, e) {
|
|
|
1018
966
|
r,
|
|
1019
967
|
o
|
|
1020
968
|
);
|
|
1021
|
-
return
|
|
969
|
+
return m.bufferToUtf8(new Uint8Array(c));
|
|
1022
970
|
}
|
|
1023
|
-
async function
|
|
971
|
+
async function Rt(a, e) {
|
|
1024
972
|
try {
|
|
1025
973
|
if (a) {
|
|
1026
|
-
const t = await
|
|
1027
|
-
if (t &&
|
|
974
|
+
const t = await Ue(a, e);
|
|
975
|
+
if (t && _e(t))
|
|
1028
976
|
return t;
|
|
1029
977
|
}
|
|
1030
978
|
return !1;
|
|
@@ -1032,57 +980,83 @@ async function qt(a, e) {
|
|
|
1032
980
|
return !1;
|
|
1033
981
|
}
|
|
1034
982
|
}
|
|
1035
|
-
const
|
|
983
|
+
const ce = [
|
|
1036
984
|
{ code: "usd", symbol: "$", name: "US Dollar" },
|
|
1037
985
|
{ code: "eur", symbol: "€", name: "Euro" },
|
|
1038
986
|
{ code: "gbp", symbol: "£", name: "British Pound" },
|
|
1039
|
-
{ code: "cny", symbol: "¥", name: "Chinese Yuan" },
|
|
1040
|
-
{ code: "jpy", symbol: "¥", name: "Japanese Yen" },
|
|
1041
987
|
{ code: "aud", symbol: "A$", name: "Australian Dollar" },
|
|
1042
988
|
{ code: "cad", symbol: "C$", name: "Canadian Dollar" },
|
|
1043
|
-
{ code: "chf", symbol: "Fr", name: "Swiss Franc" }
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
989
|
+
{ code: "chf", symbol: "Fr", name: "Swiss Franc" },
|
|
990
|
+
{ code: "inr", symbol: "₹", name: "Indian Rupee" },
|
|
991
|
+
{ code: "cny", symbol: "¥", name: "Chinese Yuan" },
|
|
992
|
+
{ code: "jpy", symbol: "¥", name: "Japanese Yen" }
|
|
993
|
+
], De = Object.fromEntries(
|
|
994
|
+
ce.map((a) => [a.code, a.symbol])
|
|
995
|
+
), Kt = ce.map((a) => a.code), ee = {
|
|
996
|
+
nexacoin: "nexa"
|
|
997
|
+
};
|
|
998
|
+
async function Ve(a) {
|
|
999
|
+
const e = Object.keys(ee).join(","), t = await fetch(`https://api.coingecko.com/api/v3/coins/markets?ids=${e}&vs_currency=${a}`);
|
|
1000
|
+
if (!t.ok)
|
|
1001
|
+
throw new Error("Failed to fetch market data");
|
|
1002
|
+
const s = await t.json(), n = {};
|
|
1003
|
+
return s.forEach((i) => {
|
|
1004
|
+
n[ee[i.id]] = {
|
|
1005
|
+
id: i.id,
|
|
1006
|
+
name: i.name ?? "",
|
|
1007
|
+
symbol: i.symbol ?? "",
|
|
1008
|
+
image: i.image ?? "",
|
|
1009
|
+
price: i.current_price ?? 0,
|
|
1010
|
+
priceChange: i.price_change_24h,
|
|
1011
|
+
priceChangePercentage: i.price_change_percentage_24h,
|
|
1012
|
+
marketCap: i.market_cap,
|
|
1013
|
+
fdv: i.fully_diluted_valuation,
|
|
1014
|
+
circSupply: i.circulating_supply,
|
|
1015
|
+
totalSupply: i.total_supply,
|
|
1016
|
+
maxSupply: i.max_supply,
|
|
1017
|
+
totalVolume: i.total_volume
|
|
1018
|
+
};
|
|
1019
|
+
}), n;
|
|
1020
|
+
}
|
|
1021
|
+
function Lt(a) {
|
|
1022
|
+
return De[a] || a;
|
|
1052
1023
|
}
|
|
1053
|
-
function
|
|
1054
|
-
|
|
1024
|
+
function Ft(a, e, t) {
|
|
1025
|
+
const s = B.multiply(a, e), n = B.round(s, 2, B.RoundingModes.HALF_DOWN);
|
|
1026
|
+
return t ? He(n, t) : n;
|
|
1055
1027
|
}
|
|
1056
|
-
function
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1028
|
+
function He(a, e, t = "en-US") {
|
|
1029
|
+
return new Intl.NumberFormat(t, {
|
|
1030
|
+
style: "currency",
|
|
1031
|
+
currency: e,
|
|
1032
|
+
maximumFractionDigits: 2,
|
|
1033
|
+
minimumFractionDigits: 2
|
|
1034
|
+
}).format(Number(a));
|
|
1061
1035
|
}
|
|
1062
|
-
function
|
|
1063
|
-
return
|
|
1036
|
+
function Re() {
|
|
1037
|
+
return b.empty().add(A.OP_FROMALTSTACK).add(A.OP_DROP).add(A.OP_FROMALTSTACK).add(A.OP_CHECKLOCKTIMEVERIFY).add(A.OP_DROP).add(A.OP_FROMALTSTACK).add(A.OP_CHECKSIGVERIFY);
|
|
1064
1038
|
}
|
|
1065
|
-
function
|
|
1066
|
-
const a =
|
|
1067
|
-
return
|
|
1039
|
+
function Ke() {
|
|
1040
|
+
const a = Re();
|
|
1041
|
+
return _.sha256ripemd160(a.toBuffer());
|
|
1068
1042
|
}
|
|
1069
|
-
function
|
|
1070
|
-
return
|
|
1043
|
+
function Le(a) {
|
|
1044
|
+
return b.empty().add(a.toBuffer());
|
|
1071
1045
|
}
|
|
1072
|
-
function
|
|
1073
|
-
const e =
|
|
1074
|
-
return
|
|
1046
|
+
function Fe(a) {
|
|
1047
|
+
const e = Le(a);
|
|
1048
|
+
return _.sha256ripemd160(e.toBuffer());
|
|
1075
1049
|
}
|
|
1076
|
-
function
|
|
1077
|
-
return a.map((e) => e <= 16 ?
|
|
1050
|
+
function $e(a) {
|
|
1051
|
+
return a.map((e) => e <= 16 ? L.smallInt(e) : F.fromNumber(e).toScriptNumBuffer());
|
|
1078
1052
|
}
|
|
1079
|
-
function
|
|
1053
|
+
function We(a, e) {
|
|
1080
1054
|
if (e.length !== 2)
|
|
1081
1055
|
return;
|
|
1082
|
-
const t =
|
|
1083
|
-
return
|
|
1056
|
+
const t = Ke(), s = Fe(a), n = $e(e);
|
|
1057
|
+
return I.fromScriptTemplate(t, s, n).toString();
|
|
1084
1058
|
}
|
|
1085
|
-
class
|
|
1059
|
+
class $t {
|
|
1086
1060
|
walletDb;
|
|
1087
1061
|
keyManager;
|
|
1088
1062
|
providers;
|
|
@@ -1116,25 +1090,25 @@ class zt {
|
|
|
1116
1090
|
}
|
|
1117
1091
|
async reload(e) {
|
|
1118
1092
|
for (const t of e.values()) {
|
|
1119
|
-
if (t.id ==
|
|
1093
|
+
if (t.id == w)
|
|
1120
1094
|
continue;
|
|
1121
1095
|
const s = await this.walletDb.getAccountSessions(t.id), n = this.providers.get(t.id), i = s.map(async (r) => {
|
|
1122
1096
|
if (n?.has(r.sessionId))
|
|
1123
1097
|
return;
|
|
1124
1098
|
let c;
|
|
1125
1099
|
try {
|
|
1126
|
-
c = new
|
|
1100
|
+
c = new xe(r.uri);
|
|
1127
1101
|
const d = c.getSessionInfo();
|
|
1128
1102
|
await c.connect(3e3);
|
|
1129
1103
|
const u = await c.getAppInfo(2e3);
|
|
1130
1104
|
await c.joinSession(t.address, 2e3);
|
|
1131
1105
|
const l = await c.fetchPendingMessages();
|
|
1132
|
-
for (const
|
|
1106
|
+
for (const p of l)
|
|
1133
1107
|
this.notify({
|
|
1134
1108
|
type: "new_notification",
|
|
1135
1109
|
notification: {
|
|
1136
1110
|
id: crypto.randomUUID(),
|
|
1137
|
-
createdAt:
|
|
1111
|
+
createdAt: p.createdAt,
|
|
1138
1112
|
type: "web3",
|
|
1139
1113
|
title: "Request pending approval",
|
|
1140
1114
|
message: `A connected dApp (${u.name}) has requested an action from your Account: ${t.name}. Review the request details before approving or rejecting.`,
|
|
@@ -1142,7 +1116,7 @@ class zt {
|
|
|
1142
1116
|
type: "DAPP_REQUEST",
|
|
1143
1117
|
account: t.id,
|
|
1144
1118
|
sessionId: d.sessionId,
|
|
1145
|
-
payload:
|
|
1119
|
+
payload: p.message
|
|
1146
1120
|
}
|
|
1147
1121
|
}
|
|
1148
1122
|
});
|
|
@@ -1189,14 +1163,14 @@ class zt {
|
|
|
1189
1163
|
const n = (i, o) => new Promise((r, c) => {
|
|
1190
1164
|
this.handlers.set(i, { resolve: r, reject: c }), this.notify({ type: "new_request", request: { type: i, accountId: e.id, sessionId: s, request: o } });
|
|
1191
1165
|
});
|
|
1192
|
-
t.onSignMessage((i) => n(
|
|
1193
|
-
const i = { account:
|
|
1166
|
+
t.onSignMessage((i) => n(N.SignMessage, i)), t.onAddToken((i) => n(N.AddToken, i)), t.onSendTransaction((i) => n(N.SendTransaction, i)), t.onSignTransaction((i) => n(N.SignTransaction, i)), t.onGetAccount(() => {
|
|
1167
|
+
const i = { account: h.DAPP, type: y.RECEIVE, index: e.id };
|
|
1194
1168
|
return {
|
|
1195
1169
|
name: e.name,
|
|
1196
1170
|
address: e.address,
|
|
1197
1171
|
pubkey: this.keyManager.getKey(i).publicKey.toString(),
|
|
1198
1172
|
blockchain: "nexa",
|
|
1199
|
-
network:
|
|
1173
|
+
network: E.defaultNetwork.name,
|
|
1200
1174
|
capabilities: {
|
|
1201
1175
|
addToken: !0,
|
|
1202
1176
|
sendTransaction: !0,
|
|
@@ -1207,7 +1181,7 @@ class zt {
|
|
|
1207
1181
|
});
|
|
1208
1182
|
}
|
|
1209
1183
|
}
|
|
1210
|
-
class
|
|
1184
|
+
class Wt {
|
|
1211
1185
|
rostrumService;
|
|
1212
1186
|
keyManager;
|
|
1213
1187
|
assetService;
|
|
@@ -1224,7 +1198,7 @@ class $t {
|
|
|
1224
1198
|
address: t.address,
|
|
1225
1199
|
privateKey: this.keyManager.getKey(t.keyPath).privateKey,
|
|
1226
1200
|
txDetails: {
|
|
1227
|
-
tx: new
|
|
1201
|
+
tx: new x(e),
|
|
1228
1202
|
send: [],
|
|
1229
1203
|
receive: []
|
|
1230
1204
|
},
|
|
@@ -1248,16 +1222,16 @@ class $t {
|
|
|
1248
1222
|
await Promise.all(t);
|
|
1249
1223
|
}
|
|
1250
1224
|
async processInput(e, t) {
|
|
1251
|
-
const s = e.txDetails.tx.inputs[t], n = await this.rostrumService.getUtxo(
|
|
1225
|
+
const s = e.txDetails.tx.inputs[t], n = await this.rostrumService.getUtxo(m.bufferToHex(s.outpoint));
|
|
1252
1226
|
if (n.status == "spent")
|
|
1253
1227
|
throw new Error("Input UTXO is already spent.");
|
|
1254
|
-
if (s.output = new
|
|
1228
|
+
if (s.output = new we(n.amount, n.scriptpubkey), s.output.address == e.address) {
|
|
1255
1229
|
const i = n.token_id_hex || "NEXA";
|
|
1256
1230
|
e.myInputs.set(t, {
|
|
1257
1231
|
address: e.address,
|
|
1258
1232
|
nexaAmount: n.amount.toString(),
|
|
1259
1233
|
assetId: i,
|
|
1260
|
-
assetAmount:
|
|
1234
|
+
assetAmount: U(n.group_quantity) || n.amount.toString()
|
|
1261
1235
|
}), e.involvedAssets.add(i), s.scriptSig.isEmpty() && e.inputsToSign.add(t);
|
|
1262
1236
|
}
|
|
1263
1237
|
s.scriptSig.findPlaceholder() > 0 && e.inputsToSign.add(t);
|
|
@@ -1267,11 +1241,11 @@ class $t {
|
|
|
1267
1241
|
const s = e.txDetails.tx.outputs[t].toObject();
|
|
1268
1242
|
if (s.address !== e.address)
|
|
1269
1243
|
continue;
|
|
1270
|
-
const n = s.groupId ?
|
|
1244
|
+
const n = s.groupId ? v(s.groupId) : "NEXA", i = {
|
|
1271
1245
|
address: s.address,
|
|
1272
1246
|
nexaAmount: s.value.toString(),
|
|
1273
1247
|
assetId: n,
|
|
1274
|
-
assetAmount:
|
|
1248
|
+
assetAmount: U(s.groupAmount) || s.value.toString()
|
|
1275
1249
|
};
|
|
1276
1250
|
e.involvedAssets.add(n), e.myOutputs.set(t, i);
|
|
1277
1251
|
}
|
|
@@ -1283,13 +1257,13 @@ class $t {
|
|
|
1283
1257
|
const s = e.txDetails.tx.inputs[t], n = this.validateAndGetSubscript(s);
|
|
1284
1258
|
if (s.scriptSig.isEmpty()) {
|
|
1285
1259
|
e.allMyOutputsCovered = !0;
|
|
1286
|
-
const i =
|
|
1287
|
-
s.scriptSig =
|
|
1260
|
+
const i = q.sign(e.txDetails.tx, t, X.ALL, n, e.privateKey).toTxFormat(), o = b.empty().add(e.privateKey.publicKey.toBuffer());
|
|
1261
|
+
s.scriptSig = Ae.buildScriptTemplateIn(void 0, o, b.empty().add(i));
|
|
1288
1262
|
} else {
|
|
1289
|
-
const i = s.scriptSig.findPlaceholder(), r = s.scriptSig.chunks[i].buf.subarray(64), c =
|
|
1263
|
+
const i = s.scriptSig.findPlaceholder(), r = s.scriptSig.chunks[i].buf.subarray(64), c = X.fromBuffer(r);
|
|
1290
1264
|
this.processSignatureCoverage(e, c);
|
|
1291
|
-
const d =
|
|
1292
|
-
s.scriptSig.replaceChunk(i,
|
|
1265
|
+
const d = q.sign(e.txDetails.tx, t, c, n, e.privateKey).toTxFormat(r);
|
|
1266
|
+
s.scriptSig.replaceChunk(i, b.empty().add(d));
|
|
1293
1267
|
}
|
|
1294
1268
|
}
|
|
1295
1269
|
if (!e.allMyOutputsCovered)
|
|
@@ -1298,24 +1272,24 @@ class $t {
|
|
|
1298
1272
|
validateAndGetSubscript(e) {
|
|
1299
1273
|
if (e.output.scriptPubKey.isPublicKeyTemplateOut()) {
|
|
1300
1274
|
if (e.scriptSig.isEmpty() || e.scriptSig.isPublicKeyTemplateIn())
|
|
1301
|
-
return
|
|
1275
|
+
return b.empty().add(A.OP_FROMALTSTACK).add(A.OP_CHECKSIGVERIFY);
|
|
1302
1276
|
throw new Error("Invalid input script type.");
|
|
1303
1277
|
}
|
|
1304
1278
|
if (e.output.scriptPubKey.isScriptTemplateOut()) {
|
|
1305
1279
|
if (!e.scriptSig.isScriptTemplateIn())
|
|
1306
1280
|
throw new Error("Unsupported input script type.");
|
|
1307
1281
|
const t = e.output.scriptPubKey.getTemplateHash(), s = e.scriptSig.chunks[0].buf;
|
|
1308
|
-
if (
|
|
1309
|
-
return
|
|
1282
|
+
if (m.equals(t, _.sha256ripemd160(s)) || m.equals(t, _.sha256sha256(s)))
|
|
1283
|
+
return b.fromBuffer(s);
|
|
1310
1284
|
throw new Error("Invalid input script template.");
|
|
1311
1285
|
}
|
|
1312
1286
|
throw new Error("Unsupported prevout script type.");
|
|
1313
1287
|
}
|
|
1314
1288
|
processSignatureCoverage(e, t) {
|
|
1315
1289
|
if (!e.allMyOutputsCovered)
|
|
1316
|
-
if (t.outType ==
|
|
1290
|
+
if (t.outType == Y.TWO)
|
|
1317
1291
|
e.coveredOutputs.add(t.outData[0]), e.coveredOutputs.add(t.outData[1]), this.checkSignatureCoverage(e);
|
|
1318
|
-
else if (t.outType ==
|
|
1292
|
+
else if (t.outType == Y.FIRSTN) {
|
|
1319
1293
|
const s = t.outData[0];
|
|
1320
1294
|
for (let n = 0; n < s; n++)
|
|
1321
1295
|
e.coveredOutputs.add(n);
|
|
@@ -1347,8 +1321,8 @@ class $t {
|
|
|
1347
1321
|
}
|
|
1348
1322
|
}
|
|
1349
1323
|
}
|
|
1350
|
-
const
|
|
1351
|
-
class
|
|
1324
|
+
const Ge = 274710, Je = "0014461ad25081cb0119d034385ff154c8d3ad6bdd76";
|
|
1325
|
+
class je {
|
|
1352
1326
|
rostrumService;
|
|
1353
1327
|
keyManager;
|
|
1354
1328
|
constructor(e, t) {
|
|
@@ -1381,16 +1355,16 @@ class st {
|
|
|
1381
1355
|
}), n;
|
|
1382
1356
|
}
|
|
1383
1357
|
async checkVaultsForAddress(e) {
|
|
1384
|
-
const t = /* @__PURE__ */ new Set(), s = await this.rostrumService.getTransactionsHistory(e,
|
|
1358
|
+
const t = /* @__PURE__ */ new Set(), s = await this.rostrumService.getTransactionsHistory(e, Ge);
|
|
1385
1359
|
for (const n of s) {
|
|
1386
|
-
const o = (await this.rostrumService.getTransaction(n.tx_hash)).vout.filter((r) => r.scriptPubKey.hex.startsWith(
|
|
1360
|
+
const o = (await this.rostrumService.getTransaction(n.tx_hash)).vout.filter((r) => r.scriptPubKey.hex.startsWith(Je));
|
|
1387
1361
|
for (const r of o)
|
|
1388
1362
|
t.add(r.scriptPubKey.hex);
|
|
1389
1363
|
}
|
|
1390
1364
|
return t;
|
|
1391
1365
|
}
|
|
1392
1366
|
parseVaultDetails(e) {
|
|
1393
|
-
const t =
|
|
1367
|
+
const t = b.fromHex(e), s = new ve().writeVarLengthBuf(t.toBuffer()).toBuffer(), n = new I(s).toString(), i = t.getVisibleArgs(), o = F.fromScriptNumBuffer(i.chunks[0].buf).toNumber(), r = L.isSmallIntOp(i.chunks[1].opcodenum) ? L.decodeOP_N(i.chunks[1].opcodenum) : F.fromScriptNumBuffer(i.chunks[1].buf).toNumber(), c = [o, r], d = this.keyManager.getKey({ account: h.VAULT, type: y.RECEIVE, index: r }), u = We(d.publicKey, c);
|
|
1394
1368
|
return n != u ? void 0 : {
|
|
1395
1369
|
address: n,
|
|
1396
1370
|
block: o,
|
|
@@ -1399,13 +1373,13 @@ class st {
|
|
|
1399
1373
|
balance: { confirmed: "0", unconfirmed: "0" },
|
|
1400
1374
|
tokensBalance: {},
|
|
1401
1375
|
height: 0,
|
|
1402
|
-
type:
|
|
1376
|
+
type: h.VAULT
|
|
1403
1377
|
};
|
|
1404
1378
|
}
|
|
1405
1379
|
}
|
|
1406
|
-
class
|
|
1380
|
+
class T {
|
|
1407
1381
|
constructor(e, t, s, n, i, o, r) {
|
|
1408
|
-
this.keyManager = e, this.kvStore = t, this.walletDb = s, this.rostrumService = n, this.assetService = i, this.transactionService = o, this.sessionManager = r, this.discoveryService = new
|
|
1382
|
+
this.keyManager = e, this.kvStore = t, this.walletDb = s, this.rostrumService = n, this.assetService = i, this.transactionService = o, this.sessionManager = r, this.discoveryService = new je(this.rostrumService, this.keyManager), this.accounts = /* @__PURE__ */ new Map(), this.accountsAddressToId = /* @__PURE__ */ new Map(), this.receiveAddresses = [], this.changeAddresses = [], this.vaults = /* @__PURE__ */ new Map(), this.pendingUpdates = /* @__PURE__ */ new Map(), this.addressResolvers = /* @__PURE__ */ new Map();
|
|
1409
1383
|
}
|
|
1410
1384
|
static GAP_LIMIT = 20;
|
|
1411
1385
|
static DEBOUNCE_MS = 1e3;
|
|
@@ -1434,22 +1408,22 @@ class x {
|
|
|
1434
1408
|
getReceiveAddress() {
|
|
1435
1409
|
return this.receiveAddresses.find((e) => !e.used).address;
|
|
1436
1410
|
}
|
|
1437
|
-
getChangeAddress(e =
|
|
1438
|
-
return e !=
|
|
1411
|
+
getChangeAddress(e = w) {
|
|
1412
|
+
return e != w ? this.accounts.get(e).address : this.changeAddresses.find((t) => !t.used).address;
|
|
1439
1413
|
}
|
|
1440
|
-
getUsedAddressKeys(e =
|
|
1441
|
-
if (e !=
|
|
1414
|
+
getUsedAddressKeys(e = w) {
|
|
1415
|
+
if (e != w) {
|
|
1442
1416
|
const t = this.accounts.get(e);
|
|
1443
1417
|
return [{
|
|
1444
1418
|
address: t.address,
|
|
1445
|
-
keyPath:
|
|
1419
|
+
keyPath: k(h.DAPP, 0, t.id),
|
|
1446
1420
|
balance: t.balance,
|
|
1447
1421
|
tokensBalance: t.tokensBalance
|
|
1448
1422
|
}];
|
|
1449
1423
|
}
|
|
1450
1424
|
return this.getMainAddresses().filter((t) => t.used).map((t) => ({
|
|
1451
1425
|
address: t.address,
|
|
1452
|
-
keyPath:
|
|
1426
|
+
keyPath: k(h.MAIN, t.space, t.idx),
|
|
1453
1427
|
balance: t.balance,
|
|
1454
1428
|
tokensBalance: t.tokensBalance
|
|
1455
1429
|
}));
|
|
@@ -1465,8 +1439,8 @@ class x {
|
|
|
1465
1439
|
}
|
|
1466
1440
|
async discoverWallet() {
|
|
1467
1441
|
this.notify({ type: "discover_wallet", loading: !0 });
|
|
1468
|
-
const e = this.discoveryService.discoverWalletIndex(
|
|
1469
|
-
this.receiveAddresses = this.deriveAddresses(
|
|
1442
|
+
const e = this.discoveryService.discoverWalletIndex(h.MAIN, y.RECEIVE), t = this.discoveryService.discoverWalletIndex(h.MAIN, y.CHANGE), s = this.discoveryService.discoverWalletIndex(h.DAPP, y.RECEIVE), [n, i, o] = await Promise.all([e, t, s]);
|
|
1443
|
+
this.receiveAddresses = this.deriveAddresses(y.RECEIVE, 0, n + T.GAP_LIMIT), this.changeAddresses = this.deriveAddresses(y.CHANGE, 0, i + T.GAP_LIMIT), this.accounts = this.deriveAccounts(0, o + 1), this.accounts.forEach((r) => this.accountsAddressToId.set(r.address, r.id)), await this.saveAddresses(this.receiveAddresses), await this.saveAddresses(this.changeAddresses), await this.saveAccounts(this.accounts), this.initState(), await this.initialSync(), this.notify({ type: "discover_wallet", loading: !1 }), this.notify({ type: "load_wallet", loading: !1 }), await this.rescanVaults();
|
|
1470
1444
|
}
|
|
1471
1445
|
async loadWallet() {
|
|
1472
1446
|
this.receiveAddresses = await this.walletDb.getReceiveAddresses(), this.changeAddresses = await this.walletDb.getChangeAddresses();
|
|
@@ -1478,9 +1452,9 @@ class x {
|
|
|
1478
1452
|
async initialSync() {
|
|
1479
1453
|
await this.subscribeAddresses(this.getAllAddresses(), !0);
|
|
1480
1454
|
const e = [];
|
|
1481
|
-
e.push(this.assetService.
|
|
1455
|
+
e.push(this.assetService.syncTokens(w, K(this.getMainAddresses().map((t) => t.tokensBalance))));
|
|
1482
1456
|
for (const t of this.accounts.values())
|
|
1483
|
-
e.push(this.assetService.
|
|
1457
|
+
e.push(this.assetService.syncTokens(t.id, t.tokensBalance));
|
|
1484
1458
|
await Promise.all(e);
|
|
1485
1459
|
}
|
|
1486
1460
|
async reconnectSync() {
|
|
@@ -1494,12 +1468,11 @@ class x {
|
|
|
1494
1468
|
this.notify({
|
|
1495
1469
|
type: "new_account",
|
|
1496
1470
|
account: {
|
|
1497
|
-
id:
|
|
1471
|
+
id: w,
|
|
1498
1472
|
name: "Main Wallet",
|
|
1499
1473
|
address: this.getReceiveAddress(),
|
|
1500
|
-
balance:
|
|
1501
|
-
tokensBalance:
|
|
1502
|
-
tokens: [],
|
|
1474
|
+
balance: Q(e.map((t) => t.balance)),
|
|
1475
|
+
tokensBalance: K(e.map((t) => t.tokensBalance)),
|
|
1503
1476
|
sessions: {}
|
|
1504
1477
|
}
|
|
1505
1478
|
});
|
|
@@ -1512,7 +1485,6 @@ class x {
|
|
|
1512
1485
|
address: t.address,
|
|
1513
1486
|
balance: t.balance,
|
|
1514
1487
|
tokensBalance: t.tokensBalance,
|
|
1515
|
-
tokens: [],
|
|
1516
1488
|
sessions: {}
|
|
1517
1489
|
}
|
|
1518
1490
|
});
|
|
@@ -1530,7 +1502,7 @@ class x {
|
|
|
1530
1502
|
deriveAddresses(e, t, s) {
|
|
1531
1503
|
const n = [];
|
|
1532
1504
|
for (let i = t; i < t + s; i++) {
|
|
1533
|
-
const o =
|
|
1505
|
+
const o = k(h.MAIN, e, i), c = {
|
|
1534
1506
|
address: this.keyManager.getKey(o).privateKey.toAddress().toString(),
|
|
1535
1507
|
space: e,
|
|
1536
1508
|
idx: i,
|
|
@@ -1539,7 +1511,7 @@ class x {
|
|
|
1539
1511
|
statusHash: "",
|
|
1540
1512
|
balance: { confirmed: "0", unconfirmed: "0" },
|
|
1541
1513
|
tokensBalance: {},
|
|
1542
|
-
type:
|
|
1514
|
+
type: h.MAIN
|
|
1543
1515
|
};
|
|
1544
1516
|
n.push(c);
|
|
1545
1517
|
}
|
|
@@ -1548,7 +1520,7 @@ class x {
|
|
|
1548
1520
|
deriveAccounts(e, t) {
|
|
1549
1521
|
const s = /* @__PURE__ */ new Map();
|
|
1550
1522
|
for (let n = e; n < e + t; n++) {
|
|
1551
|
-
const i =
|
|
1523
|
+
const i = k(h.DAPP, 0, n), o = this.keyManager.getKey(i).privateKey.toAddress().toString(), r = {
|
|
1552
1524
|
id: n,
|
|
1553
1525
|
name: `Account ${n + 1}`,
|
|
1554
1526
|
address: o,
|
|
@@ -1557,7 +1529,7 @@ class x {
|
|
|
1557
1529
|
statusHash: "",
|
|
1558
1530
|
balance: { confirmed: "0", unconfirmed: "0" },
|
|
1559
1531
|
tokensBalance: {},
|
|
1560
|
-
type:
|
|
1532
|
+
type: h.DAPP
|
|
1561
1533
|
};
|
|
1562
1534
|
s.set(r.id, r);
|
|
1563
1535
|
}
|
|
@@ -1597,7 +1569,7 @@ class x {
|
|
|
1597
1569
|
registerUpdate(e) {
|
|
1598
1570
|
this.pendingUpdates.set(e.address.address, e), clearTimeout(this.updateTimer), this.updateTimer = setTimeout(() => {
|
|
1599
1571
|
this.processPendingUpdates();
|
|
1600
|
-
},
|
|
1572
|
+
}, T.DEBOUNCE_MS);
|
|
1601
1573
|
}
|
|
1602
1574
|
async processPendingUpdates() {
|
|
1603
1575
|
if (this.pendingUpdates.size !== 0)
|
|
@@ -1625,7 +1597,7 @@ class x {
|
|
|
1625
1597
|
const c = this.addressResolvers.get(r);
|
|
1626
1598
|
c && (c(), this.addressResolvers.delete(r));
|
|
1627
1599
|
}
|
|
1628
|
-
await Promise.all([this.postProcessWalletUpdate(o), this.
|
|
1600
|
+
await Promise.all([this.postProcessWalletUpdate(o), this.postProcessAccountsUpdate(i)]);
|
|
1629
1601
|
} catch (e) {
|
|
1630
1602
|
console.error("Error processing pending updates:", e);
|
|
1631
1603
|
} finally {
|
|
@@ -1636,27 +1608,32 @@ class x {
|
|
|
1636
1608
|
if (e.length === 0)
|
|
1637
1609
|
return;
|
|
1638
1610
|
const t = /* @__PURE__ */ new Map();
|
|
1639
|
-
for (const { txs:
|
|
1640
|
-
for (const
|
|
1641
|
-
t.set(
|
|
1642
|
-
await this.checkGapLimit(
|
|
1643
|
-
const s = this.getMainAddresses(), n =
|
|
1644
|
-
this.notify({ type: "account_balance_updated", accountId:
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1611
|
+
for (const { txs: o } of e)
|
|
1612
|
+
for (const r of o)
|
|
1613
|
+
t.set(r.tx_hash, r);
|
|
1614
|
+
await this.checkGapLimit(y.RECEIVE), await this.checkGapLimit(y.CHANGE);
|
|
1615
|
+
const s = this.getMainAddresses(), n = Q(s.map((o) => o.balance)), i = K(s.map((o) => o.tokensBalance));
|
|
1616
|
+
this.notify({ type: "account_balance_updated", accountId: w, balance: n, tokensBalance: i }), this.notify({ type: "main_address_updated", address: this.getReceiveAddress() }), await this.postProcessActivity(w, Array.from(t.values()), s.map((o) => o.address), i);
|
|
1617
|
+
}
|
|
1618
|
+
async postProcessAccountsUpdate(e) {
|
|
1619
|
+
if (e.length === 0)
|
|
1620
|
+
return;
|
|
1621
|
+
const t = [];
|
|
1622
|
+
for (const { address: s, txs: n } of e) {
|
|
1623
|
+
const i = s;
|
|
1624
|
+
this.notify({ type: "account_balance_updated", accountId: i.id, balance: i.balance, tokensBalance: i.tokensBalance });
|
|
1625
|
+
const o = this.postProcessActivity(i.id, n, [i.address], i.tokensBalance);
|
|
1626
|
+
t.push(o);
|
|
1627
|
+
}
|
|
1628
|
+
await Promise.all(t);
|
|
1629
|
+
}
|
|
1630
|
+
async postProcessActivity(e, t, s, n) {
|
|
1631
|
+
const i = [], o = this.assetService.syncNfts(e, n);
|
|
1632
|
+
for (const r of t) {
|
|
1633
|
+
const c = this.transactionService.classifyAndSaveTransaction(e, r.tx_hash, s);
|
|
1634
|
+
i.push(c);
|
|
1635
|
+
}
|
|
1636
|
+
i.push(o), await Promise.all(i);
|
|
1660
1637
|
}
|
|
1661
1638
|
async fetchAndUpdateAddress(e, t) {
|
|
1662
1639
|
e.statusHash = t, e.balance = await this.rostrumService.getBalance(e.address), e.tokensBalance = await this.rostrumService.getTokensBalance(e.address);
|
|
@@ -1674,16 +1651,16 @@ class x {
|
|
|
1674
1651
|
return e.height = s.lastHeight, await this.walletDb.saveVault(e), this.notify({ type: "vault_balance_updated", address: e.address, balance: e.balance }), { address: e, txs: s.txs };
|
|
1675
1652
|
}
|
|
1676
1653
|
async checkGapLimit(e) {
|
|
1677
|
-
const t = e ===
|
|
1678
|
-
if (n <
|
|
1679
|
-
const i =
|
|
1654
|
+
const t = e === y.RECEIVE ? this.receiveAddresses : this.changeAddresses, s = e === y.RECEIVE ? "Receive" : "Change", n = t.filter((i) => !i.used).length;
|
|
1655
|
+
if (n < T.GAP_LIMIT) {
|
|
1656
|
+
const i = T.GAP_LIMIT - n, o = t[t.length - 1].idx;
|
|
1680
1657
|
console.log(`Deriving ${i} more ${s} addresses...`);
|
|
1681
1658
|
const r = this.deriveAddresses(e, o + 1, i);
|
|
1682
|
-
e ===
|
|
1659
|
+
e === y.RECEIVE ? this.receiveAddresses.push(...r) : this.changeAddresses.push(...r), await this.saveAddresses(r), await this.subscribeAddresses(r);
|
|
1683
1660
|
}
|
|
1684
1661
|
}
|
|
1685
1662
|
async addNewAccount(e, t) {
|
|
1686
|
-
const s =
|
|
1663
|
+
const s = k(h.DAPP, 0, e), n = this.keyManager.getKey(s).privateKey.toAddress().toString(), i = {
|
|
1687
1664
|
id: e,
|
|
1688
1665
|
name: t,
|
|
1689
1666
|
address: n,
|
|
@@ -1692,9 +1669,9 @@ class x {
|
|
|
1692
1669
|
statusHash: "",
|
|
1693
1670
|
balance: { confirmed: "0", unconfirmed: "0" },
|
|
1694
1671
|
tokensBalance: {},
|
|
1695
|
-
type:
|
|
1672
|
+
type: h.DAPP
|
|
1696
1673
|
};
|
|
1697
|
-
this.accounts.set(e, i), this.accountsAddressToId.set(n, e), await this.walletDb.saveAccount(i),
|
|
1674
|
+
this.accounts.set(e, i), this.accountsAddressToId.set(n, e), await this.walletDb.saveAccount(i), this.notify({
|
|
1698
1675
|
type: "new_account",
|
|
1699
1676
|
account: {
|
|
1700
1677
|
id: i.id,
|
|
@@ -1702,10 +1679,9 @@ class x {
|
|
|
1702
1679
|
address: i.address,
|
|
1703
1680
|
balance: i.balance,
|
|
1704
1681
|
tokensBalance: i.tokensBalance,
|
|
1705
|
-
tokens: [],
|
|
1706
1682
|
sessions: {}
|
|
1707
1683
|
}
|
|
1708
|
-
});
|
|
1684
|
+
}), await this.subscribeAddresses([i]);
|
|
1709
1685
|
}
|
|
1710
1686
|
async updateAccountName(e, t) {
|
|
1711
1687
|
if (!t)
|
|
@@ -1714,7 +1690,7 @@ class x {
|
|
|
1714
1690
|
s.name = t, await this.walletDb.updateAccountName(e, t);
|
|
1715
1691
|
}
|
|
1716
1692
|
rescanAccount(e) {
|
|
1717
|
-
if (e ==
|
|
1693
|
+
if (e == w) {
|
|
1718
1694
|
const t = this.getMainAddresses();
|
|
1719
1695
|
for (const s of t)
|
|
1720
1696
|
s.height = 0, this.registerUpdate({ address: s, result: s.statusHash });
|
|
@@ -1735,12 +1711,12 @@ class x {
|
|
|
1735
1711
|
statusHash: "",
|
|
1736
1712
|
balance: { confirmed: "0", unconfirmed: "0" },
|
|
1737
1713
|
tokensBalance: {},
|
|
1738
|
-
type:
|
|
1714
|
+
type: h.VAULT
|
|
1739
1715
|
};
|
|
1740
1716
|
await this.addVault(n);
|
|
1741
1717
|
}
|
|
1742
1718
|
async addVault(e) {
|
|
1743
|
-
this.vaults.set(e.address, e), await this.walletDb.saveVault(e),
|
|
1719
|
+
this.vaults.set(e.address, e), await this.walletDb.saveVault(e), this.notify({
|
|
1744
1720
|
type: "new_vault",
|
|
1745
1721
|
vault: {
|
|
1746
1722
|
address: e.address,
|
|
@@ -1748,7 +1724,7 @@ class x {
|
|
|
1748
1724
|
block: e.block,
|
|
1749
1725
|
index: e.idx
|
|
1750
1726
|
}
|
|
1751
|
-
});
|
|
1727
|
+
}), await this.subscribeAddresses([e]);
|
|
1752
1728
|
}
|
|
1753
1729
|
async rescanVaults() {
|
|
1754
1730
|
let e = !1;
|
|
@@ -1758,21 +1734,21 @@ class x {
|
|
|
1758
1734
|
return await Promise.all(s), e;
|
|
1759
1735
|
}
|
|
1760
1736
|
isVaultAddress(e) {
|
|
1761
|
-
return e.type ==
|
|
1737
|
+
return e.type == h.VAULT;
|
|
1762
1738
|
}
|
|
1763
1739
|
isAccountAddress(e) {
|
|
1764
|
-
return e.type ==
|
|
1740
|
+
return e.type == h.DAPP;
|
|
1765
1741
|
}
|
|
1766
1742
|
isMainAddress(e) {
|
|
1767
|
-
return e.type ==
|
|
1743
|
+
return e.type == h.MAIN;
|
|
1768
1744
|
}
|
|
1769
1745
|
}
|
|
1770
|
-
const
|
|
1746
|
+
const ze = {
|
|
1771
1747
|
isWalletExist: !1,
|
|
1772
1748
|
isAuthorized: !1
|
|
1773
|
-
},
|
|
1749
|
+
}, de = S({
|
|
1774
1750
|
name: "auth",
|
|
1775
|
-
initialState:
|
|
1751
|
+
initialState: ze,
|
|
1776
1752
|
reducers: {
|
|
1777
1753
|
setWalletExist: (a, e) => {
|
|
1778
1754
|
a.isWalletExist = e.payload;
|
|
@@ -1781,12 +1757,12 @@ const at = {
|
|
|
1781
1757
|
a.isAuthorized = e.payload;
|
|
1782
1758
|
}
|
|
1783
1759
|
}
|
|
1784
|
-
}),
|
|
1760
|
+
}), Gt = de.actions, qe = de.reducer, Xe = {
|
|
1785
1761
|
modalType: null,
|
|
1786
1762
|
currentRequest: null
|
|
1787
|
-
},
|
|
1763
|
+
}, ue = S({
|
|
1788
1764
|
name: "dappModal",
|
|
1789
|
-
initialState:
|
|
1765
|
+
initialState: Xe,
|
|
1790
1766
|
reducers: {
|
|
1791
1767
|
showRequest(a, e) {
|
|
1792
1768
|
a.modalType = e.payload.type, a.currentRequest = e.payload;
|
|
@@ -1795,24 +1771,50 @@ const at = {
|
|
|
1795
1771
|
a.modalType = null, a.currentRequest = null;
|
|
1796
1772
|
}
|
|
1797
1773
|
}
|
|
1798
|
-
}),
|
|
1774
|
+
}), Jt = ue.actions, Ye = ue.reducer, Ze = {
|
|
1799
1775
|
counter: 0,
|
|
1800
1776
|
loading: !1
|
|
1801
|
-
},
|
|
1777
|
+
}, le = S({
|
|
1802
1778
|
name: "loader",
|
|
1803
|
-
initialState:
|
|
1779
|
+
initialState: Ze,
|
|
1804
1780
|
reducers: {
|
|
1805
1781
|
setLoader: (a, e) => {
|
|
1806
1782
|
const t = e.payload.loading ? a.counter + 1 : Math.max(0, a.counter - 1);
|
|
1807
1783
|
a.counter = t, a.loading = t > 0, a.text = e.payload.text;
|
|
1808
1784
|
}
|
|
1809
1785
|
}
|
|
1810
|
-
}),
|
|
1786
|
+
}), jt = le.actions, Qe = le.reducer, et = {
|
|
1787
|
+
currency: "usd",
|
|
1788
|
+
data: {}
|
|
1789
|
+
}, te = Ne("market/updateMarketData", async (a, e) => {
|
|
1790
|
+
const t = e.getState();
|
|
1791
|
+
return await Ve(t.market.currency);
|
|
1792
|
+
}), he = S({
|
|
1793
|
+
name: "market",
|
|
1794
|
+
initialState: et,
|
|
1795
|
+
reducers: {
|
|
1796
|
+
setCurrency: (a, e) => {
|
|
1797
|
+
a.currency = e.payload;
|
|
1798
|
+
},
|
|
1799
|
+
setMarketData: (a, e) => {
|
|
1800
|
+
a.data = e.payload;
|
|
1801
|
+
}
|
|
1802
|
+
},
|
|
1803
|
+
extraReducers: (a) => {
|
|
1804
|
+
a.addCase(te.fulfilled, (e, t) => {
|
|
1805
|
+
e.data = t.payload;
|
|
1806
|
+
}).addCase(te.rejected, (e, t) => {
|
|
1807
|
+
console.error(t.error.message);
|
|
1808
|
+
});
|
|
1809
|
+
}
|
|
1810
|
+
});
|
|
1811
|
+
he.actions;
|
|
1812
|
+
const tt = he.reducer, st = {
|
|
1811
1813
|
wallet: {},
|
|
1812
1814
|
web3: {}
|
|
1813
|
-
},
|
|
1815
|
+
}, pe = S({
|
|
1814
1816
|
name: "notifications",
|
|
1815
|
-
initialState:
|
|
1817
|
+
initialState: st,
|
|
1816
1818
|
reducers: {
|
|
1817
1819
|
addNotification: (a, e) => {
|
|
1818
1820
|
e.payload.type == "wallet" ? a.wallet[e.payload.id] = e.payload : e.payload.type == "web3" && (a.web3[e.payload.id] = e.payload);
|
|
@@ -1824,28 +1826,14 @@ const at = {
|
|
|
1824
1826
|
e.payload === "wallet" ? a.wallet = {} : e.payload === "web3" ? a.web3 = {} : e.payload === "all" && (a.wallet = {}, a.web3 = {});
|
|
1825
1827
|
}
|
|
1826
1828
|
}
|
|
1827
|
-
}),
|
|
1829
|
+
}), zt = pe.actions, at = pe.reducer, nt = {
|
|
1828
1830
|
status: "Offline",
|
|
1829
1831
|
height: 0,
|
|
1830
|
-
price: ge(),
|
|
1831
1832
|
hasNetwork: !0,
|
|
1832
1833
|
isSuspended: !1
|
|
1833
|
-
},
|
|
1834
|
-
const a = ge();
|
|
1835
|
-
try {
|
|
1836
|
-
const e = await ze();
|
|
1837
|
-
Object.keys(e).forEach((t) => {
|
|
1838
|
-
a[t] = {
|
|
1839
|
-
value: e[t],
|
|
1840
|
-
change: e[`${t}_24h_change`]
|
|
1841
|
-
};
|
|
1842
|
-
});
|
|
1843
|
-
} catch {
|
|
1844
|
-
}
|
|
1845
|
-
return a;
|
|
1846
|
-
}), Se = M({
|
|
1834
|
+
}, fe = S({
|
|
1847
1835
|
name: "status",
|
|
1848
|
-
initialState:
|
|
1836
|
+
initialState: nt,
|
|
1849
1837
|
reducers: {
|
|
1850
1838
|
setHeight: (a, e) => {
|
|
1851
1839
|
e.payload > 0 && (a.status = "Online"), a.height = e.payload;
|
|
@@ -1859,25 +1847,17 @@ const at = {
|
|
|
1859
1847
|
setIsSuspended: (a, e) => {
|
|
1860
1848
|
a.isSuspended = e.payload;
|
|
1861
1849
|
}
|
|
1862
|
-
},
|
|
1863
|
-
extraReducers: (a) => {
|
|
1864
|
-
a.addCase(de.fulfilled, (e, t) => {
|
|
1865
|
-
e.price = t.payload;
|
|
1866
|
-
}).addCase(de.rejected, (e, t) => {
|
|
1867
|
-
console.error(t.error.message);
|
|
1868
|
-
});
|
|
1869
1850
|
}
|
|
1870
|
-
}),
|
|
1851
|
+
}), qt = fe.actions, it = fe.reducer, rt = {
|
|
1871
1852
|
isAuthorized: !1,
|
|
1872
|
-
selectedAccount:
|
|
1853
|
+
selectedAccount: w,
|
|
1873
1854
|
accounts: {
|
|
1874
1855
|
"-1": {
|
|
1875
|
-
id:
|
|
1856
|
+
id: w,
|
|
1876
1857
|
name: "Main Wallet",
|
|
1877
1858
|
address: "",
|
|
1878
1859
|
balance: { confirmed: "0", unconfirmed: "0" },
|
|
1879
1860
|
tokensBalance: {},
|
|
1880
|
-
tokens: [],
|
|
1881
1861
|
sessions: {}
|
|
1882
1862
|
}
|
|
1883
1863
|
},
|
|
@@ -1885,10 +1865,11 @@ const at = {
|
|
|
1885
1865
|
sync: !1,
|
|
1886
1866
|
initLoad: !0,
|
|
1887
1867
|
txUpdateTrigger: 0,
|
|
1888
|
-
nftsUpdateTrigger: 0
|
|
1889
|
-
|
|
1868
|
+
nftsUpdateTrigger: 0,
|
|
1869
|
+
tokensUpdateTrigger: 0
|
|
1870
|
+
}, me = S({
|
|
1890
1871
|
name: "wallet",
|
|
1891
|
-
initialState:
|
|
1872
|
+
initialState: rt,
|
|
1892
1873
|
reducers: {
|
|
1893
1874
|
setInitLoad: (a, e) => {
|
|
1894
1875
|
a.initLoad = e.payload;
|
|
@@ -1909,7 +1890,7 @@ const at = {
|
|
|
1909
1890
|
a.accounts[e.payload.id] = e.payload;
|
|
1910
1891
|
},
|
|
1911
1892
|
setMainAddress: (a, e) => {
|
|
1912
|
-
a.accounts[
|
|
1893
|
+
a.accounts[w].address = e.payload;
|
|
1913
1894
|
},
|
|
1914
1895
|
setAccountBalance: (a, e) => {
|
|
1915
1896
|
a.accounts[e.payload.id].balance = e.payload.balance, a.accounts[e.payload.id].tokensBalance = e.payload.tokensBalance;
|
|
@@ -1917,21 +1898,15 @@ const at = {
|
|
|
1917
1898
|
setAccountName: (a, e) => {
|
|
1918
1899
|
a.accounts[e.payload.id].name = e.payload.name;
|
|
1919
1900
|
},
|
|
1920
|
-
setTokens: (a, e) => {
|
|
1921
|
-
a.accounts[e.payload.id].tokens = e.payload.assets;
|
|
1922
|
-
},
|
|
1923
|
-
addToken: (a, e) => {
|
|
1924
|
-
a.accounts[e.payload.id].tokens.unshift(e.payload.asset);
|
|
1925
|
-
},
|
|
1926
|
-
removeToken: (a, e) => {
|
|
1927
|
-
a.accounts[e.payload.id].tokens = a.accounts[e.payload.id].tokens.filter((t) => t.tokenIdHex !== e.payload.tokenId);
|
|
1928
|
-
},
|
|
1929
1901
|
refreshTxs: (a) => {
|
|
1930
1902
|
a.txUpdateTrigger++;
|
|
1931
1903
|
},
|
|
1932
1904
|
refreshNfts: (a) => {
|
|
1933
1905
|
a.nftsUpdateTrigger++;
|
|
1934
1906
|
},
|
|
1907
|
+
refreshTokens: (a) => {
|
|
1908
|
+
a.tokensUpdateTrigger++;
|
|
1909
|
+
},
|
|
1935
1910
|
addSession(a, e) {
|
|
1936
1911
|
const { accountId: t, sessionInfo: s } = e.payload;
|
|
1937
1912
|
a.accounts[t].sessions[s.details.sessionId] = s;
|
|
@@ -1944,113 +1919,111 @@ const at = {
|
|
|
1944
1919
|
a.accounts[e.payload.accountId].sessions = {};
|
|
1945
1920
|
}
|
|
1946
1921
|
}
|
|
1947
|
-
}),
|
|
1948
|
-
loader:
|
|
1949
|
-
dapp:
|
|
1950
|
-
status:
|
|
1951
|
-
wallet:
|
|
1952
|
-
auth:
|
|
1953
|
-
notifications:
|
|
1954
|
-
|
|
1922
|
+
}), Xt = me.actions, ot = me.reducer, Yt = {
|
|
1923
|
+
loader: Qe,
|
|
1924
|
+
dapp: Ye,
|
|
1925
|
+
status: it,
|
|
1926
|
+
wallet: ot,
|
|
1927
|
+
auth: qe,
|
|
1928
|
+
notifications: at,
|
|
1929
|
+
market: tt
|
|
1930
|
+
}, g = Me.withTypes(), Zt = () => g((a) => a.auth), Qt = (a) => g((e) => e.market.data[a]), es = () => g((a) => a.status.height), ts = (a) => g((e) => e.wallet.accounts[a]), ss = () => g((a) => a.wallet.selectedAccount), as = () => g((a) => Math.max(...Object.keys(a.wallet.accounts).map(Number))), ns = (a) => g((e) => e.wallet.accounts[a].address), is = (a) => g((e) => e.wallet.accounts[a].balance), rs = (a, e) => g((t) => t.wallet.accounts[a].tokensBalance[e]), os = (a, e) => g((t) => t.wallet.accounts[a].sessions[e]), cs = () => g((a) => a.wallet.vaults), ge = W(
|
|
1955
1931
|
[(a) => a.notifications.wallet],
|
|
1956
1932
|
(a) => Object.values(a).sort((e, t) => t.createdAt - e.createdAt)
|
|
1957
|
-
),
|
|
1933
|
+
), ye = W(
|
|
1958
1934
|
[(a) => a.notifications.web3],
|
|
1959
1935
|
(a) => Object.values(a).sort((e, t) => t.createdAt - e.createdAt)
|
|
1960
|
-
),
|
|
1961
|
-
[
|
|
1936
|
+
), ct = W(
|
|
1937
|
+
[ge, ye],
|
|
1962
1938
|
(a, e) => [...a, ...e].sort((t, s) => s.createdAt - t.createdAt)
|
|
1963
|
-
),
|
|
1939
|
+
), ds = () => g(ge), us = () => g(ye), ls = () => g(ct);
|
|
1964
1940
|
export {
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
ie as
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
rs as
|
|
2045
|
-
|
|
2046
|
-
is as
|
|
2047
|
-
ds as
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
qt as validateAndDecryptMnemonic,
|
|
2053
|
-
es as walletActions,
|
|
2054
|
-
pt as walletReducer
|
|
1941
|
+
h as AccountType,
|
|
1942
|
+
Ut as AssetService,
|
|
1943
|
+
ce as CURRENCIES,
|
|
1944
|
+
Mt as KVStore,
|
|
1945
|
+
Pt as KeyManager,
|
|
1946
|
+
y as KeySpace,
|
|
1947
|
+
w as MAIN_WALLET_ID,
|
|
1948
|
+
Z as MAX_INT64,
|
|
1949
|
+
ie as RostrumService,
|
|
1950
|
+
ee as SUPPORTED_TOKENS,
|
|
1951
|
+
$t as SessionManager,
|
|
1952
|
+
N as SessionRequestType,
|
|
1953
|
+
Dt as TransactionService,
|
|
1954
|
+
Wt as TransactionTransformer,
|
|
1955
|
+
Ee as VAULT_FIRST_BLOCK,
|
|
1956
|
+
yt as VAULT_SCRIPT_PREFIX,
|
|
1957
|
+
Ct as WalletCache,
|
|
1958
|
+
Et as WalletDB,
|
|
1959
|
+
T as WalletManager,
|
|
1960
|
+
Gt as authActions,
|
|
1961
|
+
qe as authReducer,
|
|
1962
|
+
Ft as calculateFiatValue,
|
|
1963
|
+
St as capitalizeFirstLetter,
|
|
1964
|
+
Kt as currencyCodes,
|
|
1965
|
+
De as currencySymbols,
|
|
1966
|
+
G as currentTimestamp,
|
|
1967
|
+
Jt as dappModalActions,
|
|
1968
|
+
Ye as dappModalReducer,
|
|
1969
|
+
Ht as encryptMnemonic,
|
|
1970
|
+
vt as estimateDateByFutureBlock,
|
|
1971
|
+
He as formatMoney,
|
|
1972
|
+
Vt as generateNewMnemonic,
|
|
1973
|
+
We as generateVaultAddress,
|
|
1974
|
+
Le as generateVaultConstraint,
|
|
1975
|
+
$e as generateVaultVisibleArgs,
|
|
1976
|
+
ae as getAddressBuffer,
|
|
1977
|
+
_t as getAssetFileUrl,
|
|
1978
|
+
Be as getAssetMetadata,
|
|
1979
|
+
Lt as getCurrencySymbol,
|
|
1980
|
+
At as getExplorerUrl,
|
|
1981
|
+
Tt as getFileMediaType,
|
|
1982
|
+
It as getFileMimeType,
|
|
1983
|
+
Ve as getMarketData,
|
|
1984
|
+
Fe as getVaultConstraintHash,
|
|
1985
|
+
Re as getVaultTemplate,
|
|
1986
|
+
Ke as getVaultTemplateHash,
|
|
1987
|
+
wt as isGenesisHashValid,
|
|
1988
|
+
_e as isMnemonicValid,
|
|
1989
|
+
M as isNullOrEmpty,
|
|
1990
|
+
C as isTestnet,
|
|
1991
|
+
R as isValidNexaAddress,
|
|
1992
|
+
k as keyPathToString,
|
|
1993
|
+
jt as loaderActions,
|
|
1994
|
+
Qe as loaderReducer,
|
|
1995
|
+
zt as notificationsActions,
|
|
1996
|
+
at as notificationsReducer,
|
|
1997
|
+
Ot as parseTokenDataUrl,
|
|
1998
|
+
Nt as prettifyAmount,
|
|
1999
|
+
Yt as sharedReducers,
|
|
2000
|
+
xt as sleep,
|
|
2001
|
+
qt as statusActions,
|
|
2002
|
+
it as statusReducer,
|
|
2003
|
+
Ce as stringToKeyPath,
|
|
2004
|
+
Q as sumBalance,
|
|
2005
|
+
K as sumTokensBalance,
|
|
2006
|
+
U as tokenAmountToAssetAmount,
|
|
2007
|
+
kt as tokenHexToAddr,
|
|
2008
|
+
v as tokenIdToHex,
|
|
2009
|
+
Bt as transformTokenIconUrl,
|
|
2010
|
+
bt as truncateStringMiddle,
|
|
2011
|
+
ts as useAccount,
|
|
2012
|
+
ls as useAllNotifications,
|
|
2013
|
+
Zt as useAuth,
|
|
2014
|
+
es as useBlockHeight,
|
|
2015
|
+
os as useDAppSession,
|
|
2016
|
+
as as useLastAccountId,
|
|
2017
|
+
ns as useMainReceiveAddress,
|
|
2018
|
+
Qt as useMarketData,
|
|
2019
|
+
ss as useSelectedAccount,
|
|
2020
|
+
rs as useTokenBalance,
|
|
2021
|
+
cs as useVaults,
|
|
2022
|
+
is as useWalletBalance,
|
|
2023
|
+
ds as useWalletNotifications,
|
|
2024
|
+
us as useWeb3Notifications,
|
|
2025
|
+
Rt as validateAndDecryptMnemonic,
|
|
2026
|
+
Xt as walletActions,
|
|
2027
|
+
ot as walletReducer
|
|
2055
2028
|
};
|
|
2056
2029
|
//# sourceMappingURL=index.js.map
|