-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle click on coins in Widget extension
- Loading branch information
Showing
2 changed files
with
27 additions
and
14 deletions.
There are no files selected for viewing
30 changes: 20 additions & 10 deletions
30
UnstoppableWallet/UnstoppableWallet/Core/Managers/DeepLinkManager.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters