Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

siwe fallback #77

Merged
merged 15 commits into from
Jun 20, 2024
18 changes: 9 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@ jobs:
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
type: [unit-tests]
# matrix:
# type: [unit-tests]

steps:
- uses: actions/checkout@v3
with:
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:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SupernLucky

# 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
Expand All @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let package = Package(
dependencies: [
.package(
url: "https://github.com/WalletConnect/WalletConnectSwiftV2",
.upToNextMinor(from: "1.19.1")
.upToNextMinor(from: "1.19.3")
),
.package(
url: "https://github.com/WalletConnect/QRCode",
Expand Down
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)
}
}
}
21 changes: 20 additions & 1 deletion Sample/Example/ExampleApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ExampleApp: App {
projectId: projectId,
metadata: metadata,
crypto: DefaultCryptoProvider(),
authRequestParams: .stub(),
authRequestParams: nil,
customWallets: [
.init(
id: "swift-sample",
Expand Down 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 Sample/swift-web3modal-Package.xctestplan
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
},
"testTargets" : [
{
"enabled" : false,
"target" : {
"containerPath" : "container:",
"identifier" : "Web3ModalTests",
"name" : "Web3ModalTests"
}
},
{
"enabled" : false,
"target" : {
"containerPath" : "container:",
"identifier" : "Web3ModalUITests",
Expand Down
4 changes: 3 additions & 1 deletion Sources/Web3Modal/Core/Web3Modal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ public class Web3Modal {
store: store,
w3mApiInteractor: w3mApiInteractor,
signInteractor: signInteractor,
blockchainApiInteractor: blockchainApiInteractor
blockchainApiInteractor: blockchainApiInteractor,
supportsAuthenticatedSession: (config.authRequestParams != nil)
)

Task {
Expand Down Expand Up @@ -225,6 +226,7 @@ public class Web3Modal {
try? await w3mApiInteractor.fetchWalletImages(for: [wallet])
}
}

}

#if canImport(UIKit)
Expand Down
6 changes: 6 additions & 0 deletions Sources/Web3Modal/Core/Web3ModalClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ public class Web3ModalClient {
return analyticsService.isAnalyticsEnabled
}

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

private let signClient: SignClient
Expand Down
Loading
Loading