Consolidating operations into using EtherFormatter

pull/2/head
Michael Scoff 7 years ago
parent 7f7cbd4ccc
commit 7d2d2ce169
  1. 2
      Trust/Core/Initializers/MirgrationInitializer.swift
  2. 12
      Trust/EtherClient/TrustClient/Models/LocalizedOperation.swift
  3. 8
      Trust/Transactions/Types/LocalizedOperationObject.swift
  4. 14
      Trust/Transactions/ViewModels/TransactionCellViewModel.swift
  5. 9
      Trust/Transactions/ViewModels/TransactionViewModel.swift

@ -11,7 +11,7 @@ class MigrationInitializer {
func perform() {
let config = Realm.Configuration(
schemaVersion: 16,
schemaVersion: 17,
migrationBlock: { _, _ in }
)
Realm.Configuration.defaultConfiguration = config

@ -10,4 +10,16 @@ struct LocalizedOperation: Decodable {
let type: OperationType
let value: String
let symbol: String?
let decimals: String?
enum CodingKeys: String, CodingKey {
case title
case from
case to
case contract
case type
case value = "new_value"
case symbol
case decimals
}
}

@ -11,6 +11,7 @@ class LocalizedOperationObject: Object {
@objc dynamic var type: String = ""
@objc dynamic var value: String = ""
@objc dynamic var symbol: String? = .none
@objc dynamic var decimals: String? = .none
convenience init(
title: String,
@ -19,7 +20,8 @@ class LocalizedOperationObject: Object {
contract: String?,
type: String,
value: String,
symbol: String?
symbol: String?,
decimals: String?
) {
self.init()
self.title = title
@ -29,6 +31,7 @@ class LocalizedOperationObject: Object {
self.type = type
self.value = value
self.symbol = symbol
self.decimals = decimals
}
}
@ -43,7 +46,8 @@ extension LocalizedOperationObject {
contract: operation.contract,
type: operation.type.rawValue,
value: operation.value,
symbol: operation.symbol
symbol: operation.symbol,
decimals: operation.decimals
)
}
}

@ -8,7 +8,7 @@ struct TransactionCellViewModel {
let transaction: Transaction
let chainState: ChainState
let formatter = EtherNumberFormatter.short
let shortFormatter = EtherNumberFormatter.short
init(
transaction: Transaction,
@ -36,10 +36,6 @@ struct TransactionCellViewModel {
return transaction.operation?.title
}
private var operationValue: String? {
return transaction.operation?.value
}
var title: String {
if let operationTitle = operationTitle { return operationTitle }
switch state {
@ -74,11 +70,13 @@ struct TransactionCellViewModel {
var amount: String {
let value: String = {
if let operationValue = operationValue {
return operationValue
if let operation = transaction.operation {
return shortFormatter.string(
from: shortFormatter.number(from: operation.value, decimals: Int(operation.decimals ?? "0") ?? 0) ?? BigInt()
)
}
let number = BigInt(transaction.value) ?? BigInt()
return formatter.string(from: number)
return shortFormatter.string(from: number)
}()
guard value != "0" else { return value }
switch transaction.direction {

@ -44,8 +44,13 @@ struct TransactionViewModel {
}
var value: TransactionValue {
if let amount = transaction.operation?.value, let symbol = transaction.operation?.symbol {
return TransactionValue(amount: amount, symbol: symbol)
if let operation = transaction.operation, let symbol = operation.symbol {
return TransactionValue(
amount: shortFormatter.string(
from: shortFormatter.number(from: operation.value, decimals: Int(operation.decimals ?? "0") ?? 0) ?? BigInt()
),
symbol: symbol
)
}
return TransactionValue(
amount: fullFormatter.string(from: BigInt(transaction.value) ?? BigInt()),

Loading…
Cancel
Save