Skip to content

Commit

Permalink
adds alerts on authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
llbartekll committed Jun 13, 2024
1 parent a6e7b85 commit e0d14d9
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 8 deletions.
37 changes: 29 additions & 8 deletions Sample/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand All @@ -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 */; };
Expand All @@ -27,6 +29,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
84871D562C1B1E58005C1B50 /* AlertPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertPresenter.swift; sourceTree = "<group>"; };
84F3EFBA2BA86FA6005FCFAE /* DefaultCryptoProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultCryptoProvider.swift; sourceTree = "<group>"; };
CF0BCCE42AB0886400A2866C /* ContentView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
CF533D032ADD411A00B3441C /* web3modal-swift */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = "web3modal-swift"; path = ..; sourceTree = "<group>"; };
Expand All @@ -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;
};
Expand Down Expand Up @@ -96,6 +100,7 @@
CFD7207D2A9CC60700636CAF /* Example.entitlements */,
CFD7207E2A9CC60700636CAF /* Preview Content */,
CFEAAF092B6C0B3A001565F5 /* InputConfig.swift */,
84871D562C1B1E58005C1B50 /* AlertPresenter.swift */,
);
path = Example;
sourceTree = "<group>";
Expand Down Expand Up @@ -134,14 +139,15 @@
name = Example;
packageProductDependencies = (
CF3B9AD12ACDBA3A00984D53 /* Web3ModalUI */,
CFD6A70E2ADE8DE2002B402C /* Atlantis */,
BD206AA550964C49AE94A3CA /* Sentry */,
CF25F3A12B40C7070030B3DC /* Web3Modal */,
CF25F3A32B40C7070030B3DC /* Web3ModalUI */,
84F3EFBD2BA87760005FCFAE /* Web3 */,
84F3EFBF2BA87760005FCFAE /* Web3ContractABI */,
84F3EFC12BA87760005FCFAE /* Web3PromiseKit */,
84FEB1372C0DAE210018CB53 /* Starscream */,
84733CCC2C1B2134001B2850 /* Atlantis */,
84733CD12C1B21D4001B2850 /* SwiftMessages */,
);
productName = Example;
productReference = CFD720742A9CC60600636CAF /* Example.app */;
Expand Down Expand Up @@ -177,6 +183,7 @@
F4A0329B6CFF49E682D3DFE7 /* XCRemoteSwiftPackageReference "sentry-cocoa" */,
84D9CCC12B9708E4001EDEE3 /* XCRemoteSwiftPackageReference "Starscream" */,
84F3EFBC2BA87760005FCFAE /* XCRemoteSwiftPackageReference "Web3" */,
84733CD02C1B21D4001B2850 /* XCRemoteSwiftPackageReference "SwiftMessages" */,
);
productRefGroup = CFD720752A9CC60600636CAF /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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" */;
Expand Down Expand Up @@ -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 */;
Expand Down
35 changes: 35 additions & 0 deletions Sample/Example/AlertPresenter.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
19 changes: 19 additions & 0 deletions Sample/Example/ExampleApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions Sources/Web3Modal/Sheets/Web3ModalViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions Web3Modal.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit e0d14d9

Please sign in to comment.