Split transaction info into separate cells

This commit is contained in:
Ivan Grachyov 2021-12-13 18:58:28 +03:00
parent f947f3247c
commit 572f8a8600
2 changed files with 26 additions and 8 deletions

View File

@ -32,6 +32,17 @@ struct Transaction {
}
func description(chain: EthereumChain, ethPrice: Double?) -> String {
var result = [String]()
if let value = valueWithSymbol(chain: chain, ethPrice: ethPrice, withLabel: false) {
result.append(value)
}
result.append(feeWithSymbol(chain: chain, ethPrice: ethPrice))
result.append("Data: " + data)
return result.joined(separator: "\n\n")
}
func feeWithSymbol(chain: EthereumChain, ethPrice: Double?) -> String {
let fee: String
if let gasPrice = gasPrice,
let gas = gas,
@ -43,18 +54,19 @@ struct Transaction {
} else {
fee = "Calculating…"
}
var result = [String]()
return "Fee: " + fee
}
func valueWithSymbol(chain: EthereumChain, ethPrice: Double?, withLabel: Bool) -> String? {
if let decimal = try? weiAmount.value().toNormalizedDecimal(power: 18) {
let decimalNumber = NSDecimalNumber(decimal: decimal)
let costString = chain.hasUSDPrice ? cost(value: decimalNumber, price: ethPrice) : ""
if let value = ethString(decimalNumber: decimalNumber) {
result.append("\(value) \(chain.symbol)" + costString)
let valueString = "\(value) \(chain.symbol)" + costString
return withLabel ? "Value: " + valueString : valueString
}
}
result.append("Fee: " + fee)
result.append("Data: " + data)
return result.joined(separator: "\n\n")
return nil
}
private func cost(value: NSDecimalNumber, price: Double?) -> String {

View File

@ -63,9 +63,15 @@ class ApproveTransactionViewController: UIViewController {
private func updateInterface() {
cellModels = [
.textWithImage(text: peerMeta?.name ?? Strings.unknownWebsite, imageURL: peerMeta?.iconURLString, image: nil),
.textWithImage(text: address.trimmedAddress, imageURL: nil, image: Blockies(seed: address.lowercased()).createImage()),
.text(transaction.description(chain: chain, ethPrice: priceService.currentPrice))
.textWithImage(text: address.trimmedAddress, imageURL: nil, image: Blockies(seed: address.lowercased()).createImage())
]
if let value = transaction.valueWithSymbol(chain: chain, ethPrice: priceService.currentPrice, withLabel: true) {
cellModels.append(.text(value))
}
cellModels.append(.text(transaction.feeWithSymbol(chain: chain, ethPrice: priceService.currentPrice)))
// TODO: display tx data somehow
tableView.reloadData()
okButton.isEnabled = transaction.hasFee