Proper handling confirmations

pull/2/head
Michael Scoff 7 years ago
parent e7e29ce095
commit d1a056187e
  1. 6
      Trust/EtherClient/ChainState.swift
  2. 6
      Trust/Transactions/ViewModels/TransactionCellViewModel.swift
  3. 6
      Trust/Transactions/ViewModels/TransactionViewModel.swift

@ -56,4 +56,10 @@ class ChainState {
} }
} }
} }
func confirmations(fromBlock: Int) -> Int? {
guard latestBlock != 0 else { return nil }
return max(0, latestBlock - fromBlock)
}
} }

@ -18,15 +18,15 @@ struct TransactionCellViewModel {
self.chainState = chainState self.chainState = chainState
} }
var confirmations: Int { var confirmations: Int? {
return max(chainState.latestBlock - Int(transaction.blockNumber), 0) return chainState.confirmations(fromBlock: transaction.blockNumber)
} }
var state: TransactionState { var state: TransactionState {
if transaction.isError { if transaction.isError {
return .error return .error
} }
if confirmations <= 0 && chainState.latestBlock >= transaction.blockNumber { if confirmations == 0 {
return .pending return .pending
} }
return .completed return .completed

@ -83,8 +83,10 @@ struct TransactionViewModel {
} }
var confirmation: String { var confirmation: String {
let confirmation = chainState.latestBlock - Int(transaction.blockNumber) guard let confirmation = chainState.confirmations(fromBlock: transaction.blockNumber) else {
return String(max(0, confirmation)) return "--"
}
return String(confirmation)
} }
var blockNumber: String { var blockNumber: String {

Loading…
Cancel
Save