edge-currency-monero 1.3.1 → 1.4.0
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/CHANGELOG.md +42 -33
- package/lib/MoneroEngine.js +120 -93
- package/lib/MoneroLocalData.js +70 -58
- package/lib/MoneroTools.js +14 -7
- package/lib/moneroInfo.js +3 -1
- package/lib/moneroTypes.js +15 -0
- package/lib/react-native/edge-currency-monero.ts +1074 -1005
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,123 +1,132 @@
|
|
|
1
1
|
# edge-currency-monero
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Unreleased
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## 1.4.0 (2025-03-25)
|
|
6
|
+
|
|
7
|
+
- fixed: Remove race condition causing missing transaction between showing address and initial login.
|
|
8
|
+
- fixed: Upgrade edge-core-js to 2.26.0 to implemented new Seen Tx Checkpoint API
|
|
9
|
+
|
|
10
|
+
## 1.3.2 (2024-11-19)
|
|
11
|
+
|
|
12
|
+
- fixed: URI parsing and creation according to the correct format
|
|
13
|
+
|
|
14
|
+
## 1.3.1 (2024-03-21)
|
|
6
15
|
|
|
7
16
|
- fixed: Include missing files in the NPM package.
|
|
8
17
|
|
|
9
|
-
|
|
18
|
+
## 1.3.0 (2024-03-21)
|
|
10
19
|
|
|
11
20
|
- changed: Switch our codebase from Flow to TypeScript.
|
|
12
21
|
|
|
13
|
-
|
|
22
|
+
## 1.2.0 (2024-03-20)
|
|
14
23
|
|
|
15
24
|
- added: Report legacy payment ID's using the new core `memo` transaction property.
|
|
16
25
|
- removed: Only bundle the package in CJS-format, and drop the ESM output.
|
|
17
26
|
- removed: Stop supporting undocumented `getTransaction` options.
|
|
18
27
|
|
|
19
|
-
|
|
28
|
+
## 1.1.1 (2023-08-15)
|
|
20
29
|
|
|
21
30
|
- fixed: Fixed address transaction cleaner broken for wallets with no transaction history.
|
|
22
31
|
|
|
23
|
-
|
|
32
|
+
## 1.1.0 (2023-08-11)
|
|
24
33
|
|
|
25
34
|
- added: Support custom servers via `enableCustomServers` and `moneroLightwalletServer` user settings.
|
|
26
35
|
|
|
27
|
-
|
|
36
|
+
## 1.0.0 (2023-03-28)
|
|
28
37
|
|
|
29
38
|
- fixed: Return the correct `walletId` on `EdgeTransaction` instances.
|
|
30
39
|
- fixed: Add a missing `await` to `saveTx`, ensuring the transaction is on-disk.
|
|
31
40
|
- changed: Upgrade to react-native-mymonero-core v0.3.0.
|
|
32
41
|
|
|
33
|
-
|
|
42
|
+
## 0.6.0 (2023-03-28)
|
|
34
43
|
|
|
35
44
|
- changed: Allow engine to run without private keys. This requires edge-core-js v0.19.47 or greater.
|
|
36
45
|
|
|
37
|
-
|
|
46
|
+
## 0.5.5 (2023-01-10)
|
|
38
47
|
|
|
39
48
|
- Add `getMaxSpendable`
|
|
40
49
|
- Upgrade edge-core-js to v0.19.36
|
|
41
50
|
- Upgrade react-native-mymonero-core to v0.2.7
|
|
42
51
|
|
|
43
|
-
|
|
52
|
+
## 0.5.4 (2022-11-30)
|
|
44
53
|
|
|
45
54
|
- Reduce transaction changed callbacks on wallet initialization
|
|
46
55
|
|
|
47
|
-
|
|
56
|
+
## 0.5.3 (2022-08-26)
|
|
48
57
|
|
|
49
58
|
- changed: Update spending constants to match upstream MyMonero SDK.
|
|
50
59
|
|
|
51
|
-
|
|
60
|
+
## 0.5.2 (2022-08-13)
|
|
52
61
|
|
|
53
62
|
- fixed: Incorrect amounts after spend.
|
|
54
63
|
|
|
55
|
-
|
|
64
|
+
## 0.5.1 (2022-08-13)
|
|
56
65
|
|
|
57
66
|
- fixed: Stop randomly crashing while sending funds.
|
|
58
67
|
|
|
59
|
-
|
|
68
|
+
## 0.5.0 (2022-08-11)
|
|
60
69
|
|
|
61
70
|
- changed: Upgrade to react-native-mymonero-core v0.2.0, with its new API.
|
|
62
71
|
|
|
63
|
-
|
|
72
|
+
## 0.4.2 (2022-08-03)
|
|
64
73
|
|
|
65
74
|
- fixed: Set `addressesChecked` to `false` on resync
|
|
66
75
|
|
|
67
|
-
|
|
76
|
+
## 0.4.1 (2022-05-11)
|
|
68
77
|
|
|
69
78
|
- fixed: Fix syncing when the user settings are empty
|
|
70
79
|
|
|
71
|
-
|
|
80
|
+
## 0.4.0 (2022-01-11)
|
|
72
81
|
|
|
73
82
|
- added: Move the forked code out of mymonero-core-js directly into this repo.
|
|
74
83
|
- changed: Require react-native-mymonero-core ^0.1.2.
|
|
75
84
|
|
|
76
|
-
|
|
85
|
+
## 0.3.4 (2022-01-11)
|
|
77
86
|
|
|
78
87
|
- Fix git urls
|
|
79
88
|
|
|
80
|
-
|
|
89
|
+
## 0.3.3 (2021-09-28)
|
|
81
90
|
|
|
82
91
|
- Reformat spendable balance error into 3 lines
|
|
83
92
|
|
|
84
|
-
|
|
93
|
+
## 0.3.2 (2021-06-03)
|
|
85
94
|
|
|
86
95
|
- Remove icon URLs
|
|
87
96
|
|
|
88
|
-
|
|
97
|
+
## 0.3.1 (2021-05-25)
|
|
89
98
|
|
|
90
99
|
- Fix float amount precision
|
|
91
100
|
- Fix recorded native amount and fee
|
|
92
101
|
|
|
93
|
-
|
|
102
|
+
## 0.3.0 (2021-05-24)
|
|
94
103
|
|
|
95
104
|
- Import native code directly from react-native-mymonero-core. Before, this plugin relied on "magic" methods passed in via the global object.
|
|
96
105
|
|
|
97
|
-
|
|
106
|
+
## 0.2.10 (2021-04-12)
|
|
98
107
|
|
|
99
108
|
- Update image URL
|
|
100
109
|
|
|
101
|
-
|
|
110
|
+
## 0.2.9 (2021-01-17)
|
|
102
111
|
|
|
103
112
|
- Add additional logging and context for logs
|
|
104
113
|
- Upgrade to eslint-config-standard-kit v0.15.1
|
|
105
114
|
|
|
106
|
-
|
|
115
|
+
## 0.2.8 (2021-01-05)
|
|
107
116
|
|
|
108
117
|
- Update logging levels
|
|
109
118
|
- Add parseUri tests
|
|
110
119
|
|
|
111
|
-
|
|
120
|
+
## 0.2.7 (2020-12-08)
|
|
112
121
|
|
|
113
122
|
- Update Blockchair explorer URL to include partner ID
|
|
114
123
|
|
|
115
|
-
|
|
124
|
+
## 0.2.6 (2020-08-11)
|
|
116
125
|
|
|
117
126
|
- Export private view key via getDisplayPublicSeed()
|
|
118
127
|
- Update transaction explorer to Blockchair
|
|
119
128
|
|
|
120
|
-
|
|
129
|
+
## 0.2.5 (2020-06-03)
|
|
121
130
|
|
|
122
131
|
- Upgrade mymonero-core-js to export transaction private key
|
|
123
132
|
- Upgrade edge-core-js to v0.17.4
|
|
@@ -125,25 +134,25 @@
|
|
|
125
134
|
- Improve logging
|
|
126
135
|
- Add makeMutex() to wrap makeSpend() to avoid entering it more than once at a time
|
|
127
136
|
|
|
128
|
-
|
|
137
|
+
## 0.2.4 (2019-08-08)
|
|
129
138
|
|
|
130
139
|
- Default `signedTx` property on EdgeTransaction to empty string
|
|
131
140
|
|
|
132
|
-
|
|
141
|
+
## 0.2.3 (2019-07-31)
|
|
133
142
|
|
|
134
143
|
- Pass an `apiKey` with every API request.
|
|
135
144
|
- Correctly handle the server-provided `fee_mask`.
|
|
136
145
|
|
|
137
|
-
|
|
146
|
+
## 0.2.2 (2019-03-27)
|
|
138
147
|
|
|
139
148
|
- Fix block explorer link.
|
|
140
149
|
|
|
141
|
-
|
|
150
|
+
## 0.2.1 (2019-03-07)
|
|
142
151
|
|
|
143
152
|
- Upgrade `mymonero-core-js` in preparation for the Monero v0.14.0 hard fork.
|
|
144
153
|
- Properly report failed broadcasts.
|
|
145
154
|
|
|
146
|
-
|
|
155
|
+
## 0.2.0 (2019-02-19)
|
|
147
156
|
|
|
148
157
|
- Upgrade to the edge-core-js v0.15.0 and adapt to breaking changes.
|
|
149
158
|
|
package/lib/MoneroEngine.js
CHANGED
|
@@ -25,12 +25,18 @@ var _biggystring = require('biggystring');
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
|
|
28
|
+
|
|
28
29
|
|
|
29
30
|
|
|
30
31
|
var _types = require('edge-core-js/types');
|
|
31
32
|
|
|
32
33
|
|
|
33
34
|
var _moneroInfo = require('./moneroInfo');
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
34
40
|
var _MoneroLocalData = require('./MoneroLocalData');
|
|
35
41
|
|
|
36
42
|
|
|
@@ -42,6 +48,8 @@ var _MoneroLocalData = require('./MoneroLocalData');
|
|
|
42
48
|
|
|
43
49
|
|
|
44
50
|
|
|
51
|
+
|
|
52
|
+
|
|
45
53
|
var _moneroTypes = require('./moneroTypes');
|
|
46
54
|
|
|
47
55
|
|
|
@@ -55,7 +63,7 @@ const SAVE_DATASTORE_MILLISECONDS = 10000
|
|
|
55
63
|
// const ADDRESS_QUERY_LOOKBACK_BLOCKS = '8' // ~ 2 minutes
|
|
56
64
|
// const ADDRESS_QUERY_LOOKBACK_BLOCKS = (4 * 60 * 24 * 7) // ~ one week
|
|
57
65
|
|
|
58
|
-
const
|
|
66
|
+
const PRIMARY_CURRENCY_TOKEN_ID = null
|
|
59
67
|
|
|
60
68
|
class MoneroEngine {
|
|
61
69
|
|
|
@@ -95,7 +103,7 @@ const PRIMARY_CURRENCY = _moneroInfo.currencyInfo.currencyCode
|
|
|
95
103
|
this.loggedIn = false
|
|
96
104
|
this.addressesChecked = false
|
|
97
105
|
this.walletLocalDataDirty = false
|
|
98
|
-
this.
|
|
106
|
+
this.transactionEventArray = []
|
|
99
107
|
this.walletInfo = walletInfo // We derive the public keys at init
|
|
100
108
|
this.walletId = walletInfo.id
|
|
101
109
|
this.currencyInfo = _moneroInfo.currencyInfo
|
|
@@ -106,8 +114,8 @@ const PRIMARY_CURRENCY = _moneroInfo.currencyInfo.currencyCode
|
|
|
106
114
|
fetch: env.io.fetch,
|
|
107
115
|
nettype: networkInfo.nettype
|
|
108
116
|
})
|
|
117
|
+
this.seenTxCheckpoint = _moneroTypes.asSeenTxCheckpoint.call(void 0, opts.seenTxCheckpoint)
|
|
109
118
|
|
|
110
|
-
this.allTokens = _moneroInfo.currencyInfo.metaTokens.slice(0)
|
|
111
119
|
// this.customTokens = []
|
|
112
120
|
this.timers = {}
|
|
113
121
|
|
|
@@ -178,6 +186,7 @@ const PRIMARY_CURRENCY = _moneroInfo.currencyInfo.currencyCode
|
|
|
178
186
|
this.walletLocalData.hasLoggedIn = true
|
|
179
187
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
180
188
|
this.addToLoop('saveWalletLoop', SAVE_DATASTORE_MILLISECONDS)
|
|
189
|
+
this.edgeTxLibCallbacks.onAddressChanged()
|
|
181
190
|
}
|
|
182
191
|
} catch (e) {
|
|
183
192
|
this.log.error('Error logging into mymonero', e)
|
|
@@ -206,9 +215,18 @@ const PRIMARY_CURRENCY = _moneroInfo.currencyInfo.currencyCode
|
|
|
206
215
|
|
|
207
216
|
const nativeBalance = _biggystring.sub.call(void 0, addrResult.totalReceived, addrResult.totalSent)
|
|
208
217
|
|
|
209
|
-
if (
|
|
210
|
-
this.walletLocalData.totalBalances.
|
|
211
|
-
|
|
218
|
+
if (
|
|
219
|
+
this.walletLocalData.totalBalances.get(PRIMARY_CURRENCY_TOKEN_ID) !==
|
|
220
|
+
nativeBalance
|
|
221
|
+
) {
|
|
222
|
+
this.walletLocalData.totalBalances.set(
|
|
223
|
+
PRIMARY_CURRENCY_TOKEN_ID,
|
|
224
|
+
nativeBalance
|
|
225
|
+
)
|
|
226
|
+
this.edgeTxLibCallbacks.onTokenBalanceChanged(
|
|
227
|
+
PRIMARY_CURRENCY_TOKEN_ID,
|
|
228
|
+
nativeBalance
|
|
229
|
+
)
|
|
212
230
|
}
|
|
213
231
|
this.walletLocalData.lockedXmrBalance = addrResult.lockedBalance
|
|
214
232
|
} catch (e) {
|
|
@@ -257,6 +275,7 @@ const PRIMARY_CURRENCY = _moneroInfo.currencyInfo.currencyCode
|
|
|
257
275
|
memos,
|
|
258
276
|
nativeAmount: netNativeAmount,
|
|
259
277
|
networkFee: nativeNetworkFee,
|
|
278
|
+
networkFees: [{ tokenId: null, nativeAmount: nativeNetworkFee }],
|
|
260
279
|
otherParams: {},
|
|
261
280
|
ourReceiveAddresses,
|
|
262
281
|
signedTx: '',
|
|
@@ -265,21 +284,18 @@ const PRIMARY_CURRENCY = _moneroInfo.currencyInfo.currencyCode
|
|
|
265
284
|
walletId: this.walletId
|
|
266
285
|
}
|
|
267
286
|
|
|
268
|
-
const idx = this.findTransaction(
|
|
287
|
+
const idx = this.findTransaction(PRIMARY_CURRENCY_TOKEN_ID, tx.hash)
|
|
269
288
|
if (idx === -1) {
|
|
270
289
|
this.log(`New transaction: ${tx.hash}`)
|
|
271
290
|
|
|
272
291
|
// New transaction not in database
|
|
273
|
-
this.addTransaction(
|
|
292
|
+
this.addTransaction(PRIMARY_CURRENCY_TOKEN_ID, edgeTransaction)
|
|
274
293
|
|
|
275
|
-
this.edgeTxLibCallbacks.
|
|
276
|
-
|
|
277
|
-
)
|
|
278
|
-
this.transactionsChangedArray = []
|
|
294
|
+
this.edgeTxLibCallbacks.onTransactions(this.transactionEventArray)
|
|
295
|
+
this.transactionEventArray = []
|
|
279
296
|
} else {
|
|
280
297
|
// Already have this tx in the database. See if anything changed
|
|
281
|
-
const transactionsArray =
|
|
282
|
-
this.walletLocalData.transactionsObj[PRIMARY_CURRENCY]
|
|
298
|
+
const transactionsArray = this.getTxs(PRIMARY_CURRENCY_TOKEN_ID)
|
|
283
299
|
const edgeTx = transactionsArray[idx]
|
|
284
300
|
|
|
285
301
|
if (edgeTx.blockHeight !== edgeTransaction.blockHeight) {
|
|
@@ -290,13 +306,13 @@ const PRIMARY_CURRENCY = _moneroInfo.currencyInfo.currencyCode
|
|
|
290
306
|
}
|
|
291
307
|
|
|
292
308
|
this.log(`Update transaction: ${tx.hash} height:${tx.height}`)
|
|
293
|
-
this.updateTransaction(
|
|
294
|
-
this.edgeTxLibCallbacks.
|
|
295
|
-
|
|
296
|
-
)
|
|
297
|
-
this.transactionsChangedArray = []
|
|
309
|
+
this.updateTransaction(PRIMARY_CURRENCY_TOKEN_ID, edgeTransaction, idx)
|
|
310
|
+
this.edgeTxLibCallbacks.onTransactions(this.transactionEventArray)
|
|
311
|
+
this.transactionEventArray = []
|
|
298
312
|
}
|
|
299
313
|
}
|
|
314
|
+
|
|
315
|
+
return blockHeight
|
|
300
316
|
}
|
|
301
317
|
|
|
302
318
|
async checkTransactionsInnerLoop(privateKeys) {
|
|
@@ -309,6 +325,8 @@ const PRIMARY_CURRENCY = _moneroInfo.currencyInfo.currencyCode
|
|
|
309
325
|
// }
|
|
310
326
|
|
|
311
327
|
try {
|
|
328
|
+
// Let the seenTxCheckpoint be defined before querying transactions.
|
|
329
|
+
let seenTxCheckpoint = _nullishCoalesce(this.seenTxCheckpoint, () => ( 0))
|
|
312
330
|
const transactions = await this.myMoneroApi.getTransactions({
|
|
313
331
|
address: this.walletInfo.keys.moneroAddress,
|
|
314
332
|
privateViewKey: this.walletInfo.keys.moneroViewKeyPrivate,
|
|
@@ -322,26 +340,27 @@ const PRIMARY_CURRENCY = _moneroInfo.currencyInfo.currencyCode
|
|
|
322
340
|
// Iterate over transactions in address
|
|
323
341
|
for (let i = 0; i < transactions.length; i++) {
|
|
324
342
|
const tx = transactions[i]
|
|
325
|
-
this.processMoneroTransaction(tx)
|
|
343
|
+
const blockHeight = this.processMoneroTransaction(tx)
|
|
344
|
+
seenTxCheckpoint = Math.max(seenTxCheckpoint, blockHeight)
|
|
326
345
|
if (i % 10 === 0) {
|
|
327
346
|
this.updateOnAddressesChecked(i, transactions.length)
|
|
328
347
|
}
|
|
329
348
|
}
|
|
349
|
+
|
|
330
350
|
this.updateOnAddressesChecked(transactions.length, transactions.length)
|
|
351
|
+
// Update the seenTxCheckpoint state:
|
|
352
|
+
this.seenTxCheckpoint = seenTxCheckpoint
|
|
353
|
+
this.edgeTxLibCallbacks.onSeenTxCheckpoint(
|
|
354
|
+
_moneroTypes.wasSeenTxCheckpoint.call(void 0, this.seenTxCheckpoint)
|
|
355
|
+
)
|
|
331
356
|
} catch (e) {
|
|
332
357
|
this.log.error('checkTransactionsInnerLoop', e)
|
|
333
358
|
}
|
|
334
359
|
}
|
|
335
360
|
|
|
336
|
-
findTransaction(
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
) {
|
|
340
|
-
return -1
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
const currency = this.walletLocalData.transactionsObj[currencyCode]
|
|
344
|
-
return currency.findIndex(element => {
|
|
361
|
+
findTransaction(tokenId, txid) {
|
|
362
|
+
const txs = this.getTxs(tokenId)
|
|
363
|
+
return txs.findIndex(element => {
|
|
345
364
|
return _utils.normalizeAddress.call(void 0, element.txid) === _utils.normalizeAddress.call(void 0, txid)
|
|
346
365
|
})
|
|
347
366
|
}
|
|
@@ -350,9 +369,19 @@ const PRIMARY_CURRENCY = _moneroInfo.currencyInfo.currencyCode
|
|
|
350
369
|
return b.date - a.date
|
|
351
370
|
}
|
|
352
371
|
|
|
353
|
-
|
|
372
|
+
getTxs(tokenId) {
|
|
373
|
+
const txs = this.walletLocalData.transactionsObj.get(tokenId)
|
|
374
|
+
if (txs == null) {
|
|
375
|
+
const txs = []
|
|
376
|
+
this.walletLocalData.transactionsObj.set(tokenId, txs)
|
|
377
|
+
return txs
|
|
378
|
+
}
|
|
379
|
+
return txs
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
addTransaction(tokenId, edgeTransaction) {
|
|
354
383
|
// Add or update tx in transactionsObj
|
|
355
|
-
const idx = this.findTransaction(
|
|
384
|
+
const idx = this.findTransaction(tokenId, edgeTransaction.txid)
|
|
356
385
|
|
|
357
386
|
if (idx === -1) {
|
|
358
387
|
this.log.warn(
|
|
@@ -360,32 +389,42 @@ const PRIMARY_CURRENCY = _moneroInfo.currencyInfo.currencyCode
|
|
|
360
389
|
edgeTransaction.txid +
|
|
361
390
|
edgeTransaction.nativeAmount
|
|
362
391
|
)
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
'undefined'
|
|
366
|
-
) {
|
|
367
|
-
this.walletLocalData.transactionsObj[currencyCode] = []
|
|
368
|
-
}
|
|
369
|
-
this.walletLocalData.transactionsObj[currencyCode].push(edgeTransaction)
|
|
392
|
+
const txs = this.getTxs(tokenId)
|
|
393
|
+
txs.push(edgeTransaction)
|
|
370
394
|
|
|
371
395
|
// Sort
|
|
372
|
-
|
|
396
|
+
txs.sort(this.sortTxByDate)
|
|
373
397
|
this.walletLocalDataDirty = true
|
|
374
|
-
|
|
398
|
+
const txCheckpoint = edgeTransaction.blockHeight
|
|
399
|
+
const isNew =
|
|
400
|
+
// New if unconfirmed
|
|
401
|
+
txCheckpoint === 0 ||
|
|
402
|
+
// No checkpoint means initial sync
|
|
403
|
+
(this.seenTxCheckpoint != null &&
|
|
404
|
+
// New if txCheckpoint exceeds the last seen checkpoint
|
|
405
|
+
txCheckpoint >= this.seenTxCheckpoint)
|
|
406
|
+
this.transactionEventArray.push({
|
|
407
|
+
isNew,
|
|
408
|
+
transaction: edgeTransaction
|
|
409
|
+
})
|
|
375
410
|
} else {
|
|
376
|
-
this.updateTransaction(
|
|
411
|
+
this.updateTransaction(tokenId, edgeTransaction, idx)
|
|
377
412
|
}
|
|
378
413
|
}
|
|
379
414
|
|
|
380
415
|
updateTransaction(
|
|
381
|
-
|
|
416
|
+
tokenId,
|
|
382
417
|
edgeTransaction,
|
|
383
418
|
idx
|
|
384
419
|
) {
|
|
385
420
|
// Update the transaction
|
|
386
|
-
|
|
421
|
+
const txs = this.getTxs(tokenId)
|
|
422
|
+
txs[idx] = edgeTransaction
|
|
387
423
|
this.walletLocalDataDirty = true
|
|
388
|
-
this.
|
|
424
|
+
this.transactionEventArray.push({
|
|
425
|
+
isNew: false,
|
|
426
|
+
transaction: edgeTransaction
|
|
427
|
+
})
|
|
389
428
|
this.log.warn(
|
|
390
429
|
'updateTransaction' + edgeTransaction.txid + edgeTransaction.nativeAmount
|
|
391
430
|
)
|
|
@@ -398,7 +437,7 @@ const PRIMARY_CURRENCY = _moneroInfo.currencyInfo.currencyCode
|
|
|
398
437
|
if (this.walletLocalDataDirty) {
|
|
399
438
|
try {
|
|
400
439
|
this.log('walletLocalDataDirty. Saving...')
|
|
401
|
-
const walletJson =
|
|
440
|
+
const walletJson = _MoneroLocalData.wasMoneroLocalData.call(void 0, this.walletLocalData)
|
|
402
441
|
await this.walletLocalDisklet.setText(_MoneroLocalData.DATA_STORE_FILE, walletJson)
|
|
403
442
|
this.walletLocalDataDirty = false
|
|
404
443
|
} catch (err) {
|
|
@@ -408,14 +447,14 @@ const PRIMARY_CURRENCY = _moneroInfo.currencyInfo.currencyCode
|
|
|
408
447
|
}
|
|
409
448
|
|
|
410
449
|
doInitialCallbacks() {
|
|
411
|
-
for (const
|
|
450
|
+
for (const tokenId of this.walletLocalData.enabledTokens) {
|
|
412
451
|
try {
|
|
413
|
-
this.edgeTxLibCallbacks.
|
|
414
|
-
|
|
415
|
-
this.walletLocalData.totalBalances
|
|
452
|
+
this.edgeTxLibCallbacks.onTokenBalanceChanged(
|
|
453
|
+
tokenId,
|
|
454
|
+
_nullishCoalesce(this.walletLocalData.totalBalances.get(tokenId), () => ( '0'))
|
|
416
455
|
)
|
|
417
456
|
} catch (e) {
|
|
418
|
-
this.log.error('Error for currencyCode',
|
|
457
|
+
this.log.error('Error for currencyCode', tokenId, e)
|
|
419
458
|
}
|
|
420
459
|
}
|
|
421
460
|
}
|
|
@@ -481,13 +520,11 @@ const PRIMARY_CURRENCY = _moneroInfo.currencyInfo.currencyCode
|
|
|
481
520
|
async resyncBlockchain() {
|
|
482
521
|
await this.killEngine()
|
|
483
522
|
this.myMoneroApi.keyImageCache = {}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
})
|
|
490
|
-
this.walletLocalData = new (0, _MoneroLocalData.MoneroLocalData)(temp)
|
|
523
|
+
this.walletLocalData = _MoneroLocalData.asMoneroLocalData.call(void 0,
|
|
524
|
+
JSON.stringify({
|
|
525
|
+
enabledTokens: this.walletLocalData.enabledTokens
|
|
526
|
+
})
|
|
527
|
+
)
|
|
491
528
|
this.walletLocalDataDirty = true
|
|
492
529
|
this.addressesChecked = false
|
|
493
530
|
await this.saveWalletLoop()
|
|
@@ -528,46 +565,32 @@ const PRIMARY_CURRENCY = _moneroInfo.currencyInfo.currencyCode
|
|
|
528
565
|
return false
|
|
529
566
|
}
|
|
530
567
|
|
|
531
|
-
getBalance(options
|
|
532
|
-
const {
|
|
568
|
+
getBalance(options) {
|
|
569
|
+
const { tokenId = PRIMARY_CURRENCY_TOKEN_ID } = options
|
|
533
570
|
|
|
534
|
-
|
|
535
|
-
typeof this.walletLocalData.totalBalances[currencyCode] === 'undefined'
|
|
536
|
-
) {
|
|
537
|
-
return '0'
|
|
538
|
-
} else {
|
|
539
|
-
const nativeBalance = this.walletLocalData.totalBalances[currencyCode]
|
|
540
|
-
return nativeBalance
|
|
541
|
-
}
|
|
571
|
+
return _nullishCoalesce(this.walletLocalData.totalBalances.get(tokenId), () => ( '0'))
|
|
542
572
|
}
|
|
543
573
|
|
|
544
|
-
getNumTransactions(options
|
|
545
|
-
const {
|
|
574
|
+
getNumTransactions(options) {
|
|
575
|
+
const { tokenId = PRIMARY_CURRENCY_TOKEN_ID } = options
|
|
546
576
|
|
|
547
|
-
|
|
548
|
-
typeof this.walletLocalData.transactionsObj[currencyCode] === 'undefined'
|
|
549
|
-
) {
|
|
550
|
-
return 0
|
|
551
|
-
} else {
|
|
552
|
-
return this.walletLocalData.transactionsObj[currencyCode].length
|
|
553
|
-
}
|
|
577
|
+
return _nullishCoalesce(_optionalChain([this, 'access', _ => _.walletLocalData, 'access', _2 => _2.transactionsObj, 'access', _3 => _3.get, 'call', _4 => _4(tokenId), 'optionalAccess', _5 => _5.length]), () => ( 0))
|
|
554
578
|
}
|
|
555
579
|
|
|
556
580
|
async getTransactions(
|
|
557
|
-
options
|
|
581
|
+
options
|
|
558
582
|
) {
|
|
559
|
-
const {
|
|
583
|
+
const { tokenId = PRIMARY_CURRENCY_TOKEN_ID } = options
|
|
560
584
|
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
return this.walletLocalData.transactionsObj[currencyCode].slice(0)
|
|
585
|
+
return (_nullishCoalesce(this.walletLocalData.transactionsObj.get(tokenId), () => (
|
|
586
|
+
[])))
|
|
566
587
|
}
|
|
567
588
|
|
|
568
589
|
async getFreshAddress(
|
|
569
590
|
options
|
|
570
591
|
) {
|
|
592
|
+
// Do not show the address before logging into my monero...
|
|
593
|
+
if (!this.walletLocalData.hasLoggedIn) return { publicAddress: '' }
|
|
571
594
|
return { publicAddress: this.walletInfo.keys.moneroAddress }
|
|
572
595
|
}
|
|
573
596
|
|
|
@@ -581,7 +604,7 @@ const PRIMARY_CURRENCY = _moneroInfo.currencyInfo.currencyCode
|
|
|
581
604
|
edgeSpendInfo,
|
|
582
605
|
opts
|
|
583
606
|
) {
|
|
584
|
-
const privateKeys = _moneroTypes.asPrivateKeys.call(void 0, _optionalChain([opts, 'optionalAccess',
|
|
607
|
+
const privateKeys = _moneroTypes.asPrivateKeys.call(void 0, _optionalChain([opts, 'optionalAccess', _6 => _6.privateKeys]))
|
|
585
608
|
const [spendTarget] = edgeSpendInfo.spendTargets
|
|
586
609
|
const { publicAddress } = spendTarget
|
|
587
610
|
if (publicAddress == null) {
|
|
@@ -628,7 +651,7 @@ const PRIMARY_CURRENCY = _moneroInfo.currencyInfo.currencyCode
|
|
|
628
651
|
opts
|
|
629
652
|
) {
|
|
630
653
|
const { memos = [] } = edgeSpendInfo
|
|
631
|
-
const privateKeys = _moneroTypes.asPrivateKeys.call(void 0, _optionalChain([opts, 'optionalAccess',
|
|
654
|
+
const privateKeys = _moneroTypes.asPrivateKeys.call(void 0, _optionalChain([opts, 'optionalAccess', _7 => _7.privateKeys]))
|
|
632
655
|
|
|
633
656
|
// Monero can only have one output
|
|
634
657
|
// TODO: The new SDK fixes this!
|
|
@@ -645,11 +668,16 @@ const PRIMARY_CURRENCY = _moneroInfo.currencyInfo.currencyCode
|
|
|
645
668
|
throw new (0, _types.NoAmountSpecifiedError)()
|
|
646
669
|
}
|
|
647
670
|
|
|
648
|
-
if (
|
|
671
|
+
if (
|
|
672
|
+
_biggystring.gte.call(void 0,
|
|
673
|
+
nativeAmount,
|
|
674
|
+
_nullishCoalesce(this.walletLocalData.totalBalances.get(PRIMARY_CURRENCY_TOKEN_ID), () => ( '0'))
|
|
675
|
+
)
|
|
676
|
+
) {
|
|
649
677
|
if (_biggystring.gte.call(void 0, this.walletLocalData.lockedXmrBalance, nativeAmount)) {
|
|
650
678
|
throw new (0, _types.PendingFundsError)()
|
|
651
679
|
} else {
|
|
652
|
-
throw new (0, _types.InsufficientFundsError)()
|
|
680
|
+
throw new (0, _types.InsufficientFundsError)({ tokenId: PRIMARY_CURRENCY_TOKEN_ID })
|
|
653
681
|
}
|
|
654
682
|
}
|
|
655
683
|
|
|
@@ -677,6 +705,7 @@ const PRIMARY_CURRENCY = _moneroInfo.currencyInfo.currencyCode
|
|
|
677
705
|
memos,
|
|
678
706
|
nativeAmount: '-' + result.total_sent,
|
|
679
707
|
networkFee: result.used_fee,
|
|
708
|
+
networkFees: [{ tokenId: null, nativeAmount: result.used_fee }],
|
|
680
709
|
ourReceiveAddresses: [], // ourReceiveAddresses
|
|
681
710
|
signedTx: result.serialized_signed_tx,
|
|
682
711
|
tokenId: null,
|
|
@@ -718,8 +747,6 @@ const PRIMARY_CURRENCY = _moneroInfo.currencyInfo.currencyCode
|
|
|
718
747
|
|
|
719
748
|
async saveTx(edgeTransaction) {
|
|
720
749
|
await this.addTransaction(edgeTransaction.currencyCode, edgeTransaction)
|
|
721
|
-
|
|
722
|
-
this.edgeTxLibCallbacks.onTransactionsChanged([edgeTransaction])
|
|
723
750
|
}
|
|
724
751
|
|
|
725
752
|
getDisplayPrivateSeed(privateKeys) {
|
|
@@ -728,7 +755,7 @@ const PRIMARY_CURRENCY = _moneroInfo.currencyInfo.currencyCode
|
|
|
728
755
|
}
|
|
729
756
|
|
|
730
757
|
getDisplayPublicSeed() {
|
|
731
|
-
if (_optionalChain([this, 'access',
|
|
758
|
+
if (_optionalChain([this, 'access', _8 => _8.walletInfo, 'access', _9 => _9.keys, 'optionalAccess', _10 => _10.moneroViewKeyPrivate]) != null) {
|
|
732
759
|
return this.walletInfo.keys.moneroViewKeyPrivate
|
|
733
760
|
}
|
|
734
761
|
return ''
|
|
@@ -766,15 +793,15 @@ function translateFee(fee) {
|
|
|
766
793
|
await engine.init()
|
|
767
794
|
try {
|
|
768
795
|
const result = await engine.walletLocalDisklet.getText(_MoneroLocalData.DATA_STORE_FILE)
|
|
769
|
-
engine.walletLocalData =
|
|
796
|
+
engine.walletLocalData = _MoneroLocalData.asMoneroLocalData.call(void 0, result)
|
|
770
797
|
} catch (err) {
|
|
771
798
|
try {
|
|
772
799
|
opts.log(err)
|
|
773
800
|
opts.log('No walletLocalData setup yet: Failure is ok')
|
|
774
|
-
engine.walletLocalData =
|
|
801
|
+
engine.walletLocalData = _MoneroLocalData.asMoneroLocalData.call(void 0, '{}')
|
|
775
802
|
await engine.walletLocalDisklet.setText(
|
|
776
803
|
_MoneroLocalData.DATA_STORE_FILE,
|
|
777
|
-
|
|
804
|
+
_MoneroLocalData.wasMoneroLocalData.call(void 0, engine.walletLocalData)
|
|
778
805
|
)
|
|
779
806
|
} catch (e) {
|
|
780
807
|
opts.log.error(
|