diff --git a/example/Assets.xcassets/x.imageset/Contents.json b/example/Assets.xcassets/x.imageset/Contents.json new file mode 100644 index 0000000..0eaff71 --- /dev/null +++ b/example/Assets.xcassets/x.imageset/Contents.json @@ -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 + } +} diff --git a/example/Assets.xcassets/x.imageset/logo-white.png b/example/Assets.xcassets/x.imageset/logo-white.png new file mode 100644 index 0000000..2609e58 Binary files /dev/null and b/example/Assets.xcassets/x.imageset/logo-white.png differ diff --git a/example/Auth/ExternalWalletAuthView.swift b/example/Auth/ExternalWalletAuthView.swift index 0977733..8b1a305 100644 --- a/example/Auth/ExternalWalletAuthView.swift +++ b/example/Auth/ExternalWalletAuthView.swift @@ -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 @@ -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 diff --git a/example/Auth/MetaMaskDemoView.swift b/example/Auth/MetaMaskDemoView.swift index 1377e3a..765cdf9 100644 --- a/example/Auth/MetaMaskDemoView.swift +++ b/example/Auth/MetaMaskDemoView.swift @@ -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)? @@ -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") @@ -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 @@ -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")) } } diff --git a/example/Auth/OAuthView.swift b/example/Auth/OAuthView.swift index 97e5a65..01541ea 100644 --- a/example/Auth/OAuthView.swift +++ b/example/Auth/OAuthView.swift @@ -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) } @@ -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) } @@ -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) { }