Pass wallet id instead of TokenaryWallet on successful account selection

This commit is contained in:
Ivan Grachev 2022-08-17 15:58:04 +03:00
parent d5583f5709
commit 502e6cc12b
5 changed files with 17 additions and 17 deletions

View File

@ -5,5 +5,5 @@ import WalletCore
struct AccountSelectionConfiguration {
let peer: PeerMeta?
let completion: ((EthereumChain?, TokenaryWallet?, Account?) -> Void)
let completion: ((EthereumChain?, String?, Account?) -> Void)
}

View File

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

View File

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

View File

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

View File

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