Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ interface Web3TransactionDao : BaseDao<Web3Transaction> {
@Query("DELETE FROM transactions WHERE status = 'pending' AND transaction_hash = :hash AND chain_id = :chainId")
fun deletePending(hash: String, chainId: String)

@Query("UPDATE transactions SET status = :status WHERE transaction_hash = :hash AND chain_id = :chainId")
fun updateTransaction(hash: String, status: String, chainId: String)
@Query("UPDATE transactions SET status = :status WHERE transaction_hash = :hash AND chain_id = :chainId AND address = :address")
fun updateTransaction(hash: String, status: String, chainId: String, address: String)

@Query("DELETE FROM transactions")
suspend fun deleteAllTransactions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1897,7 +1897,7 @@ class TokenRepository
updatedAt = updatedAt,
),
)
web3TransactionDao.updateTransaction(hash, status, chainId)
web3TransactionDao.updateTransaction(hash, status, chainId, pendingRaw.account)
}
}

Expand All @@ -1910,7 +1910,7 @@ class TokenRepository
) {
walletDatabase.withRoomTransaction {
web3RawTransactionDao.insertSuspend(raw)
web3TransactionDao.updateTransaction(hash, status, chainId)
web3TransactionDao.updateTransaction(hash, status, chainId, raw.account)
if (chainId !in Constants.Web3UtxoChainIds || utxoRawTransactionHexToDeleteOutputs.isNullOrBlank()) return@withRoomTransaction
val cleanedHex: String = utxoRawTransactionHexToDeleteOutputs.removePrefix("0x").trim()
if (cleanedHex.isBlank()) return@withRoomTransaction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,39 @@ class TokenRepositoryWalletTransactionTest {
}
}

@Test
fun statusUpdatesOnlyAffectMatchingTransactionAddress() = runBlocking<Unit> {
insertSigned()
wallet.web3AddressDao().insertSuspend(Web3Address("receiver-address", "receiver-wallet", chain, "receiver", null, createdAt))
val outgoing = assertNotNull(transaction("signed"))
val records = listOf(
outgoing,
outgoing.copy(address = "receiver", transactionType = "transfer_in"),
outgoing.copy(chainId = "other-chain"),
outgoing.copy(transactionHash = "other-hash"),
)
for (gasless in listOf(true, false)) {
wallet.web3TransactionDao().insert(*records.toTypedArray())
val status = if (gasless) "failed" else "success"
if (gasless) {
repository.updateGaslessPendingTransactionStatus("wallet", "signed", chain, status, updatedAt)
} else {
repository.insertRawTransactionAndUpdateTransactionStatus(rawRecord("signed").copy(state = status), "signed", status, chain, null)
}
assertEquals(status, assertNotNull(raw("signed")).state)
for (record in records) {
RoomDatabaseCompat.query(
wallet,
"SELECT status FROM transactions WHERE transaction_hash = ? AND chain_id = ? AND address = ?",
arrayOf(record.transactionHash, record.chainId, record.address),
).use {
assertTrue(it.moveToFirst())
assertEquals(if (record == outgoing) status else "pending", it.getString(0))
}
}
}
}

@Test
fun statusUpdateWithoutTransactionStillUpdatesRawRow() = runBlocking<Unit> {
wallet.web3RawTransactionDao().insertSuspend(rawRecord("signed"))
Expand Down
Loading