Skip to content

Commit

Permalink
Merge pull request #81 from WalletConnect/1click-auth
Browse files Browse the repository at this point in the history
siwe deeplink without pairing uri
  • Loading branch information
llbartekll authored Jul 23, 2024
2 parents 5d148bf + af286d3 commit d35349c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Sample/Example/ExampleApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -168,3 +168,4 @@ extension AuthRequestParams {
)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -102,7 +102,7 @@ class WalletDetailViewModel: ObservableObject {

if wallet.alternativeConnectionMethod == nil {

navigateToDeepLink(
navigateToWalletWithPairingUri(
wallet: wallet,
preferBrowser: preferredPlatform == .browser
)
Expand All @@ -118,7 +118,7 @@ class WalletDetailViewModel: ObservableObject {
store.retryShown = false

if wallet.alternativeConnectionMethod == nil {
navigateToDeepLink(
navigateToWalletWithPairingUri(
wallet: wallet,
preferBrowser: preferredPlatform == .browser
)
Expand All @@ -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

Expand Down

0 comments on commit d35349c

Please sign in to comment.