From 4d8a36d7c8c087ce24d6279aa08bed3fb367cca6 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Thu, 12 Sep 2024 11:42:44 +0200 Subject: [PATCH] add session properties builder --- .../BusinessLayer/SmartAccount.swift | 4 +- .../SessionProposalInteractor.swift | 47 ++++++++++++------- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/Example/WalletApp/BusinessLayer/SmartAccount.swift b/Example/WalletApp/BusinessLayer/SmartAccount.swift index 2f7d4e94..85c9b18f 100644 --- a/Example/WalletApp/BusinessLayer/SmartAccount.swift +++ b/Example/WalletApp/BusinessLayer/SmartAccount.swift @@ -27,7 +27,9 @@ class SmartAccount { private var config: Config? - private init() {} + private init() { + + } public func configure(entryPoint: String, chainId: Int) { self.config = Config( diff --git a/Example/WalletApp/PresentationLayer/Wallet/SessionProposal/SessionProposalInteractor.swift b/Example/WalletApp/PresentationLayer/Wallet/SessionProposal/SessionProposalInteractor.swift index e29864c9..b7f7dc83 100644 --- a/Example/WalletApp/PresentationLayer/Wallet/SessionProposal/SessionProposalInteractor.swift +++ b/Example/WalletApp/PresentationLayer/Wallet/SessionProposal/SessionProposalInteractor.swift @@ -11,7 +11,7 @@ final class SessionProposalInteractor { let supportedRequiredChains = proposal.requiredNamespaces["eip155"]?.chains ?? [] let supportedOptionalChains = proposal.optionalNamespaces?["eip155"]?.chains ?? [] - var supportedChains = [Blockchain("eip155:11155111")!] + var supportedChains = supportedRequiredChains + supportedOptionalChains let smartAccountAddress = try await SmartAccount.instance.getClient().getAddress() @@ -44,22 +44,9 @@ final class SessionProposalInteractor { AlertPresenter.present(message: error.localizedDescription, type: .error) return false } - let capabilities = """ - { - "0x0B0D91cF5541673b69bA4a1f596E84146Ddd006C":{ - "0xaa36a7":{ - "atomicBatch":{ - "supported":true - } - } - } - } - """ - let sessionProperties: [String: String] = [ - "bundler_name": "pimlico", - "capabilities": capabilities - ] + + let sessionProperties = getSessionProperties() _ = try await WalletKit.instance.approve(proposalId: proposal.id, namespaces: sessionNamespaces, sessionProperties: sessionProperties) if let uri = proposal.proposer.redirect?.native { ReownRouter.goBack(uri: uri) @@ -69,6 +56,34 @@ final class SessionProposalInteractor { } } + private func getSessionProperties() -> [String: String] { + + let sepoliaAtomicBatchCapability = """ + { + "0xaa36a7":{ + "atomicBatch":{ + "supported":true + } + } + } + """ + let capabilities = ["capabilities": sepoliaAtomicBatchCapability] + + if let capabilitiesData = try? JSONSerialization.data(withJSONObject: capabilities, options: []), + let capabilitiesJSONString = String(data: capabilitiesData, encoding: .utf8) { + + // Create the sessionProperties dictionary with the stringified capabilities + let sessionProperties: [String: String] = [ + "bundler_name": "pimlico", + "capabilities": capabilitiesJSONString + ] + + print(sessionProperties) + return sessionProperties + } + return [:] + } + func reject(proposal: Session.Proposal, reason: RejectionReason = .userRejected) async throws { try await WalletKit.instance.rejectSession(proposalId: proposal.id, reason: .userRejected) /* Redirect */