Skip to content

Commit

Permalink
Fix showing 'null' decimals on token details
Browse files Browse the repository at this point in the history
Show 0 instead of 'null' when a token has no decimals in the metadata.
  • Loading branch information
Radiokot committed Sep 9, 2024
1 parent 186ee37 commit be924c7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,8 @@ object CurrencyUtil {
return strBuilder.toString().removeSuffix(separator.toString())
}

fun toGTUValue(stringValue: String, token: Token?): BigInteger? {
var decimals = 0
token?.let {
it.metadata?.decimals?.let { tokenDecimals ->
decimals = tokenDecimals
}
}
return toGTUValue(stringValue, decimals)
}
fun toGTUValue(stringValue: String, token: Token?): BigInteger? =
toGTUValue(stringValue, token?.decimals ?: 0)

fun toGTUValue(stringValue: String, decimals: Int = 6): BigInteger? {
var str = stringValue.replace("Ͼ", "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class TokenDetailsActivity : BaseActivity(R.layout.activity_token_details) {
setOwnership(token, tokenMetadata)
setDescription(tokenMetadata)
setTicker(tokenMetadata)
setDecimals(tokenMetadata)
setDecimals(token)
}
if (token.isNewlyReceived) {
handleNewlyReceivedToken(token)
Expand Down Expand Up @@ -222,10 +222,10 @@ class TokenDetailsActivity : BaseActivity(R.layout.activity_token_details) {
}
}

private fun setDecimals(tokenMetadata: TokenMetadata) {
if (tokenMetadata.unique != true) {
private fun setDecimals(token: Token) {
if (!token.isUnique) {
binding.includeAbout.decimalsHolder.visibility = View.VISIBLE
binding.includeAbout.decimals.text = tokenMetadata.decimals.toString()
binding.includeAbout.decimals.text = token.decimals.toString()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ManageTokensSelectionAdapter(
val tokenBalance = CurrencyUtil.formatGTU(
token.balance,
false,
token.metadata?.decimals ?: 0
token.decimals
)
holder.binding.subtitle.text =
context.getString(R.string.cis_search_balance, tokenBalance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ManageTokensTokenDetailsFragment : Fragment() {
setImage(tokenMetadata)
setDescription(tokenMetadata)
setTicker(tokenMetadata)
setDecimals(tokenMetadata)
setDecimals(token)
}
}
}
Expand Down Expand Up @@ -125,10 +125,10 @@ class ManageTokensTokenDetailsFragment : Fragment() {
}
}

private fun setDecimals(tokenMetadata: TokenMetadata) {
if (tokenMetadata.unique != true) {
private fun setDecimals(token: Token) {
if (!token.isUnique) {
binding.details.decimalsHolder.visibility = View.VISIBLE
binding.details.decimals.text = tokenMetadata.decimals.toString()
binding.details.decimals.text = token.decimals.toString()
}
}
}

0 comments on commit be924c7

Please sign in to comment.