Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AND-5227 Fixed transaction mapping #395

Merged
merged 1 commit into from
Dec 6, 2023
Merged
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 @@ -85,6 +85,7 @@ internal class EthereumTransactionHistoryProvider(
decimals: Int,
filterType: TransactionHistoryRequest.FilterType,
): TransactionHistoryItem? {
val isOutgoing = isOutgoing(walletAddress, this, filterType)
val destinationType = extractDestinationType(walletAddress, this, filterType).guard {
Log.info { "Transaction $this doesn't contain a required value" }
return null
Expand All @@ -93,15 +94,21 @@ internal class EthereumTransactionHistoryProvider(
Log.info { "Transaction $this doesn't contain a required value" }
return null
}
val amount = extractAmount(tx = this, decimals = decimals, filterType = filterType).guard {
val amount = extractAmount(
tx = this,
decimals = decimals,
filterType = filterType,
isOutgoing = isOutgoing,
walletAddress = walletAddress
).guard {
Log.info { "Transaction $this doesn't contain a required value" }
return null
}

return TransactionHistoryItem(
txHash = txid,
timestamp = TimeUnit.SECONDS.toMillis(blockTime.toLong()),
isOutgoing = isOutgoing(walletAddress, this, filterType),
isOutgoing = isOutgoing,
destinationType = destinationType,
sourceType = sourceType,
status = extractStatus(tx = this),
Expand Down Expand Up @@ -155,8 +162,8 @@ internal class EthereumTransactionHistoryProvider(
.equals(walletAddress, ignoreCase = true)

is TransactionHistoryRequest.FilterType.Contract -> transaction.tokenTransfers
.firstOrNull { filterType.address.equals(it.contract, true) || filterType.address.equals(it.token, ignoreCase = true) }
?.from.equals(walletAddress, ignoreCase = true)
.filter { filterType.address.equals(it.contract, true) || filterType.address.equals(it.token, true) }
.any { it.from == walletAddress }
}
}

Expand Down Expand Up @@ -211,6 +218,8 @@ internal class EthereumTransactionHistoryProvider(
tx: GetAddressResponse.Transaction,
decimals: Int,
filterType: TransactionHistoryRequest.FilterType,
isOutgoing: Boolean,
walletAddress: String,
): Amount? {
return when (filterType) {
TransactionHistoryRequest.FilterType.Coin -> Amount(
Expand All @@ -221,7 +230,11 @@ internal class EthereumTransactionHistoryProvider(

is TransactionHistoryRequest.FilterType.Contract -> {
val transfer = tx.tokenTransfers
.firstOrNull { filterType.address.equals(it.contract, ignoreCase = true) || filterType.address.equals(it.token, ignoreCase = true) }
.filter { filterType.address.equals(it.contract, ignoreCase = true) || filterType.address.equals(it.token, ignoreCase = true) }
.firstOrNull { transfer ->
val otherAddress = if (isOutgoing) transfer.from else transfer.to
walletAddress.equals(otherAddress, ignoreCase = true)
}
.guard { return null }
val transferValue = transfer.value ?: "0"
val token = Token(
Expand Down