Skip to content

Commit

Permalink
Fix usd value of inbox assets
Browse files Browse the repository at this point in the history
  • Loading branch information
yasin-ce committed Oct 29, 2024
1 parent de11766 commit 61ccc4e
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ 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
Expand Down Expand Up @@ -61,7 +62,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,12 +121,13 @@ 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),
usdValue = getFormattedUsdValue(result),
amount = getTotalAssetAmount(result),
logo = result.asset.collectible?.primaryImage,
senderAccounts = result.senders.results.map {
Expand Down Expand Up @@ -175,9 +181,11 @@ class AssetInboxOneAccountPreviewMapperImpl @Inject constructor(
.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 getTotalAssetAmount(result)
.toBigDecimal()
.movePointLeft(result.asset.decimals)
.multiplyOrZero(result.asset.usdValue.toBigDecimal())
.formatAsCurrency(Currency.USD.symbol, isCompact = true)
}
}

0 comments on commit 61ccc4e

Please sign in to comment.