Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions example/Assets.xcassets/x.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "logo-white.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 16 additions & 1 deletion example/Auth/ExternalWalletAuthView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ struct ExternalWalletAuthView: View {
@EnvironmentObject private var appRootManager: AppRootManager
@EnvironmentObject private var metaMaskConnector: MetaMaskConnector

@Environment(\.authorizationController) private var authorizationController

@State private var isConnecting = false
@State private var error: Error?
@State private var showError = false
Expand Down Expand Up @@ -61,7 +63,20 @@ struct ExternalWalletAuthView: View {

Task {
do {
try await metaMaskConnector.connect()
let res = try await metaMaskConnector.connect()
let userExists = res["userExists"] as! Bool
let userId = res["userId"] as! String
let signatureVerificationMessage = res["signatureVerificationMessage"] as! String

if !userExists {
let signedMessage = try await metaMaskConnector.signMessage(signatureVerificationMessage, account: metaMaskConnector.accounts.first!)
let biometricsId = try await paraManager.verifyExternalWallet(signedMessage: signedMessage)
try await paraManager.generatePasskey(identifier: metaMaskConnector.accounts.first!, biometricsId: biometricsId, authorizationController: authorizationController)
} else {
try await paraManager.login(authorizationController: authorizationController, authInfo: metaMaskConnector.authInfo)
print("Logged In")
}

showMetaMask = true
} catch {
self.error = error
Expand Down
19 changes: 19 additions & 0 deletions example/Auth/MetaMaskDemoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import Web3Core

struct MetaMaskDemoView: View {
@EnvironmentObject private var metaMaskConnector: MetaMaskConnector
@EnvironmentObject private var paraManager: ParaManager

@State private var isLoading = false
@State private var alert: (title: String, message: String)?

Expand All @@ -37,6 +39,13 @@ struct MetaMaskDemoView: View {
.buttonStyle(.borderedProminent)
.controlSize(.large)
.tint(.orange)

Button("Export Session") {
Task { await exportSession() }
}
.buttonStyle(.borderedProminent)
.controlSize(.large)
.tint(.orange)
}
.padding()
.navigationTitle("MetaMask Wallet")
Expand All @@ -51,6 +60,15 @@ struct MetaMaskDemoView: View {
}
}

private func exportSession() async {
do {
let exportedSession = try await paraManager.exportSession()
alert = ("Success", "Exported Session: \(exportedSession)")
} catch {
alert = ("Error", error.localizedDescription)
}
}

private func signMessage() async {
guard let account = metaMaskConnector.accounts.first else { return }
isLoading = true
Expand Down Expand Up @@ -96,5 +114,6 @@ struct MetaMaskDemoView: View {
appUrl: "https://example.com",
config: MetaMaskConfig(appName: "Example App", appId: "example-app")
))
.environmentObject(ParaManager(environment: .sandbox, apiKey: "preview-key"))
}
}
43 changes: 40 additions & 3 deletions example/Auth/OAuthView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ struct OAuthView: View {
Image(.google)
.resizable()
.frame(width: 24, height: 24)
Text("Login with Google")
Text("Continue with Google")
.fontWeight(.semibold)
Spacer()
}
.frame(maxWidth: .infinity)
}
Expand All @@ -73,8 +74,9 @@ struct OAuthView: View {
Image(.discord)
.resizable()
.frame(width: 24, height: 20)
Text("Login with Discord")
Text("Continue with Discord")
.fontWeight(.semibold)
Spacer()
}
.frame(maxWidth: .infinity)
}
Expand All @@ -89,13 +91,48 @@ struct OAuthView: View {
Image(.apple)
.resizable()
.frame(width: 24, height: 24)
Text("Login with Apple")
Text("Continue with Apple")
.fontWeight(.semibold)
Spacer()
}
.frame(maxWidth: .infinity)
}
.buttonStyle(.borderedProminent)
.controlSize(.large)

Button {
login(provider: .twitter)
} label: {
HStack(spacing: 15) {
Image(.x)
.resizable()
.frame(width: 24, height: 24)
Text("Continue with X")
.fontWeight(.semibold)
Spacer()
}
.frame(maxWidth: .infinity)
}
.buttonStyle(.borderedProminent)
.controlSize(.large)
.tint(Color(uiColor: UIColor(rgb: 0xFF1DA1F2)))

Button {
login(provider: .facebook)
} label: {
HStack(spacing: 15) {
Image(.discord)
.resizable()
.frame(width: 24, height: 20)
Text("Continue with Facebook")
.fontWeight(.semibold)
Spacer()
}
.frame(maxWidth: .infinity)
}
.buttonStyle(.borderedProminent)
.controlSize(.large)
.tint(Color(uiColor: UIColor(rgb: 0x5865F2)))
}
.alert("Connection Error", isPresented: $showError) {
Button("OK", role: .cancel) { }
Expand Down