mirror of
https://github.com/lil-org/wallet.git
synced 2025-01-07 13:46:25 +03:00
Keep initially connected providers list on switch account request
This commit is contained in:
parent
e4d9b2d5df
commit
815073647a
@ -7,5 +7,6 @@ struct AccountSelectionConfiguration {
|
|||||||
let peer: PeerMeta?
|
let peer: PeerMeta?
|
||||||
let coinType: CoinType?
|
let coinType: CoinType?
|
||||||
var selectedAccounts: Set<SpecificWalletAccount>
|
var selectedAccounts: Set<SpecificWalletAccount>
|
||||||
|
let initiallyConnectedProviders: Set<Web3Provider>
|
||||||
let completion: ((EthereumChain?, SpecificWalletAccount?) -> Void)
|
let completion: ((EthereumChain?, SpecificWalletAccount?) -> Void)
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ enum DappRequestAction {
|
|||||||
|
|
||||||
struct SelectAccountAction {
|
struct SelectAccountAction {
|
||||||
let provider: Web3Provider
|
let provider: Web3Provider
|
||||||
|
let initiallyConnectedProviders: Set<Web3Provider>
|
||||||
let preselectedAccounts: [SpecificWalletAccount]
|
let preselectedAccounts: [SpecificWalletAccount]
|
||||||
let completion: (EthereumChain?, SpecificWalletAccount?) -> Void
|
let completion: (EthereumChain?, SpecificWalletAccount?) -> Void
|
||||||
}
|
}
|
||||||
|
@ -36,8 +36,10 @@ struct DappRequestProcessor {
|
|||||||
guard let coin = CoinType.correspondingToWeb3Provider(configuration.provider) else { return nil }
|
guard let coin = CoinType.correspondingToWeb3Provider(configuration.provider) else { return nil }
|
||||||
return walletsManager.getSpecificAccount(coin: coin, address: configuration.address)
|
return walletsManager.getSpecificAccount(coin: coin, address: configuration.address)
|
||||||
}
|
}
|
||||||
|
let initiallyConnectedProviders = Set(body.providerConfigurations.map { $0.provider })
|
||||||
let action = SelectAccountAction(provider: .unknown, preselectedAccounts: preselectedAccounts) { chain, specificWalletAccount in
|
let action = SelectAccountAction(provider: .unknown,
|
||||||
|
initiallyConnectedProviders: initiallyConnectedProviders,
|
||||||
|
preselectedAccounts: preselectedAccounts) { chain, specificWalletAccount in
|
||||||
if let chain = chain, let specificWalletAccount = specificWalletAccount {
|
if let chain = chain, let specificWalletAccount = specificWalletAccount {
|
||||||
let account = specificWalletAccount.account
|
let account = specificWalletAccount.account
|
||||||
switch account.coin {
|
switch account.coin {
|
||||||
@ -70,7 +72,7 @@ struct DappRequestProcessor {
|
|||||||
switch body.method {
|
switch body.method {
|
||||||
case .signIn:
|
case .signIn:
|
||||||
let suggestedAccounts = walletsManager.suggestedAccounts(coin: .near)
|
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 {
|
if let specificWalletAccount = specificWalletAccount, specificWalletAccount.account.coin == .near {
|
||||||
let responseBody = ResponseToExtension.Near(account: specificWalletAccount.account.address)
|
let responseBody = ResponseToExtension.Near(account: specificWalletAccount.account.address)
|
||||||
respond(to: request, body: .near(responseBody), completion: completion)
|
respond(to: request, body: .near(responseBody), completion: completion)
|
||||||
@ -122,7 +124,7 @@ struct DappRequestProcessor {
|
|||||||
switch body.method {
|
switch body.method {
|
||||||
case .connect:
|
case .connect:
|
||||||
let suggestedAccounts = walletsManager.suggestedAccounts(coin: .solana)
|
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 {
|
if let specificWalletAccount = specificWalletAccount, specificWalletAccount.account.coin == .solana {
|
||||||
let responseBody = ResponseToExtension.Solana(publicKey: specificWalletAccount.account.address)
|
let responseBody = ResponseToExtension.Solana(publicKey: specificWalletAccount.account.address)
|
||||||
respond(to: request, body: .solana(responseBody), completion: completion)
|
respond(to: request, body: .solana(responseBody), completion: completion)
|
||||||
@ -203,7 +205,7 @@ struct DappRequestProcessor {
|
|||||||
switch ethereumRequest.method {
|
switch ethereumRequest.method {
|
||||||
case .requestAccounts:
|
case .requestAccounts:
|
||||||
let suggestedAccounts = walletsManager.suggestedAccounts(coin: .ethereum)
|
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 {
|
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)
|
let responseBody = ResponseToExtension.Ethereum(results: [specificWalletAccount.account.address], chainId: chain.hexStringId, rpcURL: chain.nodeURLString)
|
||||||
respond(to: request, body: .ethereum(responseBody), completion: completion)
|
respond(to: request, body: .ethereum(responseBody), completion: completion)
|
||||||
|
@ -79,7 +79,11 @@ class Agent: NSObject {
|
|||||||
let accountsList = instantiate(AccountsListViewController.self)
|
let accountsList = instantiate(AccountsListViewController.self)
|
||||||
|
|
||||||
if case let .wcSession(session) = request, let completion = onSelectedWallet(session: session) {
|
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)
|
let windowController = Window.showNew(closeOthers: accountsList.accountSelectionConfiguration == nil)
|
||||||
@ -322,6 +326,7 @@ class Agent: NSObject {
|
|||||||
accountsList.accountSelectionConfiguration = AccountSelectionConfiguration(peer: safariRequest.peerMeta,
|
accountsList.accountSelectionConfiguration = AccountSelectionConfiguration(peer: safariRequest.peerMeta,
|
||||||
coinType: coinType,
|
coinType: coinType,
|
||||||
selectedAccounts: Set(accountAction.preselectedAccounts),
|
selectedAccounts: Set(accountAction.preselectedAccounts),
|
||||||
|
initiallyConnectedProviders: accountAction.initiallyConnectedProviders,
|
||||||
completion: accountAction.completion)
|
completion: accountAction.completion)
|
||||||
windowController.contentViewController = accountsList
|
windowController.contentViewController = accountsList
|
||||||
case .approveMessage(let action):
|
case .approveMessage(let action):
|
||||||
|
Loading…
Reference in New Issue
Block a user