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-5266 Fixed tokens decimal parsing in transaction history #380

Merged
merged 1 commit into from
Nov 21, 2023
Merged
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 @@ -60,6 +60,7 @@ internal class EthereumTransactionHistoryProvider(
?.mapNotNull { tx ->
tx.toTransactionHistoryItem(
walletAddress = request.address,
decimals = request.decimals,
filterType = request.filterType
)
}
Expand All @@ -79,6 +80,7 @@ internal class EthereumTransactionHistoryProvider(

private fun GetAddressResponse.Transaction.toTransactionHistoryItem(
walletAddress: String,
decimals: Int,
filterType: TransactionHistoryRequest.FilterType,
): TransactionHistoryItem? {
val destinationType = extractDestinationType(walletAddress, this, filterType).guard {
Expand All @@ -89,7 +91,7 @@ internal class EthereumTransactionHistoryProvider(
Log.info { "Transaction $this doesn't contain a required value" }
return null
}
val amount = extractAmount(tx = this, filterType = filterType).guard {
val amount = extractAmount(tx = this, decimals = decimals, filterType = filterType).guard {
Log.info { "Transaction $this doesn't contain a required value" }
return null
}
Expand Down Expand Up @@ -196,6 +198,7 @@ internal class EthereumTransactionHistoryProvider(

private fun extractAmount(
tx: GetAddressResponse.Transaction,
decimals: Int,
filterType: TransactionHistoryRequest.FilterType,
): Amount? {
return when (filterType) {
Expand All @@ -214,9 +217,9 @@ internal class EthereumTransactionHistoryProvider(
name = transfer.name.orEmpty(),
symbol = transfer.symbol.orEmpty(),
contractAddress = transfer.contract.orEmpty(),
decimals = transfer.decimals,
decimals = decimals,
)
Amount(value = BigDecimal(transferValue).movePointLeft(transfer.decimals), token = token)
Amount(value = BigDecimal(transferValue).movePointLeft(decimals), token = token)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ internal class TronTransactionHistoryProvider(
?.mapNotNull { tx ->
tx.toTransactionHistoryItem(
walletAddress = request.address,
filterType = request.filterType
decimals = request.decimals,
filterType = request.filterType,
)
}
?: emptyList()
Expand All @@ -79,13 +80,14 @@ internal class TronTransactionHistoryProvider(

private fun GetAddressResponse.Transaction.toTransactionHistoryItem(
walletAddress: String,
decimals: Int,
filterType: TransactionHistoryRequest.FilterType,
): TransactionHistoryItem? {
val destinationType = extractDestinationType(this, filterType).guard {
Log.info { "Transaction $this doesn't contain a required value" }
return null
}
val amount = extractAmount(tx = this, filterType = filterType).guard {
val amount = extractAmount(tx = this, decimals = decimals, filterType = filterType).guard {
Log.info { "Transaction $this doesn't contain a required value" }
return null
}
Expand Down Expand Up @@ -154,6 +156,7 @@ internal class TronTransactionHistoryProvider(

private fun extractAmount(
tx: GetAddressResponse.Transaction,
decimals: Int,
filterType: TransactionHistoryRequest.FilterType,
): Amount? {
return when (filterType) {
Expand All @@ -170,9 +173,9 @@ internal class TronTransactionHistoryProvider(
name = transfer.name.orEmpty(),
symbol = transfer.symbol.orEmpty(),
contractAddress = transfer.token.orEmpty(),
decimals = transfer.decimals,
decimals = decimals,
)
Amount(value = BigDecimal(transferValue).movePointLeft(transfer.decimals), token = token)
Amount(value = BigDecimal(transferValue).movePointLeft(decimals), token = token)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ private const val DEFAULT_PAGING_SIZE = 20

data class TransactionHistoryRequest(
val address: String,
val decimals: Int,
val page: Page,
val filterType: FilterType,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ data class GetAddressResponse(
@Json(name = "token") val token: String?,
@Json(name = "name") val name: String?,
@Json(name = "symbol") val symbol: String?,
@Json(name = "decimals") val decimals: Int,
@Json(name = "value") val value: String?,
)

Expand Down