Show gas fee in current currency (#264)

* Show gas fee in currency on details view

* Remove not used file during rebase
pull/2/head
Tao Xu 7 years ago committed by Michael Scoff
parent dd6ac71fd7
commit b9d306d0ee
  1. 4
      Trust.xcodeproj/project.pbxproj
  2. 17
      Trust/Transfer/Types/CurrencyRate+Fee.swift
  3. 14
      Trust/Transfer/ViewControllers/ConfigureTransactionViewController.swift
  4. 3
      Trust/Transfer/ViewControllers/ConfirmPaymentViewController.swift
  5. 9
      Trust/Transfer/ViewModels/ConfirmPaymentDetailsViewModel.swift

@ -314,6 +314,7 @@
77B3BF4A2019247200EEC15A /* BrowserNavigationBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B3BF492019247200EEC15A /* BrowserNavigationBar.swift */; }; 77B3BF4A2019247200EEC15A /* BrowserNavigationBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B3BF492019247200EEC15A /* BrowserNavigationBar.swift */; };
77E0E773201FAD06009B4B31 /* BrowserURLParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77E0E772201FAD05009B4B31 /* BrowserURLParser.swift */; }; 77E0E773201FAD06009B4B31 /* BrowserURLParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77E0E772201FAD05009B4B31 /* BrowserURLParser.swift */; };
77E0E777201FAD36009B4B31 /* BrowserURLParserTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77E0E776201FAD36009B4B31 /* BrowserURLParserTests.swift */; }; 77E0E777201FAD36009B4B31 /* BrowserURLParserTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77E0E776201FAD36009B4B31 /* BrowserURLParserTests.swift */; };
BB5D6A9E20232EE8000FC5AB /* CurrencyRate+Fee.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB5D6A9D20232EE8000FC5AB /* CurrencyRate+Fee.swift */; };
CCA4FE331FD3655900749AE4 /* CheckDeviceCoordinatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCA4FE321FD3655900749AE4 /* CheckDeviceCoordinatorTests.swift */; }; CCA4FE331FD3655900749AE4 /* CheckDeviceCoordinatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCA4FE321FD3655900749AE4 /* CheckDeviceCoordinatorTests.swift */; };
CCA4FE361FD4282400749AE4 /* DeviceChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCA4FE351FD4282400749AE4 /* DeviceChecker.swift */; }; CCA4FE361FD4282400749AE4 /* DeviceChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCA4FE351FD4282400749AE4 /* DeviceChecker.swift */; };
CCA4FE381FD428B300749AE4 /* JailbreakChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCA4FE371FD428B300749AE4 /* JailbreakChecker.swift */; }; CCA4FE381FD428B300749AE4 /* JailbreakChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCA4FE371FD428B300749AE4 /* JailbreakChecker.swift */; };
@ -665,6 +666,7 @@
A3B747245A27436E621E7E41 /* Pods-TrustUITests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TrustUITests.release.xcconfig"; path = "Pods/Target Support Files/Pods-TrustUITests/Pods-TrustUITests.release.xcconfig"; sourceTree = "<group>"; }; A3B747245A27436E621E7E41 /* Pods-TrustUITests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TrustUITests.release.xcconfig"; path = "Pods/Target Support Files/Pods-TrustUITests/Pods-TrustUITests.release.xcconfig"; sourceTree = "<group>"; };
A48A17FC2CC895AF2BB871D0 /* Pods_TrustTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_TrustTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; A48A17FC2CC895AF2BB871D0 /* Pods_TrustTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_TrustTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
B13A87D3BA5167741E5D0801 /* Pods-Trust.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Trust.release.xcconfig"; path = "Pods/Target Support Files/Pods-Trust/Pods-Trust.release.xcconfig"; sourceTree = "<group>"; }; B13A87D3BA5167741E5D0801 /* Pods-Trust.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Trust.release.xcconfig"; path = "Pods/Target Support Files/Pods-Trust/Pods-Trust.release.xcconfig"; sourceTree = "<group>"; };
BB5D6A9D20232EE8000FC5AB /* CurrencyRate+Fee.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CurrencyRate+Fee.swift"; sourceTree = "<group>"; };
CCA4FE321FD3655900749AE4 /* CheckDeviceCoordinatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckDeviceCoordinatorTests.swift; sourceTree = "<group>"; }; CCA4FE321FD3655900749AE4 /* CheckDeviceCoordinatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckDeviceCoordinatorTests.swift; sourceTree = "<group>"; };
CCA4FE351FD4282400749AE4 /* DeviceChecker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceChecker.swift; sourceTree = "<group>"; }; CCA4FE351FD4282400749AE4 /* DeviceChecker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceChecker.swift; sourceTree = "<group>"; };
CCA4FE371FD428B300749AE4 /* JailbreakChecker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JailbreakChecker.swift; sourceTree = "<group>"; }; CCA4FE371FD428B300749AE4 /* JailbreakChecker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JailbreakChecker.swift; sourceTree = "<group>"; };
@ -1497,6 +1499,7 @@
29BDF1A01FEE51A80023A45F /* GasLimitConfiguration.swift */, 29BDF1A01FEE51A80023A45F /* GasLimitConfiguration.swift */,
29FF6D6A2011D2AF00A3011C /* InCoordinatorError.swift */, 29FF6D6A2011D2AF00A3011C /* InCoordinatorError.swift */,
29C70C702016C7780072E454 /* SentTransaction.swift */, 29C70C702016C7780072E454 /* SentTransaction.swift */,
BB5D6A9D20232EE8000FC5AB /* CurrencyRate+Fee.swift */,
); );
path = Types; path = Types;
sourceTree = "<group>"; sourceTree = "<group>";
@ -2558,6 +2561,7 @@
294DFBA31FE0E2EA004CEB56 /* TransactionValue.swift in Sources */, 294DFBA31FE0E2EA004CEB56 /* TransactionValue.swift in Sources */,
2912CD2B1F6A833E00C6CBE3 /* TransactionsViewController.swift in Sources */, 2912CD2B1F6A833E00C6CBE3 /* TransactionsViewController.swift in Sources */,
775C00B520195BFB001B5EBC /* BrowserAction.swift in Sources */, 775C00B520195BFB001B5EBC /* BrowserAction.swift in Sources */,
BB5D6A9E20232EE8000FC5AB /* CurrencyRate+Fee.swift in Sources */,
295996161FADAFE500DB66A8 /* TransactionAction.swift in Sources */, 295996161FADAFE500DB66A8 /* TransactionAction.swift in Sources */,
299B5E291FCA8F040051361C /* GetERC20Balance.swift in Sources */, 299B5E291FCA8F040051361C /* GetERC20Balance.swift in Sources */,
77E0E773201FAD06009B4B31 /* BrowserURLParser.swift in Sources */, 77E0E773201FAD06009B4B31 /* BrowserURLParser.swift in Sources */,

