Skip to content

Commit

Permalink
Simplify, add some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nakajima committed Sep 25, 2023
1 parent eaa46a2 commit b9f1dd7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
2 changes: 1 addition & 1 deletion XMTPiOSExample/XMTPiOSExample/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct ContentView: View {
case .unknown:
Button("Connect Wallet") { isConnectingWallet = true }
.sheet(isPresented: $isConnectingWallet) {
LoginView(onTryDemo: {}, onConnecting: {}, onConnected: { client in
LoginView(onConnected: { client in
do {
let keysData = try client.privateKeyBundle.serializedData()
Persistence().saveKeys(keysData)
Expand Down
18 changes: 5 additions & 13 deletions XMTPiOSExample/XMTPiOSExample/Views/LoginView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ struct SocketFactory: WebSocketFactory {
}
}

// WalletConnectV2's ModalSheet doesn't have any public initializers so we need
// to wrap their UIKit API
struct ModalWrapper: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> UIViewController {
let controller = UIViewController()
Expand All @@ -39,6 +41,7 @@ struct ModalWrapper: UIViewControllerRepresentable {
}
}

// Conformance to XMTP iOS's SigningKey protocol
class Signer: SigningKey {
var account: WalletConnectUtils.Account
var session: WalletConnectSign.Session
Expand All @@ -51,18 +54,13 @@ class Signer: SigningKey {
self.session = session
self.account = account
self.cancellable = Sign.instance.sessionResponsePublisher.sink { response in
print("RESPONSE: \(response)")

guard case let .response(codable) = response.result else {
print("NO RESPONSE")
return
}

let signatureData = Data(hexString: codable.value as! String)
print("SIGNATURE DATA: \(signatureData)")
print("GOT A RESPONSE: \(response) signature: \(signatureData)")

let signature = Signature(bytes: signatureData[0..<64], recovery: Int(signatureData[64]))

self.continuation?.resume(returning: signature)
self.continuation = nil
}
Expand Down Expand Up @@ -105,21 +103,15 @@ class Signer: SigningKey {
}

struct LoginView: View {
var onTryDemo: () -> Void
var onConnecting: () -> Void
var onConnected: (Client) -> Void
var publishers: [AnyCancellable] = []

@State private var isShowingWebview = true

init(
onTryDemo: @escaping () -> Void,
onConnecting: @escaping () -> Void,
onConnected: @escaping (Client) -> Void
) {
self.onTryDemo = onTryDemo
self.onConnected = onConnected
self.onConnecting = onConnecting

Networking.configure(
projectId: "YOUR PROJECT ID",
Expand Down Expand Up @@ -183,5 +175,5 @@ struct LoginView: View {
}

#Preview {
LoginView(onTryDemo: {}, onConnecting: {}, onConnected: { _ in })
LoginView(onConnected: { _ in })
}

0 comments on commit b9f1dd7

Please sign in to comment.