From 53c2018a5f80e4f05cb54aac663e953f6863af9e Mon Sep 17 00:00:00 2001 From: Hwee-Boon Yar Date: Sat, 28 Mar 2020 16:03:40 +0800 Subject: [PATCH] Make token balance displayed be always 4 decimal places, except for send confirmation and transaction details screen and for fiat to be 2 decimal places. Rounding down is always used. In particular, this affects: * balance in wallets list screen and token screen (with send/receive buttons) * fiat in send screen --- AlphaWallet/Accounts/ViewModels/AccountViewModel.swift | 2 +- AlphaWallet/Core/Formatters/CurrencyFormatter.swift | 1 + AlphaWallet/Foundation/StringFormatter.swift | 1 + AlphaWallet/Transactions/ViewModels/BalanceTokenViewModel.swift | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/AlphaWallet/Accounts/ViewModels/AccountViewModel.swift b/AlphaWallet/Accounts/ViewModels/AccountViewModel.swift index 1e798d867..0c551af24 100644 --- a/AlphaWallet/Accounts/ViewModels/AccountViewModel.swift +++ b/AlphaWallet/Accounts/ViewModels/AccountViewModel.swift @@ -22,7 +22,7 @@ struct AccountViewModel { return wallet.type == .watch(wallet.address) } var balance: String { - let amount = walletBalance?.amountFull ?? "--" + let amount = walletBalance?.amountShort ?? "--" return "\(amount) \(server.symbol)" } var address: AlphaWallet.Address { diff --git a/AlphaWallet/Core/Formatters/CurrencyFormatter.swift b/AlphaWallet/Core/Formatters/CurrencyFormatter.swift index d291cbf10..634227b2d 100644 --- a/AlphaWallet/Core/Formatters/CurrencyFormatter.swift +++ b/AlphaWallet/Core/Formatters/CurrencyFormatter.swift @@ -7,6 +7,7 @@ class CurrencyFormatter { let formatter = NumberFormatter() formatter.minimumFractionDigits = 2 formatter.maximumFractionDigits = 2 + formatter.roundingMode = .down //TODO support multiple currency values formatter.currencyCode = Currency.USD.rawValue formatter.numberStyle = .currency diff --git a/AlphaWallet/Foundation/StringFormatter.swift b/AlphaWallet/Foundation/StringFormatter.swift index 0223d69ad..6be074a32 100644 --- a/AlphaWallet/Foundation/StringFormatter.swift +++ b/AlphaWallet/Foundation/StringFormatter.swift @@ -9,6 +9,7 @@ final class StringFormatter { formatter.currencySymbol = "" formatter.minimumFractionDigits = 2 formatter.maximumFractionDigits = 2 + formatter.roundingMode = .down formatter.numberStyle = .currencyAccounting formatter.isLenient = true return formatter diff --git a/AlphaWallet/Transactions/ViewModels/BalanceTokenViewModel.swift b/AlphaWallet/Transactions/ViewModels/BalanceTokenViewModel.swift index 19b6993b4..7921e2dd1 100644 --- a/AlphaWallet/Transactions/ViewModels/BalanceTokenViewModel.swift +++ b/AlphaWallet/Transactions/ViewModels/BalanceTokenViewModel.swift @@ -14,7 +14,7 @@ struct BalanceTokenViewModel: BalanceBaseViewModel { } var amountShort: String { - return EtherNumberFormatter.full.string(from: token.valueBigInt, decimals: token.decimals) + return EtherNumberFormatter.short.string(from: token.valueBigInt, decimals: token.decimals) } var name: String {