From 502e6cc12bbd9cc9e8cf5275cd8e0502d7931cf9 Mon Sep 17 00:00:00 2001 From: Ivan Grachev Date: Wed, 17 Aug 2022 15:58:04 +0300 Subject: [PATCH] Pass wallet id instead of TokenaryWallet on successful account selection --- Shared/Models/AccountSelectionConfiguration.swift | 2 +- Shared/Models/DappRequestAction.swift | 2 +- Shared/Services/DappRequestProcessor.swift | 6 +++--- Tokenary macOS/Agent.swift | 14 +++++++------- .../Screens/AccountsListViewController.swift | 10 +++++----- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Shared/Models/AccountSelectionConfiguration.swift b/Shared/Models/AccountSelectionConfiguration.swift index 7ab7eec8..3403a205 100644 --- a/Shared/Models/AccountSelectionConfiguration.swift +++ b/Shared/Models/AccountSelectionConfiguration.swift @@ -5,5 +5,5 @@ import WalletCore struct AccountSelectionConfiguration { let peer: PeerMeta? - let completion: ((EthereumChain?, TokenaryWallet?, Account?) -> Void) + let completion: ((EthereumChain?, String?, Account?) -> Void) } diff --git a/Shared/Models/DappRequestAction.swift b/Shared/Models/DappRequestAction.swift index 1296faba..cae05079 100644 --- a/Shared/Models/DappRequestAction.swift +++ b/Shared/Models/DappRequestAction.swift @@ -14,7 +14,7 @@ enum DappRequestAction { struct SelectAccountAction { let provider: Web3Provider - let completion: (EthereumChain?, TokenaryWallet?, Account?) -> Void + let completion: (EthereumChain?, String?, Account?) -> Void } struct SignMessageAction { diff --git a/Shared/Services/DappRequestProcessor.swift b/Shared/Services/DappRequestProcessor.swift index 3d358391..a0346b25 100644 --- a/Shared/Services/DappRequestProcessor.swift +++ b/Shared/Services/DappRequestProcessor.swift @@ -194,9 +194,9 @@ struct DappRequestProcessor { switch ethereumRequest.method { case .requestAccounts: - let action = SelectAccountAction(provider: .ethereum) { chain, wallet, account in - if let chain = chain, let address = wallet?.ethereumAddress, account?.coin == .ethereum { - let responseBody = ResponseToExtension.Ethereum(results: [address], chainId: chain.hexStringId, rpcURL: chain.nodeURLString) + let action = SelectAccountAction(provider: .ethereum) { chain, _, account in + if let chain = chain, let account = account, account.coin == .ethereum { + let responseBody = ResponseToExtension.Ethereum(results: [account.address], chainId: chain.hexStringId, rpcURL: chain.nodeURLString) respond(to: request, body: .ethereum(responseBody), completion: completion) } else { respond(to: request, error: Strings.canceled, completion: completion) diff --git a/Tokenary macOS/Agent.swift b/Tokenary macOS/Agent.swift index 2099de5b..f00d00e6 100644 --- a/Tokenary macOS/Agent.swift +++ b/Tokenary macOS/Agent.swift @@ -116,7 +116,7 @@ class Agent: NSObject { windowController.contentViewController = approveViewController } - func getWalletSelectionCompletionIfShouldSelect() -> ((EthereumChain?, TokenaryWallet?, Account?) -> Void)? { + func getWalletSelectionCompletionIfShouldSelect() -> ((EthereumChain?, String?, Account?) -> Void)? { let session = getSessionFromPasteboard() return onSelectedWallet(session: session) } @@ -215,14 +215,14 @@ class Agent: NSObject { } } - private func onSelectedWallet(session: WCSession?) -> ((EthereumChain?, TokenaryWallet?, Account?) -> Void)? { + private func onSelectedWallet(session: WCSession?) -> ((EthereumChain?, String?, Account?) -> Void)? { guard let session = session else { return nil } - return { [weak self] chain, wallet, account in - guard let chain = chain, let wallet = wallet, account?.coin == .ethereum else { + return { [weak self] chain, walletId, account in + guard let chain = chain, let walletId = walletId, account?.coin == .ethereum else { Window.closeAllAndActivateBrowser(specific: nil) return } - self?.connectWallet(session: session, chainId: chain.id, wallet: wallet) + self?.connectWallet(session: session, chainId: chain.id, walletId: walletId) } } @@ -286,12 +286,12 @@ class Agent: NSObject { } } - private func connectWallet(session: WCSession, chainId: Int, wallet: TokenaryWallet) { + private func connectWallet(session: WCSession, chainId: Int, walletId: String) { let windowController = Window.showNew(closeOthers: true) let window = windowController.window windowController.contentViewController = WaitingViewController.withReason(Strings.connecting) - walletConnect.connect(session: session, chainId: chainId, walletId: wallet.id) { [weak window] _ in + walletConnect.connect(session: session, chainId: chainId, walletId: walletId) { [weak window] _ in if window?.isVisible == true { Window.closeAllAndActivateBrowser(specific: nil) } diff --git a/Tokenary macOS/Screens/AccountsListViewController.swift b/Tokenary macOS/Screens/AccountsListViewController.swift index 5b9f7d1f..65a965bb 100644 --- a/Tokenary macOS/Screens/AccountsListViewController.swift +++ b/Tokenary macOS/Screens/AccountsListViewController.swift @@ -101,10 +101,10 @@ class AccountsListViewController: NSViewController { Alert.showSafariPrompt() } - private func callCompletion(wallet: TokenaryWallet?, account: Account?) { + private func callCompletion(walletId: String?, account: Account?) { if !didCallCompletion { didCallCompletion = true - accountSelectionConfiguration?.completion(chain, wallet, account) + accountSelectionConfiguration?.completion(chain, walletId, account) } } @@ -197,7 +197,7 @@ class AccountsListViewController: NSViewController { } @IBAction func didClickSecondaryButton(_ sender: Any) { - callCompletion(wallet: nil, account: nil) + callCompletion(walletId: nil, account: nil) // TODO: distinguish cancel and disconnect // when it was dapp's request, we should deliver response anyway // when it was extension action, no need to deliver response to inpage @@ -205,7 +205,7 @@ class AccountsListViewController: NSViewController { @IBAction func didClickPrimaryButton(_ sender: Any) { // TODO: call completion -// callCompletion(wallet: wallet, account: account) +// callCompletion(walletId: wallet, account: account) // woah. what do i do about the fact we do not have a wallet here? // maybe wallet is not necessary at all and i should remove it from here? } @@ -636,7 +636,7 @@ extension AccountsListViewController: NSMenuDelegate { extension AccountsListViewController: NSWindowDelegate { func windowWillClose(_ notification: Notification) { - callCompletion(wallet: nil, account: nil) + callCompletion(walletId: nil, account: nil) // TODO: distinguish cancel and disconnect // when it was dapp's request, we should deliver response anyway // when it was extension action, no need to deliver response to inpage