diff --git a/UnstoppableWallet/UnstoppableWallet/Core/Managers/DeepLinkManager.swift b/UnstoppableWallet/UnstoppableWallet/Core/Managers/DeepLinkManager.swift index ce0fccb158..d89422013c 100644 --- a/UnstoppableWallet/UnstoppableWallet/Core/Managers/DeepLinkManager.swift +++ b/UnstoppableWallet/UnstoppableWallet/Core/Managers/DeepLinkManager.swift @@ -1,37 +1,47 @@ import Foundation -import RxSwift import RxRelay +import RxSwift class DeepLinkManager { private let newSchemeRelay = BehaviorRelay(value: nil) } extension DeepLinkManager { + var newSchemeObservable: Observable { + newSchemeRelay.asObservable() + } func handle(url: URL) -> Bool { - guard let queryItems = URLComponents(url: url, resolvingAgainstBaseURL: true)?.queryItems, let uri = queryItems.first(where: { $0.name == "uri" })?.value else { + guard let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: true) else { return false } - if url.scheme == "unstoppable.money" || url.scheme == "https" { + let scheme = urlComponents.scheme + let host = urlComponents.host + let path = urlComponents.path + let queryItems = urlComponents.queryItems + + if (scheme == "unstoppable.money" && host == "wc") || (scheme == "https" && host == "unstoppable.money" && path == "/wc"), + let uri = queryItems?.first(where: { $0.name == "uri" })?.value + { newSchemeRelay.accept(.walletConnect(url: uri)) + return true + } + if scheme == "unstoppable.money" && host == "coin" { + let uid = path.replacingOccurrences(of: "/", with: "") + + newSchemeRelay.accept(.coin(uid: uid)) return true } return false } - - var newSchemeObservable: Observable { - newSchemeRelay.asObservable() - } - } extension DeepLinkManager { - enum DeepLink { case walletConnect(url: String) + case coin(uid: String) } - } diff --git a/UnstoppableWallet/Widget/CoinPriceList/CoinPriceListView.swift b/UnstoppableWallet/Widget/CoinPriceList/CoinPriceListView.swift index d0188049bc..59ab2c4b39 100644 --- a/UnstoppableWallet/Widget/CoinPriceList/CoinPriceListView.swift +++ b/UnstoppableWallet/Widget/CoinPriceList/CoinPriceListView.swift @@ -93,10 +93,13 @@ struct CoinPriceListView: View { GeometryReader { proxy in ListSection { ForEach(entry.items, id: \.uid) { item in - rowBuilder(item) - .padding(.horizontal, .margin16) - .frame(maxHeight: .infinity) - .frame(maxHeight: proxy.size.height / CGFloat(entry.maxItemCount)) + Link(destination: URL(string: "unstoppable.money://coin/\(item.uid)")!) { + rowBuilder(item) + .padding(.horizontal, .margin16) + .frame(maxHeight: .infinity) + .frame(maxHeight: proxy.size.height / CGFloat(entry.maxItemCount)) + } + .buttonStyle(PlainButtonStyle()) } if entry.items.count < entry.maxItemCount {