Skip to content

Commit

Permalink
PERA-929 :: Amount of ASA in asset inbox not displayed correctly (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
yasin-ce authored Oct 31, 2024
1 parent a0778e3 commit 17beeed
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
}
}

0 comments on commit 17beeed

Please sign in to comment.