|
|
|
@ -17,14 +17,15 @@ private class TransactionConfirmationCoordinatorBridgeToPromise { |
|
|
|
|
private let (promise, seal) = Promise<ConfirmResult>.pending() |
|
|
|
|
private var retainCycle: TransactionConfirmationCoordinatorBridgeToPromise? |
|
|
|
|
private weak var confirmationCoordinator: TransactionConfirmationCoordinator? |
|
|
|
|
private var didSendTransactionClosure: ((SentTransaction) -> Void)? |
|
|
|
|
|
|
|
|
|
init(_ navigationController: UINavigationController, session: WalletSession, coordinator: Coordinator & CanOpenURL, analyticsCoordinator: AnalyticsCoordinator) { |
|
|
|
|
init(_ navigationController: UINavigationController, session: WalletSession, coordinator: Coordinator & CanOpenURL, analyticsCoordinator: AnalyticsCoordinator, didSendTransactionClosure: @escaping (SentTransaction) -> Void) { |
|
|
|
|
self.navigationController = navigationController |
|
|
|
|
self.session = session |
|
|
|
|
self.coordinator = coordinator |
|
|
|
|
self.analyticsCoordinator = analyticsCoordinator |
|
|
|
|
retainCycle = self |
|
|
|
|
|
|
|
|
|
self.didSendTransactionClosure = didSendTransactionClosure |
|
|
|
|
promise.ensure { |
|
|
|
|
//NOTE: Ensure we break the retain cycle, and remove coordinator from list |
|
|
|
|
self.retainCycle = nil |
|
|
|
@ -35,7 +36,7 @@ private class TransactionConfirmationCoordinatorBridgeToPromise { |
|
|
|
|
}.cauterize() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func promise(account: AlphaWallet.Address, transaction: UnconfirmedTransaction, configuration: TransactionConfirmationConfiguration, source: Analytics.TransactionConfirmationSource) -> Promise<ConfirmResult> { |
|
|
|
|
func promise(transaction: UnconfirmedTransaction, configuration: TransactionConfirmationConfiguration, source: Analytics.TransactionConfirmationSource) -> Promise<ConfirmResult> { |
|
|
|
|
let confirmationCoordinator = TransactionConfirmationCoordinator(presentingViewController: navigationController, session: session, transaction: transaction, configuration: configuration, analyticsCoordinator: analyticsCoordinator) |
|
|
|
|
|
|
|
|
|
confirmationCoordinator.delegate = self |
|
|
|
@ -48,15 +49,14 @@ private class TransactionConfirmationCoordinatorBridgeToPromise { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
extension TransactionConfirmationCoordinatorBridgeToPromise: TransactionConfirmationCoordinatorDelegate { |
|
|
|
|
func didSendTransaction(_ transaction: SentTransaction, inCoordinator coordinator: TransactionConfirmationCoordinator) { |
|
|
|
|
didSendTransactionClosure?(transaction) |
|
|
|
|
didSendTransactionClosure = .none |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func coordinator(_ coordinator: TransactionConfirmationCoordinator, didCompleteTransaction result: TransactionConfirmationResult) { |
|
|
|
|
func didFinish(_ result: ConfirmResult, in coordinator: TransactionConfirmationCoordinator) { |
|
|
|
|
coordinator.close().done { _ in |
|
|
|
|
switch result { |
|
|
|
|
case .confirmationResult(let value): |
|
|
|
|
self.seal.fulfill(value) |
|
|
|
|
case .noData: |
|
|
|
|
self.seal.reject(DAppError.cancelled) |
|
|
|
|
} |
|
|
|
|
self.seal.fulfill(result) |
|
|
|
|
}.cauterize() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -107,10 +107,10 @@ extension UIViewController { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
extension TransactionConfirmationCoordinator { |
|
|
|
|
|
|
|
|
|
//session contains account already |
|
|
|
|
static func promise(_ navigationController: UINavigationController, session: WalletSession, coordinator: Coordinator & CanOpenURL, account: AlphaWallet.Address, transaction: UnconfirmedTransaction, configuration: TransactionConfirmationConfiguration, analyticsCoordinator: AnalyticsCoordinator, source: Analytics.TransactionConfirmationSource) -> Promise<ConfirmResult> { |
|
|
|
|
let bridge = TransactionConfirmationCoordinatorBridgeToPromise(navigationController, session: session, coordinator: coordinator, analyticsCoordinator: analyticsCoordinator) |
|
|
|
|
return bridge.promise(account: account, transaction: transaction, configuration: configuration, source: source) |
|
|
|
|
// NOTE: Hack usage of closure `didSendTransactionClosure`, its not good to do like that, |
|
|
|
|
// made to easily get called `didSendTransaction` method as promise can't be called twice |
|
|
|
|
static func promise(_ navigationController: UINavigationController, session: WalletSession, coordinator: Coordinator & CanOpenURL, transaction: UnconfirmedTransaction, configuration: TransactionConfirmationConfiguration, analyticsCoordinator: AnalyticsCoordinator, source: Analytics.TransactionConfirmationSource, didSendTransactionClosure: @escaping (SentTransaction) -> Void) -> Promise<ConfirmResult> { |
|
|
|
|
let bridge = TransactionConfirmationCoordinatorBridgeToPromise(navigationController, session: session, coordinator: coordinator, analyticsCoordinator: analyticsCoordinator, didSendTransactionClosure: didSendTransactionClosure) |
|
|
|
|
return bridge.promise(transaction: transaction, configuration: configuration, source: source) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|