diff --git a/app/src/main/java/com/algorand/android/modules/assetinbox/assetinboxoneaccount/data/mapper/AssetInboxOneAccountMapperImpl.kt b/app/src/main/java/com/algorand/android/modules/assetinbox/assetinboxoneaccount/data/mapper/AssetInboxOneAccountMapperImpl.kt index 091ba4ee..db4747a6 100644 --- a/app/src/main/java/com/algorand/android/modules/assetinbox/assetinboxoneaccount/data/mapper/AssetInboxOneAccountMapperImpl.kt +++ b/app/src/main/java/com/algorand/android/modules/assetinbox/assetinboxoneaccount/data/mapper/AssetInboxOneAccountMapperImpl.kt @@ -10,11 +10,10 @@ * limitations under the License */ -package com.algorand.android.modules.assetinbox.assetinboxallaccounts.data.mapper +package com.algorand.android.modules.assetinbox.assetinboxoneaccount.data.mapper import com.algorand.android.assetsearch.data.mapper.VerificationTierDTODecider import com.algorand.android.assetsearch.domain.mapper.VerificationTierDecider -import com.algorand.android.modules.assetinbox.assetinboxoneaccount.data.mapper.AssetInboxOneAccountMapper import com.algorand.android.modules.assetinbox.assetinboxoneaccount.data.model.AssetInboxOneAccountPaginatedResponse import com.algorand.android.modules.assetinbox.assetinboxoneaccount.data.model.AssetInboxOneAccountPaginatedResponse.AssetInboxOneAccountResultResponse import com.algorand.android.modules.assetinbox.assetinboxoneaccount.data.model.AssetInboxOneAccountPaginatedResponse.AssetResponse @@ -63,7 +62,7 @@ class AssetInboxOneAccountMapperImpl @Inject constructor( private fun mapToAssetInboxOneAccountResult(response: AssetInboxOneAccountResultResponse?): AssetInboxOneAccountResult { return AssetInboxOneAccountResult( - totalAmount = response?.totalAmount ?: 0, + totalAmount = response?.totalAmount ?: BigInteger.ZERO, asset = mapToAsset(response?.asset), algoGainOnClaim = response?.algoGainOnClaim ?: BigInteger.ZERO, algoGainOnReject = response?.algoGainOnReject ?: BigInteger.ZERO, diff --git a/app/src/main/java/com/algorand/android/modules/assetinbox/assetinboxoneaccount/data/model/AssetInboxOneAccountPaginatedResponse.kt b/app/src/main/java/com/algorand/android/modules/assetinbox/assetinboxoneaccount/data/model/AssetInboxOneAccountPaginatedResponse.kt index 5d551674..1b964243 100644 --- a/app/src/main/java/com/algorand/android/modules/assetinbox/assetinboxoneaccount/data/model/AssetInboxOneAccountPaginatedResponse.kt +++ b/app/src/main/java/com/algorand/android/modules/assetinbox/assetinboxoneaccount/data/model/AssetInboxOneAccountPaginatedResponse.kt @@ -33,7 +33,7 @@ data class AssetInboxOneAccountPaginatedResponse( data class AssetInboxOneAccountResultResponse( @SerializedName("total_amount") - val totalAmount: Int?, + val totalAmount: BigInteger?, @SerializedName("asset") val asset: AssetResponse?, @SerializedName("algo_gain_on_claim") diff --git a/app/src/main/java/com/algorand/android/modules/assetinbox/assetinboxoneaccount/di/AssetInboxOneAccountRepositoryModule.kt b/app/src/main/java/com/algorand/android/modules/assetinbox/assetinboxoneaccount/di/AssetInboxOneAccountRepositoryModule.kt index 86bd0bae..49a2be6a 100644 --- a/app/src/main/java/com/algorand/android/modules/assetinbox/assetinboxoneaccount/di/AssetInboxOneAccountRepositoryModule.kt +++ b/app/src/main/java/com/algorand/android/modules/assetinbox/assetinboxoneaccount/di/AssetInboxOneAccountRepositoryModule.kt @@ -10,9 +10,9 @@ * limitations under the License */ -package com.algorand.android.modules.assetinbox.assetinboxoneaccount.data.di +package com.algorand.android.modules.assetinbox.assetinboxoneaccount.di -import com.algorand.android.modules.assetinbox.assetinboxallaccounts.data.mapper.AssetInboxOneAccountMapperImpl +import com.algorand.android.modules.assetinbox.assetinboxoneaccount.data.mapper.AssetInboxOneAccountMapperImpl import com.algorand.android.modules.assetinbox.assetinboxoneaccount.data.mapper.AssetInboxOneAccountMapper import com.algorand.android.modules.assetinbox.assetinboxoneaccount.data.repository.AssetInboxOneAccountRepositoryImpl import com.algorand.android.modules.assetinbox.assetinboxoneaccount.data.service.AssetInboxOneAccountApiService diff --git a/app/src/main/java/com/algorand/android/modules/assetinbox/assetinboxoneaccount/domain/model/AssetInboxOneAccountPaginated.kt b/app/src/main/java/com/algorand/android/modules/assetinbox/assetinboxoneaccount/domain/model/AssetInboxOneAccountPaginated.kt index 179eebe1..f0e51b56 100644 --- a/app/src/main/java/com/algorand/android/modules/assetinbox/assetinboxoneaccount/domain/model/AssetInboxOneAccountPaginated.kt +++ b/app/src/main/java/com/algorand/android/modules/assetinbox/assetinboxoneaccount/domain/model/AssetInboxOneAccountPaginated.kt @@ -26,7 +26,7 @@ data class AssetInboxOneAccountPaginated( ) data class AssetInboxOneAccountResult( - val totalAmount: Int, + val totalAmount: BigInteger, val asset: Asset, val algoGainOnClaim: BigInteger, val algoGainOnReject: BigInteger, diff --git a/app/src/main/java/com/algorand/android/modules/assetinbox/assetinboxoneaccount/ui/mapper/AssetInboxOneAccountPreviewMapperImpl.kt b/app/src/main/java/com/algorand/android/modules/assetinbox/assetinboxoneaccount/ui/mapper/AssetInboxOneAccountPreviewMapperImpl.kt index 94b4a12a..500acaef 100644 --- a/app/src/main/java/com/algorand/android/modules/assetinbox/assetinboxoneaccount/ui/mapper/AssetInboxOneAccountPreviewMapperImpl.kt +++ b/app/src/main/java/com/algorand/android/modules/assetinbox/assetinboxoneaccount/ui/mapper/AssetInboxOneAccountPreviewMapperImpl.kt @@ -26,8 +26,8 @@ import com.algorand.android.utils.assetdrawable.BaseAssetDrawableProvider import com.algorand.android.utils.formatAmount import com.algorand.android.utils.formatAsAssetAmount import com.algorand.android.utils.formatAsCurrency +import com.algorand.android.utils.multiplyOrZero import com.algorand.android.utils.toShortenedAddress -import java.math.BigInteger import javax.inject.Inject class AssetInboxOneAccountPreviewMapperImpl @Inject constructor( @@ -61,7 +61,11 @@ class AssetInboxOneAccountPreviewMapperImpl @Inject constructor( result.asset.logo ) if (result.asset.collectible != null) { - createCollectiblePreview(assetInboxOneAccountPaginated, result, assetDrawableProvider) + createCollectiblePreview( + assetInboxOneAccountPaginated, + result, + assetDrawableProvider + ) } else { createAssetPreview(assetInboxOneAccountPaginated, result, assetDrawableProvider) } @@ -116,13 +120,14 @@ class AssetInboxOneAccountPreviewMapperImpl @Inject constructor( result: AssetInboxOneAccountResult, assetDrawableProvider: BaseAssetDrawableProvider ): AsaPreview { + return AsaPreview.AssetPreview( id = result.asset.assetId, receiverAddress = assetInboxOneAccountPaginated.receiverAddress, assetName = result.asset.name, shortName = result.asset.unitName, - usdValue = getFormattedUsdValue(result.asset.usdValue), - amount = getTotalAssetAmount(result), + usdValue = getFormattedUsdValue(result), + amount = result.totalAmount, logo = result.asset.collectible?.primaryImage, senderAccounts = result.senders.results.map { SenderPreview( @@ -165,19 +170,17 @@ class AssetInboxOneAccountPreviewMapperImpl @Inject constructor( ) } - private fun getTotalAssetAmount(result: AssetInboxOneAccountResult): BigInteger { - return result.senders.results.sumOf { it.amount } - } - private fun getFormattedAssetAmount(result: AssetInboxOneAccountResult): String { - return getTotalAssetAmount(result) + return result.totalAmount .formatAmount(result.asset.decimals) .formatAsAssetAmount(result.asset.unitName) } - private fun getFormattedUsdValue(usdValue: String): String { - return usdValue.toBigDecimalOrNull() - ?.formatAsCurrency(Currency.USD.symbol, isCompact = true) - .orEmpty() + private fun getFormattedUsdValue(result: AssetInboxOneAccountResult): String { + return result.totalAmount + .toBigDecimal() + .movePointLeft(result.asset.decimals) + .multiplyOrZero(result.asset.usdValue.toBigDecimalOrNull()) + .formatAsCurrency(Currency.USD.symbol, isCompact = true) } }