Keep initially connected providers list on switch account request

This commit is contained in:
Ivan Grachev 2022-08-19 13:15:34 +03:00
parent e4d9b2d5df
commit 815073647a
4 changed files with 15 additions and 6 deletions

View File

@ -7,5 +7,6 @@ struct AccountSelectionConfiguration {
let peer: PeerMeta?
let coinType: CoinType?
var selectedAccounts: Set<SpecificWalletAccount>
let initiallyConnectedProviders: Set<Web3Provider>
let completion: ((EthereumChain?, SpecificWalletAccount?) -> Void)
}

View File

@ -14,6 +14,7 @@ enum DappRequestAction {
struct SelectAccountAction {
let provider: Web3Provider
let initiallyConnectedProviders: Set<Web3Provider>
let preselectedAccounts: [SpecificWalletAccount]
let completion: (EthereumChain?, SpecificWalletAccount?) -> Void
}

View File

@ -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)

View File

@ -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):