diff --git a/Example/WalletApp/PresentationLayer/Wallet/SessionProposal/SessionProposalInteractor.swift b/Example/WalletApp/PresentationLayer/Wallet/SessionProposal/SessionProposalInteractor.swift index b5bc8aa7f..0055364f4 100644 --- a/Example/WalletApp/PresentationLayer/Wallet/SessionProposal/SessionProposalInteractor.swift +++ b/Example/WalletApp/PresentationLayer/Wallet/SessionProposal/SessionProposalInteractor.swift @@ -4,24 +4,28 @@ import Web3Wallet final class SessionProposalInteractor { func approve(proposal: Session.Proposal) async throws { - // Following properties are used to support all the required namespaces for the testing purposes - let supportedMethods = Array(proposal.requiredNamespaces.map { $0.value.methods }.first ?? []) - let supportedEvents = Array(proposal.requiredNamespaces.map { $0.value.events }.first ?? []) - let supportedChains = Array((proposal.requiredNamespaces.map { $0.value.chains }.first ?? [] )!) - let supportedAccounts = supportedChains.map { Account(blockchain: $0, address: ETHSigner.address)! } + // Following properties are used to support all the required and optional namespaces for the testing purposes + let supportedMethods = Set(proposal.requiredNamespaces.flatMap { $0.value.methods } + (proposal.optionalNamespaces?.flatMap { $0.value.methods } ?? [])) + let supportedEvents = Set(proposal.requiredNamespaces.flatMap { $0.value.events } + (proposal.optionalNamespaces?.flatMap { $0.value.events } ?? [])) + + let supportedRequiredChains = proposal.requiredNamespaces["eip155"]?.chains + let supportedOptionalChains = proposal.optionalNamespaces?["eip155"]?.chains ?? [] + let supportedChains = supportedRequiredChains?.union(supportedOptionalChains) ?? [] + + let supportedAccounts = Array(supportedChains).map { Account(blockchain: $0, address: ETHSigner.address)! } /* Use only supported values for production. I.e: let supportedMethods = ["eth_signTransaction", "personal_sign", "eth_signTypedData", "eth_sendTransaction", "eth_sign"] let supportedEvents = ["accountsChanged", "chainChanged"] - let supportedChains = [Blockchain("eip155:1")!, Blockchain("eip155:5")!] - let supportedAccounts = [Account(blockchain: Blockchain("eip155:5")!, address: ETHSigner.address)!] + let supportedChains = [Blockchain("eip155:1")!, Blockchain("eip155:137")!] + let supportedAccounts = [Account(blockchain: Blockchain("eip155:1")!, address: ETHSigner.address)!, Account(blockchain: Blockchain("eip155:137")!, address: ETHSigner.address)!] */ do { let sessionNamespaces = try AutoNamespaces.build( sessionProposal: proposal, - chains: supportedChains, - methods: supportedMethods, - events: supportedEvents, + chains: Array(supportedChains), + methods: Array(supportedMethods), + events: Array(supportedEvents), accounts: supportedAccounts ) try await Web3Wallet.instance.approve(proposalId: proposal.id, namespaces: sessionNamespaces)