@ -0,0 +1,17 @@
// Copyright SIX DAY LLC. All rights reserved.
import Foundation
import BigInt
extension CurrencyRate {
func estimate(fee: String, with symbol: String) -> String? {
guard let feeInDouble = Double(fee) else {
return nil
}
guard let price = self.rates.filter({ $0.code == symbol }).first else {
return nil
}
let formattedFee = CurrencyFormatter.formatter.string(from: NSNumber(value: price.price * feeInDouble))
return formattedFee
}
}

@ -13,6 +13,7 @@ class ConfigureTransactionViewController: FormViewController {
let configuration: TransactionConfiguration let configuration: TransactionConfiguration
let config: Config let config: Config
let transferType: TransferType let transferType: TransferType
let currencyRate: CurrencyRate?
private let fullFormatter = EtherNumberFormatter.full private let fullFormatter = EtherNumberFormatter.full
struct Values { struct Values {
@ -60,11 +61,13 @@ class ConfigureTransactionViewController: FormViewController {
init( init(
configuration: TransactionConfiguration, configuration: TransactionConfiguration,
transferType: TransferType, transferType: TransferType,
config: Config config: Config,
currencyRate: CurrencyRate?
) { ) {
self.configuration = configuration self.configuration = configuration
self.transferType = transferType self.transferType = transferType
self.config = config self.config = config
self.currencyRate = currencyRate
super.init(nibName: nil, bundle: nil) super.init(nibName: nil, bundle: nil)
@ -140,7 +143,14 @@ class ConfigureTransactionViewController: FormViewController {
} }
func recalculateTotalFee() { func recalculateTotalFee() {
totalFeeRow?.value = "\(fullFormatter.string(from: totalFee)) \(config.server.symbol)"
let fee = fullFormatter.string(from: totalFee)
var feeAndSymbol = "\(fee) \(config.server.symbol)"
if let feeInCurrency = currencyRate?.estimate(fee: fee, with: config.server.symbol) {
feeAndSymbol += " (\(feeInCurrency))"
}
totalFeeRow?.value = feeAndSymbol
totalFeeRow?.updateCell() totalFeeRow?.updateCell()
} }

@ -149,7 +149,8 @@ class ConfirmPaymentViewController: UIViewController {
let controller = ConfigureTransactionViewController( let controller = ConfigureTransactionViewController(
configuration: configurator.configuration, configuration: configurator.configuration,
transferType: configurator.transaction.transferType, transferType: configurator.transaction.transferType,
config: session.config config: session.config,
currencyRate: session.balanceCoordinator.currencyRate
) )
controller.delegate = self controller.delegate = self
self.navigationController?.pushViewController(controller, animated: true) self.navigationController?.pushViewController(controller, animated: true)

@ -71,13 +71,8 @@ struct ConfirmPaymentDetailsViewModel {
fee.description, fee.description,
config.server.symbol config.server.symbol
) )
if let feeInDouble = Double(fee), let price = currencyRate?.rates if let feeInCurrency = currencyRate?.estimate(fee: fee, with: config.server.symbol) {
.filter({ $0.code == config.server.symbol }).first { feeAndSymbol += " (\(feeInCurrency))"
feeAndSymbol += String(
format: " (~ %f %@)",
price.price * feeInDouble,
config.currency.rawValue
)
} }
let warningFee = BigInt(EthereumUnit.ether.rawValue) / BigInt(20) let warningFee = BigInt(EthereumUnit.ether.rawValue) / BigInt(20)
guard totalFee <= warningFee else { guard totalFee <= warningFee else {

Loading…
Cancel
Save