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