Skip to content

Commit 5968e95

Browse files
committed
Handle missing height & timestamp when unconfirmed
1 parent 0a233e3 commit 5968e95

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

src/MoneroEngine.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,8 @@ export class MoneroEngine implements EdgeCurrencyEngine {
231231
ourReceiveAddresses.push(this.walletInfo.keys.moneroAddress.toLowerCase())
232232
}
233233

234-
let blockHeight = tx.height
235-
if (tx.mempool) {
236-
blockHeight = 0
237-
}
238-
239-
const date = Date.parse(tx.timestamp) / 1000
234+
const blockHeight = tx.height == null || tx.mempool ? 0 : tx.height
235+
const date = tx.timestamp == null ? new Date() : new Date(tx.timestamp)
240236

241237
// Expose legacy payment ID's to the GUI. This only applies
242238
// to really old transactions, before integrated addresses:
@@ -249,10 +245,10 @@ export class MoneroEngine implements EdgeCurrencyEngine {
249245
})
250246
}
251247

252-
let edgeTransaction: EdgeTransaction = {
248+
const edgeTransaction: EdgeTransaction = {
253249
blockHeight,
254250
currencyCode: 'XMR',
255-
date,
251+
date: date.valueOf() / 1000,
256252
isSend: lt(netNativeAmount, '0'),
257253
memos,
258254
nativeAmount: netNativeAmount,
@@ -280,16 +276,14 @@ export class MoneroEngine implements EdgeCurrencyEngine {
280276
// Already have this tx in the database. See if anything changed
281277
const transactionsArray: EdgeTransaction[] =
282278
this.walletLocalData.transactionsObj[PRIMARY_CURRENCY]
283-
const edgeTx = transactionsArray[idx]
279+
const oldTx = transactionsArray[idx]
284280

285-
if (edgeTx.blockHeight !== edgeTransaction.blockHeight) {
281+
if (oldTx.date < edgeTransaction.date) edgeTransaction.date = oldTx.date
282+
if (oldTx.blockHeight !== edgeTransaction.blockHeight) {
286283
// The native amounts returned from the API take some time before they're accurate. We can trust the amounts we saved instead.
287-
edgeTransaction = {
288-
...edgeTransaction,
289-
nativeAmount: edgeTx.nativeAmount
290-
}
284+
edgeTransaction.nativeAmount = oldTx.nativeAmount
291285

292-
this.log(`Update transaction: ${tx.hash} height:${tx.height}`)
286+
this.log(`Update transaction: ${tx.hash} height:${blockHeight}`)
293287
this.updateTransaction(PRIMARY_CURRENCY, edgeTransaction, idx)
294288
this.edgeTxLibCallbacks.onTransactionsChanged(
295289
this.transactionsChangedArray

src/MyMoneroApi.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ export interface ParsedTransaction {
7474
// See asGetAddressTxsResponse for these fields:
7575
coinbase: boolean
7676
hash: string
77-
height: number
77+
height?: number
7878
id: number
7979
mempool: boolean
8080
mixin: number
8181
payment_id?: string
8282
spent_outputs?: SpentOutput[]
83-
timestamp: string
83+
timestamp?: string
8484
total_received: string
8585
total_sent: string
8686
unlock_time: number
@@ -123,13 +123,13 @@ const asGetAddressTxsResponse = asObject({
123123
asObject({
124124
coinbase: asNumberBoolean, // True if tx is coinbase
125125
hash: asString, // Bytes of tx hash
126-
height: asNumber, // Block height
126+
height: asOptional(asNumber), // Block height
127127
id: asNumber, // Index of tx in blockchain
128128
mempool: asNumberBoolean, // True if tx is in mempool
129129
mixin: asNumber, // Mixin of the receive
130130
payment_id: asOptional(asString), // Bytes of tx payment id
131131
spent_outputs: asOptional(asArray(asSpentOutput)), // List of possible spends
132-
timestamp: asString, // Timestamp of block
132+
timestamp: asOptional(asString), // Timestamp of block
133133
total_received: asString, // Total XMR received
134134
total_sent: asString, // XMR possibly being spent
135135
unlock_time: asNumber // Tx unlock time field

0 commit comments

Comments
 (0)