An advanced Ethereum/EVM mobile wallet
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
alpha-wallet-ios/Trust/Models/Balance.swift

57 lines
1.1 KiB

// Copyright SIX DAY LLC. All rights reserved.
7 years ago
import Foundation
protocol BalanceProtocol {
var amount: String { get }
}
struct TokenBalance: BalanceProtocol {
let token: ExchangeToken
let data: String
init(token: ExchangeToken, data: String) {
self.token = token
self.data = data
}
var amount: String {
return TokensFormatter.from(token: token, amount: data) ?? ""
}
}
struct Balance: BalanceProtocol {
7 years ago
let value: BInt
7 years ago
init(value: BInt) {
self.value = value
}
var isZero: Bool {
return value.isZero()
}
7 years ago
var wei: String {
return EthereumConverter.from(value: value, to: .wei, minimumFractionDigits: 2)
}
7 years ago
var amount: String {
return EthereumConverter.from(value: value, to: .ether, minimumFractionDigits: 4)
}
}
extension String {
var drop0x: String {
if self.count > 2 && self.substring(with: 0..<2) == "0x" {
return String(self.dropFirst(2))
}
return self
7 years ago
}
var add0x: String {
return "0x" + self
}
7 years ago
}