Skip to content

Commit

Permalink
convert to eth
Browse files Browse the repository at this point in the history
  • Loading branch information
trbutler4 committed Sep 15, 2024
1 parent 18d235a commit 630f49f
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class AccountBalanceActivity : ComponentActivity() {
// Get the balance of the account
val balancefinal = getBalance(accountAddress2)
Log.d("balance","${balancefinal}")
withContext(Dispatchers.Main) { balance= "${balancefinal.value} wei" }
withContext(Dispatchers.Main) { balance= "${weiToEther(balancefinal)} ETH" }
} catch (e: RpcRequestFailedException) {
withContext(Dispatchers.Main) { Toast.makeText(applicationContext, "${e.code}: ${e.message}", Toast.LENGTH_LONG).show() }
} catch (e: Exception) {
Expand Down Expand Up @@ -177,4 +177,9 @@ class AccountBalanceActivity : ComponentActivity() {
)
}

fun weiToEther(wei: Uint256): BigDecimal {
val weiInEther = BigDecimal("1000000000000000000") // 10^18
return BigDecimal(wei.value.toString()).divide(weiInEther)
}

}

0 comments on commit 630f49f

Please sign in to comment.