Skip to content

Commit

Permalink
Handle click on coins in Widget extension
Browse files Browse the repository at this point in the history
  • Loading branch information
ealymbaev committed Oct 20, 2023
1 parent 7f93b32 commit cb35ba7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,37 +1,47 @@
import Foundation
import RxSwift
import RxRelay
import RxSwift

class DeepLinkManager {
private let newSchemeRelay = BehaviorRelay<DeepLink?>(value: nil)
}

extension DeepLinkManager {
var newSchemeObservable: Observable<DeepLink?> {
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<DeepLink?> {
newSchemeRelay.asObservable()
}

}

extension DeepLinkManager {

enum DeepLink {
case walletConnect(url: String)
case coin(uid: String)
}

}
11 changes: 7 additions & 4 deletions UnstoppableWallet/Widget/CoinPriceList/CoinPriceListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit cb35ba7

Please sign in to comment.