diff --git a/Trust/EtherClient/ChainState.swift b/Trust/EtherClient/ChainState.swift index c95e62ebb..2f2af1966 100644 --- a/Trust/EtherClient/ChainState.swift +++ b/Trust/EtherClient/ChainState.swift @@ -56,4 +56,10 @@ class ChainState { } } } + + func confirmations(fromBlock: Int) -> Int? { + guard latestBlock != 0 else { return nil } + return max(0, latestBlock - fromBlock) + } + } diff --git a/Trust/Transactions/ViewModels/TransactionCellViewModel.swift b/Trust/Transactions/ViewModels/TransactionCellViewModel.swift index 9ab88d9ce..a3bc154e4 100644 --- a/Trust/Transactions/ViewModels/TransactionCellViewModel.swift +++ b/Trust/Transactions/ViewModels/TransactionCellViewModel.swift @@ -18,15 +18,15 @@ struct TransactionCellViewModel { self.chainState = chainState } - var confirmations: Int { - return max(chainState.latestBlock - Int(transaction.blockNumber), 0) + var confirmations: Int? { + return chainState.confirmations(fromBlock: transaction.blockNumber) } var state: TransactionState { if transaction.isError { return .error } - if confirmations <= 0 && chainState.latestBlock >= transaction.blockNumber { + if confirmations == 0 { return .pending } return .completed diff --git a/Trust/Transactions/ViewModels/TransactionViewModel.swift b/Trust/Transactions/ViewModels/TransactionViewModel.swift index be284be42..8e6c0cfbd 100644 --- a/Trust/Transactions/ViewModels/TransactionViewModel.swift +++ b/Trust/Transactions/ViewModels/TransactionViewModel.swift @@ -83,8 +83,10 @@ struct TransactionViewModel { } var confirmation: String { - let confirmation = chainState.latestBlock - Int(transaction.blockNumber) - return String(max(0, confirmation)) + guard let confirmation = chainState.confirmations(fromBlock: transaction.blockNumber) else { + return "--" + } + return String(confirmation) } var blockNumber: String {