Skip to content

Commit 81abbd1

Browse files
authored
Merge pull request #98 from EdgeApp/william/lws-fixes
LWS fixes
2 parents a62a270 + 6587062 commit 81abbd1

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- fixed: Handle REST responses from monero-lws.
6+
57
## 2.0.0 (2025-10-02)
68

79
- changed: *Breaking change* Change to use Edge LWS servers. Must specify edgeApiKey in plugin options, instead of apiKey

src/MoneroEngine.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,8 @@ export class MoneroEngine implements EdgeCurrencyEngine {
261261
ourReceiveAddresses.push(this.walletInfo.keys.moneroAddress.toLowerCase())
262262
}
263263

264-
let blockHeight = tx.height
265-
if (tx.mempool) {
266-
blockHeight = 0
267-
}
268-
269-
const date = Date.parse(tx.timestamp) / 1000
264+
const blockHeight = tx.height == null || tx.mempool ? 0 : tx.height
265+
const date = tx.timestamp == null ? new Date() : new Date(tx.timestamp)
270266

271267
// Expose legacy payment ID's to the GUI. This only applies
272268
// to really old transactions, before integrated addresses:
@@ -282,7 +278,7 @@ export class MoneroEngine implements EdgeCurrencyEngine {
282278
const edgeTransaction: EdgeTransaction = {
283279
blockHeight,
284280
currencyCode: 'XMR',
285-
date,
281+
date: date.valueOf() / 1000,
286282
isSend: lt(netNativeAmount, '0'),
287283
memos,
288284
nativeAmount: netNativeAmount,
@@ -401,20 +397,20 @@ export class MoneroEngine implements EdgeCurrencyEngine {
401397
})
402398
} else {
403399
const txs = this.getTxs(tokenId)
404-
const edgeTx = txs[idx]
400+
const oldTx = txs[idx]
401+
402+
// Keep the first-seen date for unconfirmed transactions:
403+
if (edgeTransaction.blockHeight === 0) edgeTransaction.date = oldTx.date
405404

406405
// Already have this tx in the database. Consider a change if blockHeight changed
407-
if (edgeTx.blockHeight === edgeTransaction.blockHeight) return
406+
if (oldTx.blockHeight === edgeTransaction.blockHeight) return
408407
this.log(
409408
`Update transaction: ${edgeTransaction.txid} height:${edgeTransaction.blockHeight}`
410409
)
411410

412411
// The native amounts returned from the API take some time before they're
413412
// accurate. We can trust the amounts we saved instead.
414-
edgeTransaction = {
415-
...edgeTransaction,
416-
nativeAmount: edgeTx.nativeAmount
417-
}
413+
edgeTransaction.nativeAmount = oldTx.nativeAmount
418414

419415
// Update the transaction
420416
txs[idx] = edgeTransaction

src/MyMoneroApi.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ export interface ParsedTransaction {
7676
// See asGetAddressTxsResponse for these fields:
7777
coinbase: boolean
7878
hash: string
79-
height: number
79+
height?: number
8080
id: number
8181
mempool: boolean
8282
mixin: number
8383
payment_id?: string
8484
spent_outputs?: SpentOutput[]
85-
timestamp: string
85+
timestamp?: string
8686
total_received: string
8787
total_sent: string
8888
unlock_time: number
@@ -125,13 +125,13 @@ const asGetAddressTxsResponse = asObject({
125125
asObject({
126126
coinbase: asNumberBoolean, // True if tx is coinbase
127127
hash: asString, // Bytes of tx hash
128-
height: asNumber, // Block height
128+
height: asOptional(asNumber), // Block height
129129
id: asNumber, // Index of tx in blockchain
130130
mempool: asNumberBoolean, // True if tx is in mempool
131131
mixin: asNumber, // Mixin of the receive
132132
payment_id: asOptional(asString), // Bytes of tx payment id
133133
spent_outputs: asOptional(asArray(asSpentOutput)), // List of possible spends
134-
timestamp: asString, // Timestamp of block
134+
timestamp: asOptional(asString), // Timestamp of block
135135
total_received: asString, // Total XMR received
136136
total_sent: asString, // XMR possibly being spent
137137
unlock_time: asNumber // Tx unlock time field
@@ -252,6 +252,9 @@ export class MyMoneroApi {
252252
use_dust: true,
253253
view_key: privateViewKey
254254
})
255+
for (const out of unspentOuts.outputs) {
256+
if (out.spend_key_images == null) out.spend_key_images = []
257+
}
255258

256259
// Grab some random outputs to mix in:
257260
const randomOutsCb = async (count: number): Promise<any> => {

0 commit comments

Comments
 (0)