From af286d37d925fab8a14b189d0fb32108c3bd647a Mon Sep 17 00:00:00 2001 From: llbartekll Date: Tue, 23 Jul 2024 20:41:14 +0900 Subject: [PATCH] siwe deeplink without pairing uri --- Sample/Example/ExampleApp.swift | 3 ++- .../WalletDetail/WalletDetailViewModel.swift | 26 +++++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Sample/Example/ExampleApp.swift b/Sample/Example/ExampleApp.swift index beeb9fe..7f32828 100644 --- a/Sample/Example/ExampleApp.swift +++ b/Sample/Example/ExampleApp.swift @@ -58,7 +58,7 @@ class ExampleApp: App { projectId: projectId, metadata: metadata, crypto: DefaultCryptoProvider(), - authRequestParams: nil, + authRequestParams: nil, // use .stab() for testing SIWE customWallets: [ .init( id: "swift-sample", @@ -168,3 +168,4 @@ extension AuthRequestParams { ) } } + diff --git a/Sources/Web3Modal/Screens/ConnectWallet/WalletDetail/WalletDetailViewModel.swift b/Sources/Web3Modal/Screens/ConnectWallet/WalletDetail/WalletDetailViewModel.swift index 5b475e8..0018b52 100644 --- a/Sources/Web3Modal/Screens/ConnectWallet/WalletDetail/WalletDetailViewModel.swift +++ b/Sources/Web3Modal/Screens/ConnectWallet/WalletDetail/WalletDetailViewModel.swift @@ -86,7 +86,7 @@ class WalletDetailViewModel: ObservableObject { DispatchQueue.main.async { [weak self] in guard let self = self else { return } - self.navigateToDeepLink( + self.navigateToWallet( wallet: self.wallet, preferBrowser: preferredPlatform == .browser ) @@ -102,7 +102,7 @@ class WalletDetailViewModel: ObservableObject { if wallet.alternativeConnectionMethod == nil { - navigateToDeepLink( + navigateToWalletWithPairingUri( wallet: wallet, preferBrowser: preferredPlatform == .browser ) @@ -118,7 +118,7 @@ class WalletDetailViewModel: ObservableObject { store.retryShown = false if wallet.alternativeConnectionMethod == nil { - navigateToDeepLink( + navigateToWalletWithPairingUri( wallet: wallet, preferBrowser: preferredPlatform == .browser ) @@ -139,8 +139,24 @@ class WalletDetailViewModel: ObservableObject { router.openURL(storeLink) } - - private func navigateToDeepLink(wallet: Wallet, preferBrowser: Bool) { + + private func navigateToWallet(wallet: Wallet, preferBrowser: Bool) { + do { + let link = preferBrowser ? wallet.webappLink : wallet.mobileLink + if let url = link?.toURL() { + router.openURL(url) { success in + self.store.toast = .init(style: .error, message: DeeplinkErrors.failedToOpen.localizedDescription) + } + } else { + throw DeeplinkErrors.noWalletLinkFound + } + } catch { + store.toast = .init(style: .error, message: error.localizedDescription) + Web3Modal.config.onError(error) + } + } + + private func navigateToWalletWithPairingUri(wallet: Wallet, preferBrowser: Bool) { do { let link = preferBrowser ? wallet.webappLink : wallet.mobileLink