Support using awallet: to switch to app and not performing any further action

pull/2622/head
Hwee-Boon Yar 4 years ago
parent 86650bcf9e
commit bfc48146ab
  1. 16
      AlphaWallet/Share/ShareContentAction.swift
  2. 5
      AlphaWallet/Share/UrlSchemeCoordinator.swift

@ -8,21 +8,26 @@
import Foundation
enum ShareContentAction {
static let scheme = "awallet"
private enum Host: String {
case openURL
case openText
case openApp
}
case url(URL)
case string(String)
case openApp
init?(_ url: URL) {
guard let scheme = url.scheme, scheme == ShareContentAction.scheme, let hostValue = url.host, let host = Host(rawValue: hostValue) else {
guard let scheme = url.scheme, scheme == ShareContentAction.scheme else {
return nil
}
guard let hostValue = url.host, let host = Host(rawValue: hostValue) else {
self = .openApp
return
}
let components = URLComponents(url: url, resolvingAgainstBaseURL: true)
switch host {
@ -36,6 +41,9 @@ enum ShareContentAction {
return nil
}
self = .string(value)
case .openApp:
//Impossible to reach here
return nil
}
}
@ -45,6 +53,8 @@ enum ShareContentAction {
return Host.openURL.rawValue
case .string:
return Host.openText.rawValue
case .openApp:
return ""
}
}
@ -67,6 +77,8 @@ enum ShareContentAction {
components.queryItems = [
.init(name: "q", value: text)
]
case .openApp:
return .init()
}
return components

@ -51,9 +51,12 @@ class UrlSchemeCoordinator: UrlSchemeCoordinatorType {
break //NOTE: here we can add parsing Addresses from string
case .url(let url):
inCoordinator.openURLInBrowser(url: url)
case .openApp:
//No-op. Just switching to the app
break
}
pendingUrl = .none
pendingUrl = .none
}
private func canHandle(url: URL) -> Bool {

Loading…
Cancel
Save