Skip to content

Commit

Permalink
add siwe publishers
Browse files Browse the repository at this point in the history
  • Loading branch information
llbartekll committed Jun 13, 2024
1 parent be72b87 commit a6e7b85
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Sources/Web3Modal/Core/Web3ModalClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ public class Web3ModalClient {
return analyticsService.isAnalyticsEnabled
}

// add user authenticated publisher authResponsePublisher+SIWE
public var SIWEAuthenticationPublisher: AnyPublisher<Result<(message: String, signature: String), SIWEAuthenticationError>, Never> {
return SIWEAuthenticationPublisherSubject.eraseToAnyPublisher()
}

internal let SIWEAuthenticationPublisherSubject = PassthroughSubject<Result<(message: String, signature: String), SIWEAuthenticationError>, Never>()

// MARK: - Private Properties

Expand Down
20 changes: 18 additions & 2 deletions Sources/Web3Modal/Sheets/Web3ModalViewModel.swift
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a6e7b85

Please sign in to comment.