mirror of
https://github.com/lil-org/tokenary.git
synced 2024-12-16 16:32:32 +03:00
Refactor chains
This commit is contained in:
parent
cdd7a7e045
commit
42243da309
@ -25,6 +25,26 @@ enum EthereumChain: Int {
|
||||
}
|
||||
}
|
||||
|
||||
var symbol: String {
|
||||
switch self {
|
||||
case .main, .arbitrum, .optimism:
|
||||
return "ETH"
|
||||
case .binance:
|
||||
return "BNB"
|
||||
case .polygon:
|
||||
return "MATIC"
|
||||
}
|
||||
}
|
||||
|
||||
var hasUSDPrice: Bool {
|
||||
switch self {
|
||||
case .main, .arbitrum, .optimism:
|
||||
return true
|
||||
case .binance, .polygon:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
var nodeURLString: String {
|
||||
switch self {
|
||||
case .main: return "https://eth-mainnet.alchemyapi.io/v2/" + Secrets.alchemy
|
||||
|
@ -32,38 +32,23 @@ struct Transaction {
|
||||
}
|
||||
|
||||
func description(chain: EthereumChain, ethPrice: Double?) -> String {
|
||||
let symbol: String
|
||||
let showUSDPrice: Bool
|
||||
|
||||
switch chain {
|
||||
case .main, .arbitrum, .optimism:
|
||||
symbol = "ETH"
|
||||
showUSDPrice = true
|
||||
case .polygon:
|
||||
symbol = "MATIC"
|
||||
showUSDPrice = false
|
||||
case .binance:
|
||||
symbol = "BNB"
|
||||
showUSDPrice = false
|
||||
}
|
||||
|
||||
let fee: String
|
||||
if let gasPrice = gasPrice,
|
||||
let gas = gas,
|
||||
let a = try? EthNumber(hex: gasPrice).value().toNormalizedDecimal(power: 18),
|
||||
let b = try? EthNumber(hex: gas).value().toDecimal() {
|
||||
let c = NSDecimalNumber(decimal: a).multiplying(by: NSDecimalNumber(decimal: b))
|
||||
let costString = showUSDPrice ? cost(value: c, price: ethPrice) : ""
|
||||
fee = c.stringValue.prefix(7) + " \(symbol)" + costString
|
||||
let costString = chain.hasUSDPrice ? cost(value: c, price: ethPrice) : ""
|
||||
fee = c.stringValue.prefix(7) + " \(chain.symbol)" + costString
|
||||
} else {
|
||||
fee = "Calculating…"
|
||||
}
|
||||
var result = [String]()
|
||||
if let decimal = try? weiAmount.value().toNormalizedDecimal(power: 18) {
|
||||
let decimalNumber = NSDecimalNumber(decimal: decimal)
|
||||
let costString = showUSDPrice ? cost(value: decimalNumber, price: ethPrice) : ""
|
||||
let costString = chain.hasUSDPrice ? cost(value: decimalNumber, price: ethPrice) : ""
|
||||
if let value = ethString(decimalNumber: decimalNumber) {
|
||||
result.append("\(value) \(symbol)" + costString)
|
||||
result.append("\(value) \(chain.symbol)" + costString)
|
||||
}
|
||||
}
|
||||
result.append("Fee: " + fee)
|
||||
|
Loading…
Reference in New Issue
Block a user