Skip to content

Commit

Permalink
PWN-945 - History and Send fixes (#2196)
Browse files Browse the repository at this point in the history
* PWN-948 - do not open details for token-2022 if input is empty
  • Loading branch information
gslevinkov authored Feb 14, 2024
1 parent dcd3b9a commit 27a2c3a
Show file tree
Hide file tree
Showing 13 changed files with 242 additions and 243 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ class HistoryAnalytics(
swapAnalytics.logSwapShowingDetails(
swapStatus = SwapAnalytics.SwapStatus.SUCCESS,
lastScreenName = analyticsInteractor.getPreviousScreenName(),
tokenAName = transaction.sourceSymbol,
tokenBName = transaction.destinationSymbol,
swapSum = transaction.receiveAmount.total,
swapUSD = transaction.sentAmount.totalInUsd.orZero(),
tokenAName = transaction.tokenA.symbol,
tokenBName = transaction.tokenB.symbol,
swapSum = transaction.tokenAAmount.total,
swapUSD = transaction.tokenBAmount.totalInUsd.orZero(),
feesSource = SwapAnalytics.FeeSource.UNKNOWN
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.p2p.wallet.history.interactor.mapper

import com.google.gson.Gson
import org.p2p.core.utils.Constants.FEE_RELAYER_ACCOUNTS
import org.p2p.core.utils.SOL_DECIMALS
import org.p2p.core.utils.fromJsonReified
import org.p2p.core.utils.toBigDecimalOrZero
import org.p2p.wallet.bridge.claim.repository.EthereumBridgeInMemoryRepository
Expand All @@ -10,16 +11,19 @@ import org.p2p.wallet.common.InAppFeatureFlags
import org.p2p.wallet.common.date.toZonedDateTime
import org.p2p.wallet.history.api.model.RpcHistoryFeeResponse
import org.p2p.wallet.history.api.model.RpcHistoryStatusResponse
import org.p2p.wallet.history.api.model.RpcHistoryTokenResponse
import org.p2p.wallet.history.api.model.RpcHistoryTransactionInfoResponse
import org.p2p.wallet.history.api.model.RpcHistoryTransactionResponse
import org.p2p.wallet.history.api.model.RpcHistoryTypeResponse
import org.p2p.wallet.history.model.rpc.RpcFee
import org.p2p.wallet.history.model.rpc.RpcHistoryAmount
import org.p2p.wallet.history.model.rpc.RpcHistoryTransaction
import org.p2p.wallet.history.model.rpc.RpcHistoryTransactionToken
import org.p2p.wallet.history.model.rpc.RpcHistoryTransactionType
import org.p2p.wallet.infrastructure.network.provider.TokenKeyProvider
import org.p2p.wallet.transaction.model.HistoryTransactionStatus
import org.p2p.wallet.utils.UsernameFormatter
import org.p2p.wallet.utils.emptyString

class RpcHistoryTransactionConverter(
private val tokenKeyProvider: TokenKeyProvider,
Expand Down Expand Up @@ -73,9 +77,8 @@ class RpcHistoryTransactionConverter(
type = transaction.type.toDomain(),
senderAddress = info.counterParty.address,
counterPartyUsername = usernameFormatter.formatOrNull(info.counterParty.username),
iconUrl = info.token.logoUrl,
token = info.token.toDomain(),
amount = RpcHistoryAmount(total, totalInUsd),
symbol = info.token.symbol.orEmpty(),
destination = tokenKeyProvider.publicKey,
fees = transaction.fees.parseFees()
)
Expand All @@ -100,6 +103,7 @@ class RpcHistoryTransactionConverter(
iconUrl = info.token.logoUrl,
amount = RpcHistoryAmount(total, totalInUsd),
symbol = info.token.symbol.orEmpty(),
decimals = info.token.decimals,
destination = tokenKeyProvider.publicKey,
fees = transaction.fees.parseFees()
)
Expand All @@ -119,9 +123,8 @@ class RpcHistoryTransactionConverter(
type = transaction.type.toDomain(),
senderAddress = tokenKeyProvider.publicKey,
counterPartyUsername = usernameFormatter.formatOrNull(info.counterParty.username),
iconUrl = info.token.logoUrl,
token = info.token.toDomain(),
amount = RpcHistoryAmount(total, totalInUsd),
symbol = info.token.symbol.orEmpty(),
destination = info.counterParty.address,
fees = transaction.fees.parseFees()
)
Expand All @@ -135,21 +138,20 @@ class RpcHistoryTransactionConverter(
val destinationTotal = info.to.amounts.amount.toBigDecimalOrZero()
val destinationTotalInUsd = info.to.amounts.usdAmount.toBigDecimalOrZero()

val tokenA = info.from.token
val tokenB = info.to.token

return RpcHistoryTransaction.Swap(
signature = transaction.signature,
date = transaction.date.toZonedDateTime(),
blockNumber = transaction.blockNumber.toInt(),
status = transaction.status.toDomain(),
sourceAddress = info.from.token.mint,
destinationAddress = info.to.token.mint,
receiveAmount = RpcHistoryAmount(sourceTotal, sourceTotalInUsd),
sentAmount = RpcHistoryAmount(destinationTotal, destinationTotalInUsd),
tokenA = tokenA.toDomain(),
tokenB = tokenB.toDomain(),
tokenAAmount = RpcHistoryAmount(sourceTotal, sourceTotalInUsd),
tokenBAmount = RpcHistoryAmount(destinationTotal, destinationTotalInUsd),
fees = transaction.fees.parseFees(),
sourceSymbol = info.from.token.symbol.orEmpty(),
sourceIconUrl = info.from.token.logoUrl,
destinationSymbol = info.to.token.symbol.orEmpty(),
destinationIconUrl = info.to.token.logoUrl,
type = transaction.type.toDomain()
type = transaction.type.toDomain(),
)
}

Expand All @@ -166,9 +168,8 @@ class RpcHistoryTransactionConverter(
status = transaction.status.toDomain(),
type = transaction.type.toDomain(),
senderAddress = tokenKeyProvider.publicKey,
iconUrl = info.token.logoUrl,
amount = RpcHistoryAmount(total, totalInUsd),
symbol = info.token.symbol.orEmpty(),
token = info.token.toDomain(),
destination = info.token.mint,
fees = transaction.fees.parseFees()
)
Expand All @@ -188,8 +189,7 @@ class RpcHistoryTransactionConverter(
type = transaction.type.toDomain(),
amount = RpcHistoryAmount(total, totalInUsd),
senderAddress = info.token.mint,
iconUrl = info.token.logoUrl,
symbol = info.token.symbol.orEmpty(),
token = info.token.toDomain(),
destination = tokenKeyProvider.publicKey,
fees = transaction.fees.parseFees()
)
Expand All @@ -206,9 +206,8 @@ class RpcHistoryTransactionConverter(
signature = transaction.signature,
blockNumber = transaction.blockNumber.toInt(),
status = transaction.status.toDomain(),
iconUrl = info.token.logoUrl,
fees = transaction.fees.parseFees(),
tokenSymbol = info.token.symbol.orEmpty(),
token = info.token.toDomain(),
type = transaction.type.toDomain(),
amount = RpcHistoryAmount(total, totalInUsd)
)
Expand Down Expand Up @@ -242,8 +241,7 @@ class RpcHistoryTransactionConverter(
date = transaction.date.toZonedDateTime(),
blockNumber = transaction.blockNumber.toInt(),
status = transaction.status.toDomain(),
tokenSymbol = info.token.symbol.orEmpty(),
iconUrl = info.token.logoUrl,
token = info.token.toDomain(),
type = transaction.type.toDomain(),
amount = RpcHistoryAmount(total, totalInUsd),
fees = transaction.fees.parseFees()
Expand All @@ -261,8 +259,7 @@ class RpcHistoryTransactionConverter(
date = transaction.date.toZonedDateTime(),
blockNumber = transaction.blockNumber.toInt(),
status = transaction.status.toDomain(),
tokenSymbol = info.token.symbol.orEmpty(),
iconUrl = info.token.logoUrl,
token = info.token.toDomain(),
type = transaction.type.toDomain(),
amount = RpcHistoryAmount(total, totalInUsd),
fees = transaction.fees.parseFees()
Expand Down Expand Up @@ -294,9 +291,10 @@ class RpcHistoryTransactionConverter(
blockNumber = transaction.blockNumber.toInt(),
status = transaction.status.toDomain(),
type = transaction.type.toDomain(),
tokenSymbol = info.tokenAmount?.token?.symbol.orEmpty(),
token = info.tokenAmount?.token?.toDomain() ?: RpcHistoryTransactionToken(
symbol = emptyString(), decimals = SOL_DECIMALS, logoUrl = null
),
amount = RpcHistoryAmount(total, totalInUsd),
iconUrl = info.tokenAmount?.token?.logoUrl,
fees = fees,
claimKey = claimKey
)
Expand Down Expand Up @@ -324,9 +322,10 @@ class RpcHistoryTransactionConverter(
blockNumber = transaction.blockNumber.toInt(),
status = transaction.status.toDomain(),
type = transaction.type.toDomain(),
tokenSymbol = info.tokenAmount?.token?.symbol.orEmpty(),
token = info.tokenAmount?.token?.toDomain() ?: RpcHistoryTransactionToken(
symbol = emptyString(), decimals = SOL_DECIMALS, logoUrl = null
),
amount = RpcHistoryAmount(total, totalInUsd),
iconUrl = info.tokenAmount?.token?.logoUrl,
fees = bundleFees.parseBridgeFees() ?: transaction.fees.parseFees(),
sourceAddress = info.to?.address.orEmpty(),
message = message
Expand All @@ -345,8 +344,10 @@ class RpcHistoryTransactionConverter(
blockNumber = transaction.blockNumber.toInt(),
status = transaction.status.toDomain(),
type = transaction.type.toDomain(),
tokenSymbol = info.token?.symbol.orEmpty(),
amount = RpcHistoryAmount(total, totalInUsd)
token = info.token?.toDomain() ?: RpcHistoryTransactionToken(
symbol = emptyString(), decimals = SOL_DECIMALS, logoUrl = null
),
amount = RpcHistoryAmount(total = total, totalInUsd = totalInUsd)
)
}
}
Expand Down Expand Up @@ -376,8 +377,14 @@ private fun RpcHistoryTypeResponse?.toDomain(): RpcHistoryTransactionType {
}
}

private fun RpcHistoryTokenResponse.toDomain(): RpcHistoryTransactionToken = RpcHistoryTransactionToken(
symbol = symbol.orEmpty(),
decimals = decimals,
logoUrl = logoUrl
)

private fun List<RpcHistoryFeeResponse>.parseFees(): List<RpcFee>? {
return if (this.all { fee -> FEE_RELAYER_ACCOUNTS.contains(fee.payer) }) {
return if (this.all { fee -> fee.payer in FEE_RELAYER_ACCOUNTS }) {
null
} else {
map { fee ->
Expand Down
Loading

0 comments on commit 27a2c3a

Please sign in to comment.