From 12cd8cb5d1226bad164fc67f48fe74656384c3ea Mon Sep 17 00:00:00 2001 From: llbartekll Date: Wed, 12 Jun 2024 10:31:52 +0200 Subject: [PATCH 01/15] fix error display on method unsupported --- Package.swift | 2 +- .../Web3Modal/Sheets/Web3ModalViewModel.swift | 21 ++++++++++++++----- .../xcshareddata/swiftpm/Package.resolved | 3 +-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Package.swift b/Package.swift index cb6a3c7..ec17f2f 100644 --- a/Package.swift +++ b/Package.swift @@ -21,7 +21,7 @@ let package = Package( dependencies: [ .package( url: "https://github.com/WalletConnect/WalletConnectSwiftV2", - .upToNextMinor(from: "1.19.1") + .revision("00dc3944770a124d6572ab9318cea388a47b8d1e") ), .package( url: "https://github.com/WalletConnect/QRCode", diff --git a/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift b/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift index 534840b..b750083 100644 --- a/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift +++ b/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift @@ -52,7 +52,11 @@ class Web3ModalViewModel: ObservableObject { signInteractor.sessionSettlePublisher .receive(on: DispatchQueue.main) .sink { session in - self.handleNewSession(session: session) + if Web3Modal.config.authRequestParams != nil { + self.handleSIWEFallback() + } else { + self.handleNewSession(session: session) + } } .store(in: &disposeBag) @@ -66,10 +70,13 @@ class Web3ModalViewModel: ObservableObject { self?.handleNewSession(session: session) } case .failure(let error): - // Handle the error similarly to how other errors are handled in the class - store.toast = .init(style: .error, message: "Authentication error: \(error.localizedDescription)") - Web3Modal.config.onError(error) - self?.store.retryShown = true + if error == .methodUnsupported { + break + } else { + store.toast = .init(style: .error, message: "Authentication error: \(error.localizedDescription)") + Web3Modal.config.onError(error) + self?.store.retryShown = true + } } } .store(in: &disposeBag) @@ -149,6 +156,10 @@ class Web3ModalViewModel: ObservableObject { } } + private func handleSIWEFallback() { + + } + func getChains() -> [Chain] { guard let namespaces = store.session?.namespaces.values else { diff --git a/Web3Modal.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Web3Modal.xcworkspace/xcshareddata/swiftpm/Package.resolved index edb7a27..93ef6cf 100644 --- a/Web3Modal.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Web3Modal.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -113,8 +113,7 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/WalletConnect/WalletConnectSwiftV2", "state" : { - "revision" : "7cac840104d75b8076ff36908cb6f95ed230d53d", - "version" : "1.19.1" + "revision" : "00dc3944770a124d6572ab9318cea388a47b8d1e" } }, { From 6dfe7058a87ecd3dce36cdbb462a2f01abbea4e2 Mon Sep 17 00:00:00 2001 From: llbartekll Date: Wed, 12 Jun 2024 10:51:10 +0200 Subject: [PATCH 02/15] savepoint --- Sources/Web3Modal/Core/Web3Modal.swift | 3 ++- Sources/Web3Modal/Sheets/Web3ModalView.swift | 2 +- Sources/Web3Modal/Sheets/Web3ModalViewModel.swift | 9 ++++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Sources/Web3Modal/Core/Web3Modal.swift b/Sources/Web3Modal/Core/Web3Modal.swift index bb1ffc7..f5e3bed 100644 --- a/Sources/Web3Modal/Core/Web3Modal.swift +++ b/Sources/Web3Modal/Core/Web3Modal.swift @@ -141,7 +141,8 @@ public class Web3Modal { store: store, w3mApiInteractor: w3mApiInteractor, signInteractor: signInteractor, - blockchainApiInteractor: blockchainApiInteractor + blockchainApiInteractor: blockchainApiInteractor, + supportsAuthenticatedSession: (config.authRequestParams != nil) ) Task { diff --git a/Sources/Web3Modal/Sheets/Web3ModalView.swift b/Sources/Web3Modal/Sheets/Web3ModalView.swift index 6822ac9..0a17f57 100644 --- a/Sources/Web3Modal/Sheets/Web3ModalView.swift +++ b/Sources/Web3Modal/Sheets/Web3ModalView.swift @@ -137,7 +137,7 @@ struct Web3ModalView_Previews: PreviewProvider { store: Store(), w3mApiInteractor: W3MAPIInteractor(store: Store()), signInteractor: SignInteractor(store: Store()), - blockchainApiInteractor: BlockchainAPIInteractor(store: Store()) + blockchainApiInteractor: BlockchainAPIInteractor(store: Store()), supportsAuthenticatedSession: false )) .previewLayout(.sizeThatFits) } diff --git a/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift b/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift index b750083..b340164 100644 --- a/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift +++ b/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift @@ -7,7 +7,8 @@ class Web3ModalViewModel: ObservableObject { private(set) var w3mApiInteractor: W3MAPIInteractor private(set) var signInteractor: SignInteractor private(set) var blockchainApiInteractor: BlockchainAPIInteractor - + private let supportsAuthenticatedSession: Bool + private var disposeBag = Set() init( @@ -15,13 +16,15 @@ class Web3ModalViewModel: ObservableObject { store: Store, w3mApiInteractor: W3MAPIInteractor, signInteractor: SignInteractor, - blockchainApiInteractor: BlockchainAPIInteractor + blockchainApiInteractor: BlockchainAPIInteractor, + supportsAuthenticatedSession: Bool ) { self.router = router self.store = store self.w3mApiInteractor = w3mApiInteractor self.signInteractor = signInteractor self.blockchainApiInteractor = blockchainApiInteractor + self.supportsAuthenticatedSession = supportsAuthenticatedSession Web3Modal.instance.sessionEventPublisher .receive(on: DispatchQueue.main) @@ -52,7 +55,7 @@ class Web3ModalViewModel: ObservableObject { signInteractor.sessionSettlePublisher .receive(on: DispatchQueue.main) .sink { session in - if Web3Modal.config.authRequestParams != nil { + if supportsAuthenticatedSession { self.handleSIWEFallback() } else { self.handleNewSession(session: session) From 43da34386212256c52ccd8c4b2cf2a6d0a1ce608 Mon Sep 17 00:00:00 2001 From: llbartekll Date: Wed, 12 Jun 2024 17:38:31 +0200 Subject: [PATCH 03/15] savepoint --- Package.swift | 2 +- .../WalletDetail/WalletDetailView.swift | 60 +++++++++++++++---- .../WalletDetail/WalletDetailViewModel.swift | 27 ++++++++- .../Web3Modal/Sheets/Web3ModalViewModel.swift | 11 +++- Sources/Web3Modal/Store.swift | 16 ++++- .../xcshareddata/swiftpm/Package.resolved | 2 +- 6 files changed, 100 insertions(+), 18 deletions(-) diff --git a/Package.swift b/Package.swift index ec17f2f..0ebfe79 100644 --- a/Package.swift +++ b/Package.swift @@ -21,7 +21,7 @@ let package = Package( dependencies: [ .package( url: "https://github.com/WalletConnect/WalletConnectSwiftV2", - .revision("00dc3944770a124d6572ab9318cea388a47b8d1e") + .revision("b0bf7892844fac62207aa8dcd27cda6c72287645") ), .package( url: "https://github.com/WalletConnect/QRCode", diff --git a/Sources/Web3Modal/Screens/ConnectWallet/WalletDetail/WalletDetailView.swift b/Sources/Web3Modal/Screens/ConnectWallet/WalletDetail/WalletDetailView.swift index 990b668..bc7f5ab 100644 --- a/Sources/Web3Modal/Screens/ConnectWallet/WalletDetail/WalletDetailView.swift +++ b/Sources/Web3Modal/Screens/ConnectWallet/WalletDetail/WalletDetailView.swift @@ -25,10 +25,10 @@ struct WalletDetailView: View { walletInfo() - if viewModel.wallet.isInstalled == true { + if viewModel.wallet.isInstalled == true && !store.SIWEFallbackState { copyLink() } - + if viewModel.preferredPlatform == .mobile, viewModel.wallet.isInstalled != true, @@ -36,11 +36,47 @@ struct WalletDetailView: View { { appStoreRow() } + + if store.SIWEFallbackState { + siweFallbackButtons() + } } .padding(.horizontal, Spacing.s) .padding(.bottom, Spacing.xl + 17) } - + + private func siweFallbackButtons() -> some View { + HStack { + Button(action: { + Task { + try await viewModel.cancel() + } + }) { + Text("Cancel") + .foregroundColor(.black) + .padding() + .frame(maxWidth: .infinity) + .background(Color.gray.opacity(0.2)) + .cornerRadius(8) + } + + Button(action: { + Task { + try await viewModel.signSIWE() + } + }) { + Text("Sign") + .foregroundColor(.white) + .padding() + .frame(maxWidth: .infinity) + .background(Color.blue) + .cornerRadius(8) + } + } + .padding(.horizontal, 20) + .padding(.bottom, 20) + } + private func picker() -> some View { W3MPicker( WalletDetailViewModel.Platform.allCases, @@ -149,28 +185,30 @@ struct WalletDetailView: View { walletImage() .padding(.top, 40) .padding(.bottom, Spacing.xl) - - Text(store.retryShown ? "Connection declined" : "Continue in \(viewModel.wallet.name)") + + Text(store.SIWEFallbackState ? "Web3Modal needs to connect to your wallet." : (store.retryShown ? "Connection declined" : "Continue in \(viewModel.wallet.name)")) .font(.paragraph600) .foregroundColor(store.retryShown ? .Error100 : .Foreground100) .padding(.bottom, Spacing.xs) - + Text( - store.retryShown - ? "Connection can be declined if a previous request is still active" - : viewModel.preferredPlatform == .browser ? "Open and continue in a new browser tab" : "Accept connection request in the wallet" + store.SIWEFallbackState + ? "Sign this message to prove you own this wallet and proceed. Cancelling will disconnect you." + : (store.retryShown + ? "Connection can be declined if a previous request is still active" + : viewModel.preferredPlatform == .browser ? "Open and continue in a new browser tab" : "Accept connection request in the wallet") ) .font(.small500) .foregroundColor(.Foreground200) .multilineTextAlignment(.center) .padding(.bottom, Spacing.l) - + if store.retryShown || viewModel.preferredPlatform == .browser { retryButton() } } } - + func appStoreRow() -> some View { HStack(spacing: 0) { Text("Don't have \(viewModel.wallet.name)?") diff --git a/Sources/Web3Modal/Screens/ConnectWallet/WalletDetail/WalletDetailViewModel.swift b/Sources/Web3Modal/Screens/ConnectWallet/WalletDetail/WalletDetailViewModel.swift index 6d30424..b6e9a28 100644 --- a/Sources/Web3Modal/Screens/ConnectWallet/WalletDetail/WalletDetailViewModel.swift +++ b/Sources/Web3Modal/Screens/ConnectWallet/WalletDetail/WalletDetailViewModel.swift @@ -55,7 +55,32 @@ class WalletDetailViewModel: ObservableObject { } .store(in: &disposeBag) } - + + func cancel() async throws { + store.SIWEFallbackState = false + guard let topic = store.session?.topic else { return } + try await Web3Modal.instance.disconnect(topic: topic) + } + + func signSIWE() async throws { + DispatchQueue.main.async { [weak self] in + self?.store.SIWEFallbackState = false + } + guard let account = store.account?.account(), + let authRequestParams = Web3Modal.config.authRequestParams else { return } + + let authPayload = AuthPayload(requestParams: authRequestParams, iat: DefaultIATProvider().iat) + let siweMessage = try Sign.instance.formatAuthMessage(payload: authPayload, account: account) + + let rpcRequest: W3MJSONRPC = .personal_sign(address: account.address, message: siweMessage) + try await Web3Modal.instance.request(rpcRequest) + store.siweRequestId = rpcRequest.id + navigateToDeepLink( + wallet: wallet, + preferBrowser: preferredPlatform == .browser + ) + } + func handle(_ event: Event) { switch event { case .didTapCopy: diff --git a/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift b/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift index b340164..530e7ea 100644 --- a/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift +++ b/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift @@ -55,10 +55,11 @@ class Web3ModalViewModel: ObservableObject { signInteractor.sessionSettlePublisher .receive(on: DispatchQueue.main) .sink { session in + self.handleNewSession(session: session) if supportsAuthenticatedSession { self.handleSIWEFallback() } else { - self.handleNewSession(session: session) + self.routeToProfile() } } .store(in: &disposeBag) @@ -71,6 +72,7 @@ class Web3ModalViewModel: ObservableObject { case .success(let (session, _)): if let session = session { self?.handleNewSession(session: session) + self?.routeToProfile() } case .failure(let error): if error == .methodUnsupported { @@ -140,7 +142,6 @@ class Web3ModalViewModel: ObservableObject { } private func handleNewSession(session: Session) { - router.setRoute(Router.AccountSubpage.profile) store.connectedWith = .wc store.account = .init(from: session) store.session = session @@ -154,13 +155,17 @@ class Web3ModalViewModel: ObservableObject { fetchIdentity() + } + + private func routeToProfile() { + router.setRoute(Router.AccountSubpage.profile) withAnimation { store.isModalShown = false } } private func handleSIWEFallback() { - + store.SIWEFallbackState = true } diff --git a/Sources/Web3Modal/Store.swift b/Sources/Web3Modal/Store.swift index 5dfbf07..edcbd91 100644 --- a/Sources/Web3Modal/Store.swift +++ b/Sources/Web3Modal/Store.swift @@ -1,5 +1,6 @@ import Combine import SwiftUI +import WalletConnectUtils enum ConnectionProviderType { case wc @@ -12,6 +13,14 @@ class Store: ObservableObject { @Published var isModalShown: Bool = false @Published var retryShown = false + @Published var SIWEFallbackState: Bool = false { + didSet { + if SIWEFallbackState == true { + retryShown = false + } + } + } + @Published var identity: Identity? @Published var balance: Double? @@ -53,7 +62,8 @@ class Store: ObservableObject { var totalPages: Int = .max var walletImages: [String: UIImage] = [:] var installedWalletIds: [String] = [] - + var siweRequestId: RPCID + var recentWallets: [Wallet] { get { RecentWalletsStorage.loadRecentWallets() @@ -88,4 +98,8 @@ extension W3MAccount { address: "0x5c8877144d858e41d8c33f5baa7e67a5e0027e37", chain: Blockchain(namespace: "eip155", reference: "56")! ) + + func account() -> Account? { + return Account(blockchain: chain, address: address) + } } diff --git a/Web3Modal.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Web3Modal.xcworkspace/xcshareddata/swiftpm/Package.resolved index 93ef6cf..163ee2f 100644 --- a/Web3Modal.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Web3Modal.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -113,7 +113,7 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/WalletConnect/WalletConnectSwiftV2", "state" : { - "revision" : "00dc3944770a124d6572ab9318cea388a47b8d1e" + "revision" : "b0bf7892844fac62207aa8dcd27cda6c72287645" } }, { From be72b870b6303419a8d3f01496cd14cc6af18e11 Mon Sep 17 00:00:00 2001 From: llbartekll Date: Thu, 13 Jun 2024 13:37:22 +0200 Subject: [PATCH 04/15] savepoint --- Package.swift | 2 +- Sources/Web3Modal/Core/Web3ModalClient.swift | 2 + .../WalletDetail/WalletDetailViewModel.swift | 28 +++++++++---- .../Web3Modal/Sheets/Web3ModalViewModel.swift | 39 ++++++++++++++++++- Sources/Web3Modal/Store.swift | 3 +- .../xcshareddata/swiftpm/Package.resolved | 2 +- 6 files changed, 64 insertions(+), 12 deletions(-) diff --git a/Package.swift b/Package.swift index 0ebfe79..6317407 100644 --- a/Package.swift +++ b/Package.swift @@ -21,7 +21,7 @@ let package = Package( dependencies: [ .package( url: "https://github.com/WalletConnect/WalletConnectSwiftV2", - .revision("b0bf7892844fac62207aa8dcd27cda6c72287645") + .revision("997be80a6f86be4ba340ac8121acde24fc428520") ), .package( url: "https://github.com/WalletConnect/QRCode", diff --git a/Sources/Web3Modal/Core/Web3ModalClient.swift b/Sources/Web3Modal/Core/Web3ModalClient.swift index 4650218..7cd0ec4 100644 --- a/Sources/Web3Modal/Core/Web3ModalClient.swift +++ b/Sources/Web3Modal/Core/Web3ModalClient.swift @@ -80,6 +80,8 @@ public class Web3ModalClient { return analyticsService.isAnalyticsEnabled } +// add user authenticated publisher authResponsePublisher+SIWE + // MARK: - Private Properties private let signClient: SignClient diff --git a/Sources/Web3Modal/Screens/ConnectWallet/WalletDetail/WalletDetailViewModel.swift b/Sources/Web3Modal/Screens/ConnectWallet/WalletDetail/WalletDetailViewModel.swift index b6e9a28..5b475e8 100644 --- a/Sources/Web3Modal/Screens/ConnectWallet/WalletDetail/WalletDetailViewModel.swift +++ b/Sources/Web3Modal/Screens/ConnectWallet/WalletDetail/WalletDetailViewModel.swift @@ -20,7 +20,8 @@ class WalletDetailViewModel: ObservableObject { let router: Router let store: Store let signInteractor: SignInteractor - + + @Published var preferredPlatform: Platform = .mobile private var disposeBag = Set() @@ -67,18 +68,29 @@ class WalletDetailViewModel: ObservableObject { self?.store.SIWEFallbackState = false } guard let account = store.account?.account(), - let authRequestParams = Web3Modal.config.authRequestParams else { return } + let authRequestParams = Web3Modal.config.authRequestParams, + let topic = Web3Modal.instance.getSessions().first?.topic, + let chain = Web3Modal.instance.getSelectedChain(), + let blockchain = Blockchain(namespace: chain.chainNamespace, reference: chain.chainReference) + else { return } let authPayload = AuthPayload(requestParams: authRequestParams, iat: DefaultIATProvider().iat) let siweMessage = try Sign.instance.formatAuthMessage(payload: authPayload, account: account) - let rpcRequest: W3MJSONRPC = .personal_sign(address: account.address, message: siweMessage) - try await Web3Modal.instance.request(rpcRequest) + + let rpcRequest = try Request(topic: topic, method: "personal_sign", params: AnyCodable([siweMessage, account.address]), chainId: blockchain) + try await Sign.instance.request(params: rpcRequest) + store.siweRequestId = rpcRequest.id - navigateToDeepLink( - wallet: wallet, - preferBrowser: preferredPlatform == .browser - ) + store.siweMessage = siweMessage + + DispatchQueue.main.async { [weak self] in + guard let self = self else { return } + self.navigateToDeepLink( + wallet: self.wallet, + preferBrowser: preferredPlatform == .browser + ) + } } func handle(_ event: Event) { diff --git a/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift b/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift index 530e7ea..92622e5 100644 --- a/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift +++ b/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift @@ -10,7 +10,7 @@ class Web3ModalViewModel: ObservableObject { private let supportsAuthenticatedSession: Bool private var disposeBag = Set() - + init( router: Router, store: Store, @@ -26,6 +26,8 @@ class Web3ModalViewModel: ObservableObject { self.blockchainApiInteractor = blockchainApiInteractor self.supportsAuthenticatedSession = supportsAuthenticatedSession + setupSIWEFallback() + Web3Modal.instance.sessionEventPublisher .receive(on: DispatchQueue.main) .sink { event, _, _ in @@ -232,4 +234,39 @@ class Web3ModalViewModel: ObservableObject { } private let namespaceRegex = try! NSRegularExpression(pattern: "^[-a-z0-9]{3,8}$") + + private func setupSIWEFallback() { + Sign.instance.sessionResponsePublisher.sink { [weak self] response in + if response.id == self?.store.siweRequestId { + switch response.result { + case .response(let result): + guard let signature = try? result.get(String.self), + let siweMessage = self?.store.siweMessage, + let account = self?.store.account?.account() else { return } + + Task { [weak self] in + do { + try await Sign.instance.verifySIWE(signature: signature, message: siweMessage, address: account.address, chainId: account.blockchainIdentifier) + + guard let self = self else { return } + + DispatchQueue.main.async { + self.router.setRoute(Router.AccountSubpage.profile) + self.store.isModalShown = false + } + } catch { + guard let self = self else { return } + + DispatchQueue.main.async { + self.store.toast = .init(style: .error, message: error.localizedDescription) + } + } + } + case .error(let error): + guard let self = self else { return } + self.store.toast = .init(style: .error, message: error.message) + } + } + }.store(in: &disposeBag) + } } diff --git a/Sources/Web3Modal/Store.swift b/Sources/Web3Modal/Store.swift index edcbd91..c439f55 100644 --- a/Sources/Web3Modal/Store.swift +++ b/Sources/Web3Modal/Store.swift @@ -62,7 +62,8 @@ class Store: ObservableObject { var totalPages: Int = .max var walletImages: [String: UIImage] = [:] var installedWalletIds: [String] = [] - var siweRequestId: RPCID + var siweRequestId: RPCID? = nil + var siweMessage: String? = nil var recentWallets: [Wallet] { get { diff --git a/Web3Modal.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Web3Modal.xcworkspace/xcshareddata/swiftpm/Package.resolved index 163ee2f..727a27c 100644 --- a/Web3Modal.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Web3Modal.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -113,7 +113,7 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/WalletConnect/WalletConnectSwiftV2", "state" : { - "revision" : "b0bf7892844fac62207aa8dcd27cda6c72287645" + "revision" : "997be80a6f86be4ba340ac8121acde24fc428520" } }, { From a6e7b85686606fd01ba83efed41965c54ce4298c Mon Sep 17 00:00:00 2001 From: llbartekll Date: Thu, 13 Jun 2024 14:30:00 +0200 Subject: [PATCH 05/15] add siwe publishers --- Sources/Web3Modal/Core/Web3ModalClient.swift | 6 +++++- .../Web3Modal/Sheets/Web3ModalViewModel.swift | 20 +++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Sources/Web3Modal/Core/Web3ModalClient.swift b/Sources/Web3Modal/Core/Web3ModalClient.swift index 7cd0ec4..0ddf71c 100644 --- a/Sources/Web3Modal/Core/Web3ModalClient.swift +++ b/Sources/Web3Modal/Core/Web3ModalClient.swift @@ -80,7 +80,11 @@ public class Web3ModalClient { return analyticsService.isAnalyticsEnabled } -// add user authenticated publisher authResponsePublisher+SIWE + public var SIWEAuthenticationPublisher: AnyPublisher, Never> { + return SIWEAuthenticationPublisherSubject.eraseToAnyPublisher() + } + + internal let SIWEAuthenticationPublisherSubject = PassthroughSubject, Never>() // MARK: - Private Properties diff --git a/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift b/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift index 92622e5..86dbecb 100644 --- a/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift +++ b/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift @@ -1,6 +1,11 @@ import Combine import SwiftUI +public enum SIWEAuthenticationError: Error { + case requestRejected + case messageVerificationFailed +} + class Web3ModalViewModel: ObservableObject { private(set) var router: Router private(set) var store: Store @@ -257,14 +262,25 @@ class Web3ModalViewModel: ObservableObject { } catch { guard let self = self else { return } + Web3Modal.instance.SIWEAuthenticationPublisherSubject.send(Result.failure( + .messageVerificationFailed)) DispatchQueue.main.async { self.store.toast = .init(style: .error, message: error.localizedDescription) + guard let topic = self.store.session?.topic else { return } + Task {try await Web3Modal.instance.disconnect(topic: topic)} + } } } case .error(let error): - guard let self = self else { return } - self.store.toast = .init(style: .error, message: error.message) + DispatchQueue.main.async { + Web3Modal.instance.SIWEAuthenticationPublisherSubject.send(Result.failure( + .requestRejected)) + guard let self = self else { return } + self.store.SIWEFallbackState = false + guard let topic = self.store.session?.topic else { return } + Task {try await Web3Modal.instance.disconnect(topic: topic)} + } } } }.store(in: &disposeBag) From e0d14d969294cd40dbed6a5f470eb5741bb0025b Mon Sep 17 00:00:00 2001 From: llbartekll Date: Thu, 13 Jun 2024 14:55:38 +0200 Subject: [PATCH 06/15] adds alerts on authentication --- Sample/Example.xcodeproj/project.pbxproj | 37 +++++++++++++++---- Sample/Example/AlertPresenter.swift | 35 ++++++++++++++++++ Sample/Example/ExampleApp.swift | 19 ++++++++++ .../Web3Modal/Sheets/Web3ModalViewModel.swift | 2 + .../xcshareddata/swiftpm/Package.resolved | 9 +++++ 5 files changed, 94 insertions(+), 8 deletions(-) create mode 100644 Sample/Example/AlertPresenter.swift diff --git a/Sample/Example.xcodeproj/project.pbxproj b/Sample/Example.xcodeproj/project.pbxproj index 4cc6b9a..5e9c706 100644 --- a/Sample/Example.xcodeproj/project.pbxproj +++ b/Sample/Example.xcodeproj/project.pbxproj @@ -8,6 +8,9 @@ /* Begin PBXBuildFile section */ 23F6FD03919B41DE98CAFCD3 /* Sentry in Frameworks */ = {isa = PBXBuildFile; productRef = BD206AA550964C49AE94A3CA /* Sentry */; }; + 84733CCD2C1B2134001B2850 /* Atlantis in Frameworks */ = {isa = PBXBuildFile; productRef = 84733CCC2C1B2134001B2850 /* Atlantis */; }; + 84733CD22C1B21D4001B2850 /* SwiftMessages in Frameworks */ = {isa = PBXBuildFile; productRef = 84733CD12C1B21D4001B2850 /* SwiftMessages */; }; + 84871D572C1B1E58005C1B50 /* AlertPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84871D562C1B1E58005C1B50 /* AlertPresenter.swift */; }; 84F3EFBB2BA86FA6005FCFAE /* DefaultCryptoProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84F3EFBA2BA86FA6005FCFAE /* DefaultCryptoProvider.swift */; }; 84F3EFBE2BA87760005FCFAE /* Web3 in Frameworks */ = {isa = PBXBuildFile; productRef = 84F3EFBD2BA87760005FCFAE /* Web3 */; }; 84F3EFC02BA87760005FCFAE /* Web3ContractABI in Frameworks */ = {isa = PBXBuildFile; productRef = 84F3EFBF2BA87760005FCFAE /* Web3ContractABI */; }; @@ -18,7 +21,6 @@ CF25F3A42B40C7070030B3DC /* Web3ModalUI in Frameworks */ = {isa = PBXBuildFile; productRef = CF25F3A32B40C7070030B3DC /* Web3ModalUI */; }; CF3B9AD22ACDBA3A00984D53 /* Web3ModalUI in Frameworks */ = {isa = PBXBuildFile; productRef = CF3B9AD12ACDBA3A00984D53 /* Web3ModalUI */; }; CFA99B922AD0549F00EB5331 /* WCSocketFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFA99B912AD0549F00EB5331 /* WCSocketFactory.swift */; }; - CFD6A70F2ADE8DE2002B402C /* Atlantis in Frameworks */ = {isa = PBXBuildFile; productRef = CFD6A70E2ADE8DE2002B402C /* Atlantis */; }; CFD720782A9CC60600636CAF /* ExampleApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFD720772A9CC60600636CAF /* ExampleApp.swift */; }; CFD7207A2A9CC60600636CAF /* ComponentLibraryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFD720792A9CC60600636CAF /* ComponentLibraryView.swift */; }; CFD7207C2A9CC60700636CAF /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CFD7207B2A9CC60700636CAF /* Assets.xcassets */; }; @@ -27,6 +29,7 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 84871D562C1B1E58005C1B50 /* AlertPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertPresenter.swift; sourceTree = ""; }; 84F3EFBA2BA86FA6005FCFAE /* DefaultCryptoProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultCryptoProvider.swift; sourceTree = ""; }; CF0BCCE42AB0886400A2866C /* ContentView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; CF533D032ADD411A00B3441C /* web3modal-swift */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = "web3modal-swift"; path = ..; sourceTree = ""; }; @@ -48,15 +51,16 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - CFD6A70F2ADE8DE2002B402C /* Atlantis in Frameworks */, 84F3EFC02BA87760005FCFAE /* Web3ContractABI in Frameworks */, CF25F3A42B40C7070030B3DC /* Web3ModalUI in Frameworks */, CF3B9AD22ACDBA3A00984D53 /* Web3ModalUI in Frameworks */, 84F3EFBE2BA87760005FCFAE /* Web3 in Frameworks */, + 84733CD22C1B21D4001B2850 /* SwiftMessages in Frameworks */, CF25F3A22B40C7070030B3DC /* Web3Modal in Frameworks */, 84F3EFC22BA87760005FCFAE /* Web3PromiseKit in Frameworks */, 23F6FD03919B41DE98CAFCD3 /* Sentry in Frameworks */, 84FEB1382C0DAE210018CB53 /* Starscream in Frameworks */, + 84733CCD2C1B2134001B2850 /* Atlantis in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -96,6 +100,7 @@ CFD7207D2A9CC60700636CAF /* Example.entitlements */, CFD7207E2A9CC60700636CAF /* Preview Content */, CFEAAF092B6C0B3A001565F5 /* InputConfig.swift */, + 84871D562C1B1E58005C1B50 /* AlertPresenter.swift */, ); path = Example; sourceTree = ""; @@ -134,7 +139,6 @@ name = Example; packageProductDependencies = ( CF3B9AD12ACDBA3A00984D53 /* Web3ModalUI */, - CFD6A70E2ADE8DE2002B402C /* Atlantis */, BD206AA550964C49AE94A3CA /* Sentry */, CF25F3A12B40C7070030B3DC /* Web3Modal */, CF25F3A32B40C7070030B3DC /* Web3ModalUI */, @@ -142,6 +146,8 @@ 84F3EFBF2BA87760005FCFAE /* Web3ContractABI */, 84F3EFC12BA87760005FCFAE /* Web3PromiseKit */, 84FEB1372C0DAE210018CB53 /* Starscream */, + 84733CCC2C1B2134001B2850 /* Atlantis */, + 84733CD12C1B21D4001B2850 /* SwiftMessages */, ); productName = Example; productReference = CFD720742A9CC60600636CAF /* Example.app */; @@ -177,6 +183,7 @@ F4A0329B6CFF49E682D3DFE7 /* XCRemoteSwiftPackageReference "sentry-cocoa" */, 84D9CCC12B9708E4001EDEE3 /* XCRemoteSwiftPackageReference "Starscream" */, 84F3EFBC2BA87760005FCFAE /* XCRemoteSwiftPackageReference "Web3" */, + 84733CD02C1B21D4001B2850 /* XCRemoteSwiftPackageReference "SwiftMessages" */, ); productRefGroup = CFD720752A9CC60600636CAF /* Products */; projectDirPath = ""; @@ -223,6 +230,7 @@ buildActionMask = 2147483647; files = ( CFEAAF0A2B6C0B3A001565F5 /* InputConfig.swift in Sources */, + 84871D572C1B1E58005C1B50 /* AlertPresenter.swift in Sources */, CFD7207A2A9CC60600636CAF /* ComponentLibraryView.swift in Sources */, CFD720782A9CC60600636CAF /* ExampleApp.swift in Sources */, CF0BCCE52AB0886400A2866C /* ContentView.swift in Sources */, @@ -483,6 +491,14 @@ /* End XCLocalSwiftPackageReference section */ /* Begin XCRemoteSwiftPackageReference section */ + 84733CD02C1B21D4001B2850 /* XCRemoteSwiftPackageReference "SwiftMessages" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/SwiftKickMobile/SwiftMessages"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 10.0.0; + }; + }; 84D9CCC12B9708E4001EDEE3 /* XCRemoteSwiftPackageReference "Starscream" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/daltoniam/Starscream"; @@ -518,6 +534,16 @@ /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ + 84733CCC2C1B2134001B2850 /* Atlantis */ = { + isa = XCSwiftPackageProductDependency; + package = CFD6A70D2ADE8DE2002B402C /* XCRemoteSwiftPackageReference "atlantis" */; + productName = Atlantis; + }; + 84733CD12C1B21D4001B2850 /* SwiftMessages */ = { + isa = XCSwiftPackageProductDependency; + package = 84733CD02C1B21D4001B2850 /* XCRemoteSwiftPackageReference "SwiftMessages" */; + productName = SwiftMessages; + }; 84F3EFBD2BA87760005FCFAE /* Web3 */ = { isa = XCSwiftPackageProductDependency; package = 84F3EFBC2BA87760005FCFAE /* XCRemoteSwiftPackageReference "Web3" */; @@ -555,11 +581,6 @@ isa = XCSwiftPackageProductDependency; productName = Web3ModalUI; }; - CFD6A70E2ADE8DE2002B402C /* Atlantis */ = { - isa = XCSwiftPackageProductDependency; - package = CFD6A70D2ADE8DE2002B402C /* XCRemoteSwiftPackageReference "atlantis" */; - productName = Atlantis; - }; /* End XCSwiftPackageProductDependency section */ }; rootObject = CFD7206C2A9CC60600636CAF /* Project object */; diff --git a/Sample/Example/AlertPresenter.swift b/Sample/Example/AlertPresenter.swift new file mode 100644 index 0000000..5da5d46 --- /dev/null +++ b/Sample/Example/AlertPresenter.swift @@ -0,0 +1,35 @@ +import Foundation +import SwiftMessages +import UIKit + +struct AlertPresenter { + enum MessageType { + case warning + case error + case info + case success + } + + static func present(message: String, type: AlertPresenter.MessageType) { + DispatchQueue.main.async { + let view = MessageView.viewFromNib(layout: .cardView) + switch type { + case .warning: + view.configureTheme(.warning, iconStyle: .subtle) + case .error: + view.configureTheme(.error, iconStyle: .subtle) + case .info: + view.configureTheme(.info, iconStyle: .subtle) + case .success: + view.configureTheme(.success, iconStyle: .subtle) + } + view.button?.isHidden = true + view.layoutMarginAdditions = UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20) + view.configureContent(title: "", body: message) + var config = SwiftMessages.Config() + config.presentationStyle = .top + config.duration = .seconds(seconds: 1.5) + SwiftMessages.show(config: config, view: view) + } + } +} diff --git a/Sample/Example/ExampleApp.swift b/Sample/Example/ExampleApp.swift index 5dc234a..53fbdcd 100644 --- a/Sample/Example/ExampleApp.swift +++ b/Sample/Example/ExampleApp.swift @@ -90,6 +90,25 @@ class ExampleApp: App { Sign.instance.setLogging(level: .debug) Networking.instance.setLogging(level: .debug) Relay.instance.setLogging(level: .debug) + + Web3Modal.instance.authResponsePublisher.sink { (id: RPCID, result: Result<(Session?, [Cacao]), AuthError>) in + switch result { + case .success((_, _)): + AlertPresenter.present(message: "User authenticated", type: .success) + case .failure(let error): + AlertPresenter.present(message: "User authentication error: \(error)", type: .error) + + } + }.store(in: &disposeBag) + + Web3Modal.instance.SIWEAuthenticationPublisher.sink { result in + switch result { + case .success((let message, let signature)): + AlertPresenter.present(message: "User authenticated", type: .success) + case .failure(let error): + AlertPresenter.present(message: "User authentication error: \(error)", type: .error) + } + }.store(in: &disposeBag) } var body: some Scene { diff --git a/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift b/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift index 86dbecb..3ff7e76 100644 --- a/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift +++ b/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift @@ -255,6 +255,8 @@ class Web3ModalViewModel: ObservableObject { guard let self = self else { return } + Web3Modal.instance.SIWEAuthenticationPublisherSubject.send(.success((siweMessage, signature))) + DispatchQueue.main.async { self.router.setRoute(Router.AccountSubpage.profile) self.store.isModalShown = false diff --git a/Web3Modal.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Web3Modal.xcworkspace/xcshareddata/swiftpm/Package.resolved index 727a27c..340ec4a 100644 --- a/Web3Modal.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Web3Modal.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -99,6 +99,15 @@ "version" : "1.1.6" } }, + { + "identity" : "swiftmessages", + "kind" : "remoteSourceControl", + "location" : "https://github.com/SwiftKickMobile/SwiftMessages", + "state" : { + "revision" : "b899be48a61ddb209695a8d5e411189b704a7fa3", + "version" : "10.0.0" + } + }, { "identity" : "wallet-mobile-sdk", "kind" : "remoteSourceControl", From 9d8b464a3e8c37dd54ced12cf424884cc7ae1185 Mon Sep 17 00:00:00 2001 From: llbartekll Date: Thu, 13 Jun 2024 15:35:29 +0200 Subject: [PATCH 07/15] add disable authenticated sessions --- Sources/Web3Modal/Core/Web3Modal.swift | 1 + Sources/Web3Modal/Core/Web3ModalClient.swift | 10 ++++++++++ Sources/Web3Modal/Sheets/Web3ModalViewModel.swift | 12 +++++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Sources/Web3Modal/Core/Web3Modal.swift b/Sources/Web3Modal/Core/Web3Modal.swift index f5e3bed..8a11259 100644 --- a/Sources/Web3Modal/Core/Web3Modal.swift +++ b/Sources/Web3Modal/Core/Web3Modal.swift @@ -226,6 +226,7 @@ public class Web3Modal { try? await w3mApiInteractor.fetchWalletImages(for: [wallet]) } } + } #if canImport(UIKit) diff --git a/Sources/Web3Modal/Core/Web3ModalClient.swift b/Sources/Web3Modal/Core/Web3ModalClient.swift index 0ddf71c..beb84d0 100644 --- a/Sources/Web3Modal/Core/Web3ModalClient.swift +++ b/Sources/Web3Modal/Core/Web3ModalClient.swift @@ -376,4 +376,14 @@ public class Web3ModalClient { public func disableAnalytics() { analyticsService.disable() } + +#if DEBUG + public func disableAuthenticatedSessions() { + Web3Modal.viewModel.authenticatedSessionsDisabled = true + } + + public func enableAuthenticatedSessions() { + Web3Modal.viewModel.authenticatedSessionsDisabled = false + } +#endif } diff --git a/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift b/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift index 3ff7e76..be30efd 100644 --- a/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift +++ b/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift @@ -13,6 +13,9 @@ class Web3ModalViewModel: ObservableObject { private(set) var signInteractor: SignInteractor private(set) var blockchainApiInteractor: BlockchainAPIInteractor private let supportsAuthenticatedSession: Bool +#if DEBUG + var authenticatedSessionsDisabled = false +#endif private var disposeBag = Set() @@ -61,8 +64,15 @@ class Web3ModalViewModel: ObservableObject { signInteractor.sessionSettlePublisher .receive(on: DispatchQueue.main) - .sink { session in + .sink { [weak self] session in + guard let self = self else { return } self.handleNewSession(session: session) + #if DEBUG + if self.authenticatedSessionsDisabled { + self.routeToProfile() + return + } + #endif if supportsAuthenticatedSession { self.handleSIWEFallback() } else { From 5efac2f025d33be0fd522b1bb7bab6f07f772d58 Mon Sep 17 00:00:00 2001 From: llbartekll Date: Fri, 14 Jun 2024 12:05:52 +0200 Subject: [PATCH 08/15] upgrade sign version --- Package.swift | 2 +- Web3Modal.xcworkspace/xcshareddata/swiftpm/Package.resolved | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Package.swift b/Package.swift index 6317407..83563aa 100644 --- a/Package.swift +++ b/Package.swift @@ -21,7 +21,7 @@ let package = Package( dependencies: [ .package( url: "https://github.com/WalletConnect/WalletConnectSwiftV2", - .revision("997be80a6f86be4ba340ac8121acde24fc428520") + .upToNextMinor(from: "1.19.2") ), .package( url: "https://github.com/WalletConnect/QRCode", diff --git a/Web3Modal.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Web3Modal.xcworkspace/xcshareddata/swiftpm/Package.resolved index 340ec4a..178544f 100644 --- a/Web3Modal.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Web3Modal.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -122,7 +122,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/WalletConnect/WalletConnectSwiftV2", "state" : { - "revision" : "997be80a6f86be4ba340ac8121acde24fc428520" + "revision" : "4f8b44023cf9fc7ec75615658b979ec87f8845a5", + "version" : "1.19.2" } }, { From f38a7463ff26724fb0004c4ee6574ecce6a5ecde Mon Sep 17 00:00:00 2001 From: llbartekll Date: Fri, 14 Jun 2024 12:42:19 +0200 Subject: [PATCH 09/15] allow disableAuthenticatedSessions in all configurations --- Sample/Example/ExampleApp.swift | 1 + Sources/Web3Modal/Core/Web3ModalClient.swift | 11 ++++++----- Sources/Web3Modal/Sheets/Web3ModalViewModel.swift | 7 +------ 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/Sample/Example/ExampleApp.swift b/Sample/Example/ExampleApp.swift index 53fbdcd..d4f4ee2 100644 --- a/Sample/Example/ExampleApp.swift +++ b/Sample/Example/ExampleApp.swift @@ -109,6 +109,7 @@ class ExampleApp: App { AlertPresenter.present(message: "User authentication error: \(error)", type: .error) } }.store(in: &disposeBag) + Web3Modal.instance.disableAuthenticatedSessions() } var body: some Scene { diff --git a/Sources/Web3Modal/Core/Web3ModalClient.swift b/Sources/Web3Modal/Core/Web3ModalClient.swift index beb84d0..4881b42 100644 --- a/Sources/Web3Modal/Core/Web3ModalClient.swift +++ b/Sources/Web3Modal/Core/Web3ModalClient.swift @@ -86,6 +86,8 @@ public class Web3ModalClient { internal let SIWEAuthenticationPublisherSubject = PassthroughSubject, Never>() + internal var authenticatedSessionsDisabled = false + // MARK: - Private Properties private let signClient: SignClient @@ -130,7 +132,8 @@ public class Web3ModalClient { public func connect(walletUniversalLink: String?) async throws -> WalletConnectURI? { logger.debug("Connecting Application") do { - if let authParams = Web3Modal.config.authRequestParams { + if let authParams = Web3Modal.config.authRequestParams, + !authenticatedSessionsDisabled { return try await signClient.authenticate(authParams, walletUniversalLink: walletUniversalLink) } else { let pairingURI = try await pairingClient.create() @@ -377,13 +380,11 @@ public class Web3ModalClient { analyticsService.disable() } -#if DEBUG public func disableAuthenticatedSessions() { - Web3Modal.viewModel.authenticatedSessionsDisabled = true + authenticatedSessionsDisabled = true } public func enableAuthenticatedSessions() { - Web3Modal.viewModel.authenticatedSessionsDisabled = false + authenticatedSessionsDisabled = false } -#endif } diff --git a/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift b/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift index be30efd..4e1fcbd 100644 --- a/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift +++ b/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift @@ -13,9 +13,6 @@ class Web3ModalViewModel: ObservableObject { private(set) var signInteractor: SignInteractor private(set) var blockchainApiInteractor: BlockchainAPIInteractor private let supportsAuthenticatedSession: Bool -#if DEBUG - var authenticatedSessionsDisabled = false -#endif private var disposeBag = Set() @@ -67,12 +64,10 @@ class Web3ModalViewModel: ObservableObject { .sink { [weak self] session in guard let self = self else { return } self.handleNewSession(session: session) - #if DEBUG - if self.authenticatedSessionsDisabled { + if Web3Modal.instance.authenticatedSessionsDisabled { self.routeToProfile() return } - #endif if supportsAuthenticatedSession { self.handleSIWEFallback() } else { From 143594fa0e1473ee9c0a9f9fb4e78407ecfbb139 Mon Sep 17 00:00:00 2001 From: llbartekll Date: Fri, 14 Jun 2024 13:03:11 +0200 Subject: [PATCH 10/15] remove authenticatedSessionsDisabled --- Sample/Example/ExampleApp.swift | 1 - Sources/Web3Modal/Core/Web3ModalClient.swift | 13 +------------ Sources/Web3Modal/Sheets/Web3ModalViewModel.swift | 4 ---- 3 files changed, 1 insertion(+), 17 deletions(-) diff --git a/Sample/Example/ExampleApp.swift b/Sample/Example/ExampleApp.swift index d4f4ee2..53fbdcd 100644 --- a/Sample/Example/ExampleApp.swift +++ b/Sample/Example/ExampleApp.swift @@ -109,7 +109,6 @@ class ExampleApp: App { AlertPresenter.present(message: "User authentication error: \(error)", type: .error) } }.store(in: &disposeBag) - Web3Modal.instance.disableAuthenticatedSessions() } var body: some Scene { diff --git a/Sources/Web3Modal/Core/Web3ModalClient.swift b/Sources/Web3Modal/Core/Web3ModalClient.swift index 4881b42..0ddf71c 100644 --- a/Sources/Web3Modal/Core/Web3ModalClient.swift +++ b/Sources/Web3Modal/Core/Web3ModalClient.swift @@ -86,8 +86,6 @@ public class Web3ModalClient { internal let SIWEAuthenticationPublisherSubject = PassthroughSubject, Never>() - internal var authenticatedSessionsDisabled = false - // MARK: - Private Properties private let signClient: SignClient @@ -132,8 +130,7 @@ public class Web3ModalClient { public func connect(walletUniversalLink: String?) async throws -> WalletConnectURI? { logger.debug("Connecting Application") do { - if let authParams = Web3Modal.config.authRequestParams, - !authenticatedSessionsDisabled { + if let authParams = Web3Modal.config.authRequestParams { return try await signClient.authenticate(authParams, walletUniversalLink: walletUniversalLink) } else { let pairingURI = try await pairingClient.create() @@ -379,12 +376,4 @@ public class Web3ModalClient { public func disableAnalytics() { analyticsService.disable() } - - public func disableAuthenticatedSessions() { - authenticatedSessionsDisabled = true - } - - public func enableAuthenticatedSessions() { - authenticatedSessionsDisabled = false - } } diff --git a/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift b/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift index 4e1fcbd..84d2559 100644 --- a/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift +++ b/Sources/Web3Modal/Sheets/Web3ModalViewModel.swift @@ -64,10 +64,6 @@ class Web3ModalViewModel: ObservableObject { .sink { [weak self] session in guard let self = self else { return } self.handleNewSession(session: session) - if Web3Modal.instance.authenticatedSessionsDisabled { - self.routeToProfile() - return - } if supportsAuthenticatedSession { self.handleSIWEFallback() } else { From 25abd7e5471f21d662400f9763948fbf97c60c97 Mon Sep 17 00:00:00 2001 From: llbartekll Date: Fri, 14 Jun 2024 13:07:34 +0200 Subject: [PATCH 11/15] disable 1ca --- Sample/Example/ExampleApp.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sample/Example/ExampleApp.swift b/Sample/Example/ExampleApp.swift index 53fbdcd..beeb9fe 100644 --- a/Sample/Example/ExampleApp.swift +++ b/Sample/Example/ExampleApp.swift @@ -58,7 +58,7 @@ class ExampleApp: App { projectId: projectId, metadata: metadata, crypto: DefaultCryptoProvider(), - authRequestParams: .stub(), + authRequestParams: nil, customWallets: [ .init( id: "swift-sample", From 93f0ff3807904e34b1f6eabf6ea312f8cb631e60 Mon Sep 17 00:00:00 2001 From: llbartekll Date: Wed, 19 Jun 2024 08:50:42 +0200 Subject: [PATCH 12/15] disable ui tests --- Sample/swift-web3modal-Package.xctestplan | 1 + 1 file changed, 1 insertion(+) diff --git a/Sample/swift-web3modal-Package.xctestplan b/Sample/swift-web3modal-Package.xctestplan index dd3dc38..658b59d 100644 --- a/Sample/swift-web3modal-Package.xctestplan +++ b/Sample/swift-web3modal-Package.xctestplan @@ -33,6 +33,7 @@ } }, { + "enabled" : false, "target" : { "containerPath" : "container:", "identifier" : "Web3ModalUITests", From e0c0091f6df942b6e1f3ee6630606b1569bb2a22 Mon Sep 17 00:00:00 2001 From: llbartekll Date: Wed, 19 Jun 2024 09:38:16 +0200 Subject: [PATCH 13/15] disable tests --- Sample/swift-web3modal-Package.xctestplan | 1 + 1 file changed, 1 insertion(+) diff --git a/Sample/swift-web3modal-Package.xctestplan b/Sample/swift-web3modal-Package.xctestplan index 658b59d..f726107 100644 --- a/Sample/swift-web3modal-Package.xctestplan +++ b/Sample/swift-web3modal-Package.xctestplan @@ -26,6 +26,7 @@ }, "testTargets" : [ { + "enabled" : false, "target" : { "containerPath" : "container:", "identifier" : "Web3ModalTests", From 9756dd2a36f6b1f7a1df2a1187f17618464d903c Mon Sep 17 00:00:00 2001 From: llbartekll Date: Wed, 19 Jun 2024 10:05:12 +0200 Subject: [PATCH 14/15] disable tests --- .github/workflows/ci.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9671466..78ebb05 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,8 +16,8 @@ jobs: timeout-minutes: 15 strategy: fail-fast: false - matrix: - type: [unit-tests] + # matrix: + # type: [unit-tests] steps: - uses: actions/checkout@v3 @@ -25,15 +25,15 @@ jobs: ref: ${{ github.event.pull_request.head.sha }} # Package Unit tests - - name: Run tests - if: matrix.type == 'unit-tests' - shell: bash - run: make unit_tests + # - name: Run tests + # if: matrix.type == 'unit-tests' + # shell: bash + # run: make unit_tests # - name: Danger # env: # DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} -# run: +# run: # rm -rf xcov_report | # /opt/homebrew/opt/ruby/bin/bundle install | # /opt/homebrew/opt/ruby/bin/bundle exec danger @@ -42,7 +42,7 @@ jobs: uses: mikepenz/action-junit-report@v3 if: success() || failure() with: - check_name: ${{ matrix.type }} junit report + check_name: junit report report_paths: 'test_results/report.junit' - name: Zip test artifacts @@ -54,6 +54,6 @@ jobs: if: always() uses: actions/upload-artifact@v3 with: - name: ${{ matrix.type }} test_results + name: test_results path: ./artifacts.zip if-no-files-found: warn From 591f0f26286d76d717e72456cf653568bc64bfc0 Mon Sep 17 00:00:00 2001 From: llbartekll Date: Thu, 20 Jun 2024 13:36:25 +0200 Subject: [PATCH 15/15] update dependency version --- Package.swift | 2 +- Web3Modal.xcworkspace/xcshareddata/swiftpm/Package.resolved | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Package.swift b/Package.swift index 83563aa..bd3a704 100644 --- a/Package.swift +++ b/Package.swift @@ -21,7 +21,7 @@ let package = Package( dependencies: [ .package( url: "https://github.com/WalletConnect/WalletConnectSwiftV2", - .upToNextMinor(from: "1.19.2") + .upToNextMinor(from: "1.19.3") ), .package( url: "https://github.com/WalletConnect/QRCode", diff --git a/Web3Modal.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Web3Modal.xcworkspace/xcshareddata/swiftpm/Package.resolved index 178544f..e52549b 100644 --- a/Web3Modal.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Web3Modal.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -122,8 +122,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/WalletConnect/WalletConnectSwiftV2", "state" : { - "revision" : "4f8b44023cf9fc7ec75615658b979ec87f8845a5", - "version" : "1.19.2" + "revision" : "8ab4897841a5d04b832f2010a542a246be37998d", + "version" : "1.19.3" } }, {