|
|
|
@ -12,16 +12,16 @@ enum TransactionConfirmationViewModel { |
|
|
|
|
|
|
|
|
|
init(configurator: TransactionConfigurator, configuration: TransactionConfirmationConfiguration) { |
|
|
|
|
switch configuration { |
|
|
|
|
case .tokenScriptTransaction(_, let contract, _): |
|
|
|
|
self = .tokenScriptTransaction(.init(address: contract)) |
|
|
|
|
case .dappTransaction: |
|
|
|
|
self = .dappTransaction(.init(configurator: configurator)) |
|
|
|
|
case .tokenScriptTransaction(_, let contract, _, let ethPrice): |
|
|
|
|
self = .tokenScriptTransaction(.init(address: contract, configurator: configurator, ethPrice: ethPrice)) |
|
|
|
|
case .dappTransaction(_, _, let ethPrice): |
|
|
|
|
self = .dappTransaction(.init(configurator: configurator, ethPrice: ethPrice)) |
|
|
|
|
case .sendFungiblesTransaction(_, _, let assetDefinitionStore, let amount, let ethPrice): |
|
|
|
|
let resolver = RecipientResolver(address: configurator.transaction.recipient) |
|
|
|
|
self = .sendFungiblesTransaction(.init(configurator: configurator, assetDefinitionStore: assetDefinitionStore, recipientResolver: resolver, amount: amount, ethPrice: ethPrice)) |
|
|
|
|
case .sendNftTransaction: |
|
|
|
|
case .sendNftTransaction(_, _, let ethPrice): |
|
|
|
|
let resolver = RecipientResolver(address: configurator.transaction.recipient) |
|
|
|
|
self = .sendNftTransaction(.init(configurator: configurator, recipientResolver: resolver)) |
|
|
|
|
self = .sendNftTransaction(.init(configurator: configurator, recipientResolver: resolver, ethPrice: ethPrice)) |
|
|
|
|
case .claimPaidErc875MagicLink(_, _, let price, let ethPrice, let numberOfTokens): |
|
|
|
|
self = .claimPaidErc875MagicLink(.init(configurator: configurator, price: price, ethPrice: ethPrice, numberOfTokens: numberOfTokens)) |
|
|
|
|
} |
|
|
|
@ -75,6 +75,19 @@ enum UpdateBalanceValue { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
extension TransactionConfirmationViewModel { |
|
|
|
|
private static func gasFeeString(withConfigurator configurator: TransactionConfigurator, cryptoToDollarRate: Double?) -> String { |
|
|
|
|
let fee = configurator.currentConfiguration.gasPrice * configurator.currentConfiguration.gasLimit |
|
|
|
|
let symbol = configurator.session.server.symbol |
|
|
|
|
let feeString = EtherNumberFormatter.short.string(from: fee) |
|
|
|
|
let cryptoToDollarSymbol = Constants.Currency.usd |
|
|
|
|
if let cryptoToDollarRate = cryptoToDollarRate { |
|
|
|
|
let cryptoToDollarValue = StringFormatter().currency(with: Double(fee) * cryptoToDollarRate / Double(EthereumUnit.ether.rawValue), and: cryptoToDollarSymbol) |
|
|
|
|
return "< ~\(feeString) \(symbol) (\(cryptoToDollarValue) \(cryptoToDollarSymbol))" |
|
|
|
|
} else { |
|
|
|
|
return "< ~\(feeString) \(symbol)" |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class SendFungiblesTransactionViewModel: SectionProtocol { |
|
|
|
|
enum Section: Int, CaseIterable { |
|
|
|
|
case balance |
|
|
|
@ -101,9 +114,6 @@ extension TransactionConfirmationViewModel { |
|
|
|
|
private var newBalance: String? |
|
|
|
|
private let configurator: TransactionConfigurator |
|
|
|
|
private let assetDefinitionStore: AssetDefinitionStore |
|
|
|
|
private var defaultTitle: String { |
|
|
|
|
R.string.localizable.tokenTransactionConfirmationDefault() |
|
|
|
|
} |
|
|
|
|
private var configurationTitle: String { |
|
|
|
|
configurator.selectedConfigurationType.title |
|
|
|
|
} |
|
|
|
@ -169,6 +179,18 @@ extension TransactionConfirmationViewModel { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var gasFee: String { |
|
|
|
|
let fee: BigInt = configurator.currentConfiguration.gasPrice * configurator.currentConfiguration.gasLimit |
|
|
|
|
let feeString = EtherNumberFormatter.short.string(from: fee) |
|
|
|
|
let cryptoToDollarSymbol = Constants.Currency.usd |
|
|
|
|
if let cryptoToDollarRate = cryptoToDollarRate { |
|
|
|
|
let cryptoToDollarValue = StringFormatter().currency(with: Double(fee) * cryptoToDollarRate / Double(EthereumUnit.ether.rawValue), and: cryptoToDollarSymbol) |
|
|
|
|
return "< ~\(feeString) \(session.server.symbol) (\(cryptoToDollarValue) \(cryptoToDollarSymbol))" |
|
|
|
|
} else { |
|
|
|
|
return "< ~\(feeString) \(session.server.symbol)" |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func isSubviewsHidden(section: Int, row: Int) -> Bool { |
|
|
|
|
let isOpened = openedSections.contains(section) |
|
|
|
|
|
|
|
|
@ -195,14 +217,14 @@ extension TransactionConfirmationViewModel { |
|
|
|
|
section: section, |
|
|
|
|
shouldHideChevron: sections[section] != .recipient |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
let placeholder = sections[section].title |
|
|
|
|
switch sections[section] { |
|
|
|
|
case .balance: |
|
|
|
|
let title = R.string.localizable.tokenTransactionConfirmationDefault() |
|
|
|
|
return .init(title: balance ?? title, placeholder: placeholder, details: newBalance, configuration: configuration) |
|
|
|
|
case .gas: |
|
|
|
|
return .init(title: configurationTitle, placeholder: placeholder, configuration: configuration) |
|
|
|
|
let gasFee = gasFeeString(withConfigurator: configurator, cryptoToDollarRate: cryptoToDollarRate) |
|
|
|
|
return .init(title: configurationTitle, placeholder: placeholder, details: gasFee, configuration: configuration) |
|
|
|
|
case .amount: |
|
|
|
|
return .init(title: formattedAmountValue, placeholder: placeholder, configuration: configuration) |
|
|
|
|
case .recipient: |
|
|
|
@ -223,21 +245,21 @@ extension TransactionConfirmationViewModel { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
private let configurator: TransactionConfigurator |
|
|
|
|
private var defaultTitle: String { |
|
|
|
|
return R.string.localizable.tokenTransactionConfirmationDefault() |
|
|
|
|
} |
|
|
|
|
private var configurationTitle: String { |
|
|
|
|
return configurator.selectedConfigurationType.title |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var cryptoToDollarRate: Double? |
|
|
|
|
let ethPrice: Subscribable<Double> |
|
|
|
|
var openedSections = Set<Int>() |
|
|
|
|
|
|
|
|
|
var sections: [Section] { |
|
|
|
|
return Section.allCases |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
init(configurator: TransactionConfigurator) { |
|
|
|
|
init(configurator: TransactionConfigurator, ethPrice: Subscribable<Double>) { |
|
|
|
|
self.configurator = configurator |
|
|
|
|
self.ethPrice = ethPrice |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func isSubviewHidden(section: Int, row: Int) -> Bool { |
|
|
|
@ -258,7 +280,8 @@ extension TransactionConfirmationViewModel { |
|
|
|
|
let placeholder = sections[section].title |
|
|
|
|
switch sections[section] { |
|
|
|
|
case .gas: |
|
|
|
|
return .init(title: configurationTitle, placeholder: placeholder, configuration: configuration) |
|
|
|
|
let gasFee = gasFeeString(withConfigurator: configurator, cryptoToDollarRate: cryptoToDollarRate) |
|
|
|
|
return .init(title: configurationTitle, placeholder: placeholder, details: gasFee, configuration: configuration) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -279,17 +302,22 @@ extension TransactionConfirmationViewModel { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private let address: AlphaWallet.Address |
|
|
|
|
private var defaultTitle: String { |
|
|
|
|
return R.string.localizable.tokenTransactionConfirmationDefault() |
|
|
|
|
private let configurator: TransactionConfigurator |
|
|
|
|
private var configurationTitle: String { |
|
|
|
|
configurator.selectedConfigurationType.title |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var cryptoToDollarRate: Double? |
|
|
|
|
let ethPrice: Subscribable<Double> |
|
|
|
|
var openedSections = Set<Int>() |
|
|
|
|
var sections: [Section] { |
|
|
|
|
return Section.allCases |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
init(address: AlphaWallet.Address) { |
|
|
|
|
init(address: AlphaWallet.Address, configurator: TransactionConfigurator, ethPrice: Subscribable<Double>) { |
|
|
|
|
self.address = address |
|
|
|
|
self.configurator = configurator |
|
|
|
|
self.ethPrice = ethPrice |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func headerViewModel(section: Int) -> TransactionConfirmationHeaderViewModel { |
|
|
|
@ -298,7 +326,8 @@ extension TransactionConfirmationViewModel { |
|
|
|
|
let placeholder = sections[section].title |
|
|
|
|
switch sections[section] { |
|
|
|
|
case .gas: |
|
|
|
|
return .init(title: defaultTitle, placeholder: placeholder, configuration: configuration) |
|
|
|
|
let gasFee = gasFeeString(withConfigurator: configurator, cryptoToDollarRate: cryptoToDollarRate) |
|
|
|
|
return .init(title: configurationTitle, placeholder: placeholder, details: gasFee, configuration: configuration) |
|
|
|
|
case .contract: |
|
|
|
|
return .init(title: address.truncateMiddle, placeholder: placeholder, configuration: configuration) |
|
|
|
|
} |
|
|
|
@ -331,23 +360,22 @@ extension TransactionConfirmationViewModel { |
|
|
|
|
configurator.selectedConfigurationType.title |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private var defaultTitle: String { |
|
|
|
|
R.string.localizable.tokenTransactionConfirmationDefault() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var ensName: String? { recipientResolver.ensName } |
|
|
|
|
var addressString: String? { recipientResolver.address?.eip55String } |
|
|
|
|
var openedSections = Set<Int>() |
|
|
|
|
let recipientResolver: RecipientResolver |
|
|
|
|
var cryptoToDollarRate: Double? |
|
|
|
|
let ethPrice: Subscribable<Double> |
|
|
|
|
var sections: [Section] { |
|
|
|
|
return Section.allCases |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
init(configurator: TransactionConfigurator, recipientResolver: RecipientResolver) { |
|
|
|
|
init(configurator: TransactionConfigurator, recipientResolver: RecipientResolver, ethPrice: Subscribable<Double>) { |
|
|
|
|
self.configurator = configurator |
|
|
|
|
self.transferType = configurator.transaction.transferType |
|
|
|
|
self.session = configurator.session |
|
|
|
|
self.recipientResolver = recipientResolver |
|
|
|
|
self.ethPrice = ethPrice |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func isSubviewsHidden(section: Int, row: Int) -> Bool { |
|
|
|
@ -379,7 +407,8 @@ extension TransactionConfirmationViewModel { |
|
|
|
|
let placeholder = sections[section].title |
|
|
|
|
switch sections[section] { |
|
|
|
|
case .gas: |
|
|
|
|
return .init(title: configurationTitle, placeholder: placeholder, configuration: configuration) |
|
|
|
|
let gasFee = gasFeeString(withConfigurator: configurator, cryptoToDollarRate: cryptoToDollarRate) |
|
|
|
|
return .init(title: configurationTitle, placeholder: placeholder, details: gasFee, configuration: configuration) |
|
|
|
|
case .tokenId: |
|
|
|
|
//TODO be good to display the token instance's name or equivalent too |
|
|
|
|
let tokenId = configurator.transaction.tokenId.flatMap({ String($0) }) ?? "" |
|
|
|
|