mirror of
https://github.com/lil-org/tokenary.git
synced 2024-11-30 13:02:49 +03:00
Use chain id requested by dapp for WalletConnect
This commit is contained in:
parent
cc26a06d70
commit
c5ae232de1
@ -18,7 +18,12 @@ struct SelectAccountAction {
|
||||
var selectedAccounts: Set<SpecificWalletAccount>
|
||||
let initiallyConnectedProviders: Set<Web3Provider>
|
||||
var network: EthereumChain?
|
||||
let source: Source
|
||||
let completion: (EthereumChain?, [SpecificWalletAccount]?) -> Void
|
||||
|
||||
enum Source {
|
||||
case walletConnect, safariExtension
|
||||
}
|
||||
}
|
||||
|
||||
struct SignMessageAction {
|
||||
|
@ -42,7 +42,8 @@ struct DappRequestProcessor {
|
||||
coinType: nil,
|
||||
selectedAccounts: Set(preselectedAccounts),
|
||||
initiallyConnectedProviders: initiallyConnectedProviders,
|
||||
network: network) { chain, specificWalletAccounts in
|
||||
network: network,
|
||||
source: .safariExtension) { chain, specificWalletAccounts in
|
||||
if let chain = chain, let specificWalletAccounts = specificWalletAccounts {
|
||||
var specificProviderBodies = [ResponseToExtension.Body]()
|
||||
for specificWalletAccount in specificWalletAccounts {
|
||||
@ -93,7 +94,8 @@ struct DappRequestProcessor {
|
||||
coinType: .near,
|
||||
selectedAccounts: Set(walletsManager.suggestedAccounts(coin: .near)),
|
||||
initiallyConnectedProviders: Set(),
|
||||
network: nil) { _, specificWalletAccounts in
|
||||
network: nil,
|
||||
source: .safariExtension) { _, specificWalletAccounts in
|
||||
if let specificWalletAccount = specificWalletAccounts?.first, specificWalletAccount.account.coin == .near {
|
||||
let responseBody = ResponseToExtension.Near(account: specificWalletAccount.account.address)
|
||||
respond(to: request, body: .near(responseBody), completion: completion)
|
||||
@ -148,7 +150,8 @@ struct DappRequestProcessor {
|
||||
coinType: .solana,
|
||||
selectedAccounts: Set(walletsManager.suggestedAccounts(coin: .solana)),
|
||||
initiallyConnectedProviders: Set(),
|
||||
network: nil) { _, specificWalletAccounts in
|
||||
network: nil,
|
||||
source: .safariExtension) { _, specificWalletAccounts in
|
||||
if let specificWalletAccount = specificWalletAccounts?.first, specificWalletAccount.account.coin == .solana {
|
||||
let responseBody = ResponseToExtension.Solana(publicKey: specificWalletAccount.account.address)
|
||||
respond(to: request, body: .solana(responseBody), completion: completion)
|
||||
@ -232,7 +235,8 @@ struct DappRequestProcessor {
|
||||
coinType: .ethereum,
|
||||
selectedAccounts: Set(walletsManager.suggestedAccounts(coin: .ethereum)),
|
||||
initiallyConnectedProviders: Set(),
|
||||
network: nil) { chain, specificWalletAccounts in
|
||||
network: nil,
|
||||
source: .safariExtension) { chain, specificWalletAccounts in
|
||||
if let chain = chain, let specificWalletAccount = specificWalletAccounts?.first, 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)
|
||||
|
@ -85,6 +85,7 @@ class Agent: NSObject {
|
||||
selectedAccounts: Set(walletsManager.suggestedAccounts(coin: .ethereum)),
|
||||
initiallyConnectedProviders: Set(),
|
||||
network: nil,
|
||||
source: .walletConnect,
|
||||
completion: completion)
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,9 @@ class AccountsListViewController: NSViewController {
|
||||
secondaryButton.keyEquivalent = ""
|
||||
}
|
||||
|
||||
if networkButton.menu == nil {
|
||||
if selectAccountAction.source == .walletConnect {
|
||||
networkButton.isHidden = true
|
||||
} else if networkButton.menu == nil {
|
||||
let menu = NSMenu()
|
||||
for mainnet in EthereumChain.allMainnets {
|
||||
let item = NSMenuItem(title: mainnet.name, action: #selector(didSelectChain(_:)), keyEquivalent: "")
|
||||
|
@ -87,11 +87,16 @@ class WalletConnect {
|
||||
private func configure(interactor: WCInteractor, chainId: Int, walletId: String) {
|
||||
guard let address = walletsManager.getWallet(id: walletId)?.ethereumAddress else { return }
|
||||
let accounts = [address]
|
||||
var chainId = chainId
|
||||
|
||||
interactor.onError = { _ in }
|
||||
|
||||
interactor.onSessionRequest = { [weak self, weak interactor] (_, peerParam) in
|
||||
guard let interactor = interactor else { return }
|
||||
if let requestedChainId = peerParam.chainId {
|
||||
chainId = requestedChainId
|
||||
}
|
||||
|
||||
self?.peers[interactor.clientId] = peerParam.peerMeta
|
||||
self?.sessionStorage.add(interactor: interactor, chainId: chainId, walletId: walletId, sessionDetails: peerParam)
|
||||
interactor.approveSession(accounts: accounts, chainId: chainId).cauterize()
|
||||
|
Loading…
Reference in New Issue
Block a user