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
}
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

@ -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 {

Loading…
Cancel
Save