Fix wallet url decoding and opening in peer info

This commit is contained in:
Ilya Laktyushin 2019-10-26 02:24:40 +04:00
parent a6791dcbd3
commit 0d5326959c
3 changed files with 9 additions and 3 deletions

View File

@ -330,6 +330,6 @@ func openResolvedUrlImpl(_ resolvedUrl: ResolvedUrl, context: AccountContext, ur
dismissInput()
context.sharedContext.openWallet(context: context, walletContext: .send(address: address, amount: amount, comment: comment)) { c in
navigationController?.pushViewController(c)
}
}
}
}

View File

@ -65,6 +65,10 @@ func handleTextLinkActionImpl(context: AccountContext, peerId: PeerId?, navigate
controller.present(JoinLinkPreviewController(context: context, link: link, navigateToPeer: { peerId in
openResolvedPeerImpl(peerId, .chat(textInputState: nil, subject: nil))
}), in: .window(.root))
case let .wallet(address, amount, comment):
context.sharedContext.openWallet(context: context, walletContext: .send(address: address, amount: amount, comment: comment)) { c in
(controller.navigationController as? NavigationController)?.pushViewController(c)
}
default:
break
}

View File

@ -18,14 +18,16 @@ public func parseWalletUrl(_ url: URL) -> ParsedWalletUrl? {
guard url.scheme == "ton" && url.host == "transfer" else {
return nil
}
let updatedUrl = URL(string: url.absoluteString.replacingOccurrences(of: "+", with: "%20"), relativeTo: nil) ?? url
var address: String?
let path = url.path.trimmingCharacters(in: CharacterSet(charactersIn: "/"))
let path = updatedUrl.path.trimmingCharacters(in: CharacterSet(charactersIn: "/"))
if isValidWalletAddress(path) {
address = path
}
var amount: Int64?
var comment: String?
if let query = url.query, let components = URLComponents(string: "/?" + query), let queryItems = components.queryItems {
if let query = updatedUrl.query, let components = URLComponents(string: "/?" + query), let queryItems = components.queryItems {
for queryItem in queryItems {
if let value = queryItem.value {
if queryItem.name == "amount", !value.isEmpty, let amountValue = Int64(value) {