diff --git a/Shared/Models/AccountSelectionConfiguration.swift b/Shared/Models/AccountSelectionConfiguration.swift index b49e131a..9dc2c9f0 100644 --- a/Shared/Models/AccountSelectionConfiguration.swift +++ b/Shared/Models/AccountSelectionConfiguration.swift @@ -7,5 +7,6 @@ struct AccountSelectionConfiguration { let peer: PeerMeta? let coinType: CoinType? var selectedAccounts: Set + let initiallyConnectedProviders: Set let completion: ((EthereumChain?, SpecificWalletAccount?) -> Void) } diff --git a/Shared/Models/DappRequestAction.swift b/Shared/Models/DappRequestAction.swift index 7eb9586c..da2d4203 100644 --- a/Shared/Models/DappRequestAction.swift +++ b/Shared/Models/DappRequestAction.swift @@ -14,6 +14,7 @@ enum DappRequestAction { struct SelectAccountAction { let provider: Web3Provider + let initiallyConnectedProviders: Set let preselectedAccounts: [SpecificWalletAccount] let completion: (EthereumChain?, SpecificWalletAccount?) -> Void } diff --git a/Shared/Services/DappRequestProcessor.swift b/Shared/Services/DappRequestProcessor.swift index 59aa7ee3..9fd73e38 100644 --- a/Shared/Services/DappRequestProcessor.swift +++ b/Shared/Services/DappRequestProcessor.swift @@ -36,8 +36,10 @@ struct DappRequestProcessor { guard let coin = CoinType.correspondingToWeb3Provider(configuration.provider) else { return nil } return walletsManager.getSpecificAccount(coin: coin, address: configuration.address) } - - let action = SelectAccountAction(provider: .unknown, preselectedAccounts: preselectedAccounts) { chain, specificWalletAccount in + let initiallyConnectedProviders = Set(body.providerConfigurations.map { $0.provider }) + let action = SelectAccountAction(provider: .unknown, + initiallyConnectedProviders: initiallyConnectedProviders, + preselectedAccounts: preselectedAccounts) { chain, specificWalletAccount in if let chain = chain, let specificWalletAccount = specificWalletAccount { let account = specificWalletAccount.account switch account.coin { @@ -70,7 +72,7 @@ struct DappRequestProcessor { switch body.method { case .signIn: let suggestedAccounts = walletsManager.suggestedAccounts(coin: .near) - let action = SelectAccountAction(provider: .near, preselectedAccounts: suggestedAccounts) { _, specificWalletAccount in + let action = SelectAccountAction(provider: .near, initiallyConnectedProviders: Set(), preselectedAccounts: suggestedAccounts) { _, specificWalletAccount in if let specificWalletAccount = specificWalletAccount, specificWalletAccount.account.coin == .near { let responseBody = ResponseToExtension.Near(account: specificWalletAccount.account.address) respond(to: request, body: .near(responseBody), completion: completion) @@ -122,7 +124,7 @@ struct DappRequestProcessor { switch body.method { case .connect: let suggestedAccounts = walletsManager.suggestedAccounts(coin: .solana) - let action = SelectAccountAction(provider: .solana, preselectedAccounts: suggestedAccounts) { _, specificWalletAccount in + let action = SelectAccountAction(provider: .solana, initiallyConnectedProviders: Set(), preselectedAccounts: suggestedAccounts) { _, specificWalletAccount in if let specificWalletAccount = specificWalletAccount, specificWalletAccount.account.coin == .solana { let responseBody = ResponseToExtension.Solana(publicKey: specificWalletAccount.account.address) respond(to: request, body: .solana(responseBody), completion: completion) @@ -203,7 +205,7 @@ struct DappRequestProcessor { switch ethereumRequest.method { case .requestAccounts: let suggestedAccounts = walletsManager.suggestedAccounts(coin: .ethereum) - let action = SelectAccountAction(provider: .ethereum, preselectedAccounts: suggestedAccounts) { chain, specificWalletAccount in + let action = SelectAccountAction(provider: .ethereum, initiallyConnectedProviders: Set(), preselectedAccounts: suggestedAccounts) { chain, specificWalletAccount in if let chain = chain, let specificWalletAccount = specificWalletAccount, specificWalletAccount.account.coin == .ethereum { let responseBody = ResponseToExtension.Ethereum(results: [specificWalletAccount.account.address], chainId: chain.hexStringId, rpcURL: chain.nodeURLString) respond(to: request, body: .ethereum(responseBody), completion: completion) diff --git a/Tokenary macOS/Agent.swift b/Tokenary macOS/Agent.swift index ecedebf9..27573dcf 100644 --- a/Tokenary macOS/Agent.swift +++ b/Tokenary macOS/Agent.swift @@ -79,7 +79,11 @@ class Agent: NSObject { let accountsList = instantiate(AccountsListViewController.self) if case let .wcSession(session) = request, let completion = onSelectedWallet(session: session) { - accountsList.accountSelectionConfiguration = AccountSelectionConfiguration(peer: nil, coinType: .ethereum, selectedAccounts: Set(), completion: completion) + accountsList.accountSelectionConfiguration = AccountSelectionConfiguration(peer: nil, + coinType: .ethereum, + selectedAccounts: Set(), + initiallyConnectedProviders: Set(), + completion: completion) } let windowController = Window.showNew(closeOthers: accountsList.accountSelectionConfiguration == nil) @@ -322,6 +326,7 @@ class Agent: NSObject { accountsList.accountSelectionConfiguration = AccountSelectionConfiguration(peer: safariRequest.peerMeta, coinType: coinType, selectedAccounts: Set(accountAction.preselectedAccounts), + initiallyConnectedProviders: accountAction.initiallyConnectedProviders, completion: accountAction.completion) windowController.contentViewController = accountsList case .approveMessage(let action):