Specify coin for account selection when possible

This commit is contained in:
Ivan Grachev 2022-08-17 17:54:12 +03:00
parent a376e412b0
commit 5a16d3aeda
3 changed files with 21 additions and 2 deletions

View File

@ -43,4 +43,19 @@ extension CoinType {
}
}
static func correspondingToWeb3Provider(_ web3Provider: Web3Provider) -> CoinType? {
switch web3Provider {
case .ethereum:
return .ethereum
case .solana:
return .solana
case .tezos:
return .tezos
case .near:
return .near
case .unknown:
return nil
}
}
}

View File

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

View File

@ -79,7 +79,7 @@ class Agent: NSObject {
let accountsList = instantiate(AccountsListViewController.self)
if case let .wcSession(session) = request, let completion = onSelectedWallet(session: session) {
accountsList.accountSelectionConfiguration = AccountSelectionConfiguration(peer: nil, selectedAccounts: Set(), completion: completion)
accountsList.accountSelectionConfiguration = AccountSelectionConfiguration(peer: nil, coinType: .ethereum, selectedAccounts: Set(), completion: completion)
}
let windowController = Window.showNew(closeOthers: accountsList.accountSelectionConfiguration == nil)
@ -319,7 +319,10 @@ class Agent: NSObject {
windowNumber = windowController.window?.windowNumber
let accountsList = instantiate(AccountsListViewController.self)
// TODO: pass selected accounts when there are some
accountsList.accountSelectionConfiguration = AccountSelectionConfiguration(peer: safariRequest.peerMeta, selectedAccounts: Set(), completion: accountAction.completion)
accountsList.accountSelectionConfiguration = AccountSelectionConfiguration(peer: safariRequest.peerMeta,
coinType: CoinType.correspondingToWeb3Provider(accountAction.provider),
selectedAccounts: Set(),
completion: accountAction.completion)
windowController.contentViewController = accountsList
case .approveMessage(let action):
let windowController = Window.showNew(closeOthers: false)