Skip to content

Commit

Permalink
Merge pull request #816 from WalletConnect/extend-chains-methods
Browse files Browse the repository at this point in the history
Extend chains and methods
  • Loading branch information
llbartekll authored Apr 21, 2023
2 parents c6d06db + b01ef4d commit 48dd5fa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,25 @@ 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)! }

/* 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)!]
*/
do {
let sessionNamespaces = try AutoNamespaces.build(
sessionProposal: proposal,
chains: [Blockchain("eip155:1")!, Blockchain("eip155:137")!],
methods: ["eth_sendTransaction", "personal_sign"],
events: ["accountsChanged", "chainChanged"],
accounts: [
Account(blockchain: Blockchain("eip155:5")!, address: ETHSigner.address)!,
Account(blockchain: Blockchain("eip155:1")!, address: ETHSigner.address)!,
Account(blockchain: Blockchain("eip155:137")!, address: ETHSigner.address)!
]
chains: supportedChains,
methods: supportedMethods,
events: supportedEvents,
accounts: supportedAccounts
)
try await Web3Wallet.instance.approve(proposalId: proposal.id, namespaces: sessionNamespaces)
} catch {
Expand Down
2 changes: 1 addition & 1 deletion Sources/WalletConnectSign/Namespace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ enum Namespace {
if let chains = proposedNamespace.chains {
try chains.forEach { chain in
if !approvedNamespace.accounts.contains(where: { $0.blockchain == chain }) {
throw WalletConnectError.unsupportedNamespace(.unsupportedChains)
throw WalletConnectError.unsupportedNamespace(.unsupportedAccounts)
}
}
} else {
Expand Down

0 comments on commit 48dd5fa

Please sign in to comment.