diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2021-10-04 12:36:49 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2021-10-05 10:01:55 +0200 |
| commit | 05b4ddad70a07772ff47742287532d0f4349926e (patch) | |
| tree | 8798f42199ad229767551433bc0b094e4c5e25b0 | |
| parent | c42ea0b0c99dfde5cb7980cc3ce13539d6f87306 (diff) | |
| download | mullvadvpn-05b4ddad70a07772ff47742287532d0f4349926e.tar.xz mullvadvpn-05b4ddad70a07772ff47742287532d0f4349926e.zip | |
Account: use Promise.delay()
| -rw-r--r-- | ios/MullvadVPN/AccountViewController.swift | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/ios/MullvadVPN/AccountViewController.swift b/ios/MullvadVPN/AccountViewController.swift index 7b76042bd4..923e004dc7 100644 --- a/ios/MullvadVPN/AccountViewController.swift +++ b/ios/MullvadVPN/AccountViewController.swift @@ -22,7 +22,7 @@ class AccountViewController: UIViewController, AppStorePaymentObserver, AccountO return contentView }() - private var copyToPasteboardWork: DispatchWorkItem? + private var copyToPasteboardCancellationToken: PromiseCancellationToken? private var pendingPayment: SKPayment? private let alertPresenter = AlertPresenter() @@ -406,14 +406,14 @@ class AccountViewController: UIViewController, AppStorePaymentObserver, AccountO comment: "Message, temporarily displayed in place account token, after copying the account token to pasteboard on tap." ) - let dispatchWork = DispatchWorkItem { [weak self] in - self?.contentView.accountTokenRowView.value = Account.shared.formattedToken - } - - DispatchQueue.main.asyncAfter(wallDeadline: .now() + .seconds(3), execute: dispatchWork) + Promise.deferred { Account.shared.formattedToken } + .delay(by: .seconds(3), timerType: .walltime, queue: .main) + .storeCancellationToken(in: ©ToPasteboardCancellationToken) + .observe { [weak self] completion in + guard let formattedToken = completion.unwrappedValue else { return } - self.copyToPasteboardWork?.cancel() - self.copyToPasteboardWork = dispatchWork + self?.contentView.accountTokenRowView.value = formattedToken + } } @objc private func doPurchase() { |
