Skip to content

Commit

Permalink
savepoint
Browse files Browse the repository at this point in the history
  • Loading branch information
llbartekll committed Jun 18, 2024
1 parent 9db4bc8 commit 891073a
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 49 deletions.
110 changes: 62 additions & 48 deletions Example/DApp/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,68 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
}

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
configureClientsIfNeeded()
setUpProfilingIfNeeded()
ProfilingService.instance.send(logMessage: .init(message: "SceneDelegate: willConnectTo : \(String(describing: connectionOptions.userActivities.first?.webpageURL?.absoluteString))"))

configureClientsIfNeeded()
setUpProfilingIfNeeded()


setupWindow(scene: scene)
}

private func setupWindow(scene: UIScene) {
guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: windowScene)

let viewController = SignModule.create(app: app)
.wrapToNavigationController()

window?.rootViewController = viewController
window?.makeKeyAndVisible()
}

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
ProfilingService.instance.send(logMessage: .init(message: "SceneDelegate: - openURLContexts : \(String(describing: URLContexts.first?.url))"))

guard let context = URLContexts.first else { return }

let url = context.url

guard let components = URLComponents(url: url, resolvingAgainstBaseURL: false),
let queryItems = components.queryItems,
queryItems.contains(where: { $0.name == "wc_ev" }) else {
return
}

do {
try Sign.instance.dispatchEnvelope(url.absoluteString)
} catch {
AlertPresenter.present(message: error.localizedDescription, type: .error)
}
}

func sceneWillEnterForeground(_ scene: UIScene) {
ProfilingService.instance.send(logMessage: .init(message: "SceneDelegate: scene will enter foreground"))
// Additional code to handle entering the foreground
}

func sceneDidBecomeActive(_ scene: UIScene) {
ProfilingService.instance.send(logMessage: .init(message: "SceneDelegate: scene did become active"))
// Additional code to handle becoming active
}

private func setUpProfilingIfNeeded() {
if let clientId = try? Networking.interactor.getClientId() {
ProfilingService.instance.setUpProfiling(account: "swift_dapp_\(clientId)", clientId: clientId)
}
}

var clientsConfigured = false
private func configureClientsIfNeeded() {
if clientsConfigured {return}
else {clientsConfigured = true}
Networking.configure(
groupIdentifier: Constants.groupIdentifier,
projectId: InputConfig.projectId,
Expand All @@ -43,7 +103,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
icons: ["https://avatars.githubusercontent.com/u/37784886"],
redirect: try! AppMetadata.Redirect(native: "wcdapp://", universal: "https://lab.web3modal.com/dapp", linkMode: true)
)

Web3Modal.configure(
projectId: InputConfig.projectId,
metadata: metadata,
Expand All @@ -60,10 +120,6 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
)
]
)

if let clientId = try? Networking.interactor.getClientId() {
ProfilingService.instance.setUpProfiling(account: "swift_dapp_\(clientId)", clientId: clientId)
}

Web3Modal.instance.authResponsePublisher.sink { (id, result) in
switch result {
Expand All @@ -78,7 +134,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
projectId: InputConfig.projectId,
metadata: metadata
)

Sign.instance.logger.setLogging(level: .debug)
Networking.instance.setLogging(level: .debug)

Expand All @@ -100,47 +156,5 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
}.store(in: &publishers)

Web3Modal.instance.disableAnalytics()
setupWindow(scene: scene)
}

private func setupWindow(scene: UIScene) {
guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: windowScene)

let viewController = SignModule.create(app: app)
.wrapToNavigationController()

window?.rootViewController = viewController
window?.makeKeyAndVisible()
}

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
ProfilingService.instance.send(logMessage: .init(message: "SceneDelegate: - openURLContexts : \(String(describing: URLContexts.first?.url))"))

guard let context = URLContexts.first else { return }

let url = context.url

guard let components = URLComponents(url: url, resolvingAgainstBaseURL: false),
let queryItems = components.queryItems,
queryItems.contains(where: { $0.name == "wc_ev" }) else {
return
}

do {
try Sign.instance.dispatchEnvelope(url.absoluteString)
} catch {
AlertPresenter.present(message: error.localizedDescription, type: .error)
}
}

func sceneWillEnterForeground(_ scene: UIScene) {
ProfilingService.instance.send(logMessage: .init(message: "SceneDelegate: scene will enter foreground"))
// Additional code to handle entering the foreground
}

func sceneDidBecomeActive(_ scene: UIScene) {
ProfilingService.instance.send(logMessage: .init(message: "SceneDelegate: scene did become active"))
// Additional code to handle becoming active
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ final class AuthRequestPresenter: ObservableObject {

/* Redirect */
if let uri = request.requester.redirect?.native {
WalletConnectRouter.goBack(uri: uri)
// WalletConnectRouter.goBack(uri: uri)
router.dismiss()
} else {
showSignedSheet.toggle()
Expand Down

0 comments on commit 891073a

Please sign in to comment.