Display nonce that will be used when editing transaction settings with actionsheet for transaction confirmation

pull/2348/head
Hwee-Boon Yar 4 years ago
parent 47ffc51cec
commit 7a7a8129e4
  1. 13
      AlphaWallet/Transfer/Controllers/TransactionConfigurator.swift
  2. 4
      AlphaWallet/Transfer/Coordinators/TransactionConfirmationCoordinator.swift
  3. 4
      AlphaWallet/Transfer/Types/TransactionConfiguration.swift
  4. 12
      AlphaWallet/Transfer/ViewControllers/ConfigureTransactionViewController.swift

@ -11,6 +11,7 @@ protocol TransactionConfiguratorDelegate: class {
func configurationChanged(in configurator: TransactionConfigurator)
func gasLimitEstimateUpdated(to estimate: BigInt, in configurator: TransactionConfigurator)
func gasPriceEstimateUpdated(to estimate: BigInt, in configurator: TransactionConfigurator)
func updateNonce(to nonce: Int, in configurator: TransactionConfigurator)
}
class TransactionConfigurator {
@ -295,6 +296,18 @@ class TransactionConfigurator {
if !isGasLimitSpecifiedByTransaction {
estimateGasLimit()
}
firstly {
GetNextNonce(server: session.server, wallet: session.account.address).promise()
}.done {
var customConfig = self.configurations.custom
if let existingNonce = customConfig.nonce, existingNonce > 0 {
//no-op
} else {
customConfig.set(nonce: $0)
self.configurations.custom = customConfig
self.delegate?.updateNonce(to: $0, in: self)
}
}.cauterize()
}
func formUnsignedTransaction() -> UnsignedTransaction {

@ -205,4 +205,8 @@ extension TransactionConfirmationCoordinator: TransactionConfiguratorDelegate {
func gasPriceEstimateUpdated(to estimate: BigInt, in configurator: TransactionConfigurator) {
configureTransactionViewController?.configure(withEstimatedGasPrice: estimate, configurator: configurator)
}
func updateNonce(to nonce: Int, in configurator: TransactionConfigurator) {
configureTransactionViewController?.configure(nonce: nonce, configurator: configurator)
}
}

@ -30,6 +30,10 @@ struct TransactionConfiguration {
gasLimit = estimate
}
mutating func set(nonce: Int) {
self.nonce = nonce
}
init(transaction: UnconfirmedTransaction) {
self.init(
gasPrice: min(max(transaction.gasPrice ?? GasPriceConfiguration.defaultPrice, GasPriceConfiguration.minPrice), GasPriceConfiguration.maxPrice),

@ -105,6 +105,18 @@ class ConfigureTransactionViewController: UIViewController {
tableView.reloadData()
}
func configure(nonce: Int, configurator: TransactionConfigurator) {
var updatedViewModel = viewModel
var configuration = makeConfigureSuitableForSaving(from: updatedViewModel.configurationToEdit.configuration)
guard configuration.nonce != nonce else { return }
configuration.set(nonce: nonce)
updatedViewModel.configurationToEdit = EditedTransactionConfiguration(configuration: configuration)
updatedViewModel.configurations = configurator.configurations
viewModel = updatedViewModel
recalculateTotalFee()
tableView.reloadData()
}
@objc private func keyboardWillShow(_ notification: Notification) {
guard let info = notification.userInfo else {
return

Loading…
Cancel
Save