Handle .ton domains correctly in WebAppController and WebAppWebView#1799
Open
NikGariel wants to merge 1 commit intoTelegramMessenger:masterfrom
Open
Handle .ton domains correctly in WebAppController and WebAppWebView#1799NikGariel wants to merge 1 commit intoTelegramMessenger:masterfrom
NikGariel wants to merge 1 commit intoTelegramMessenger:masterfrom
Conversation
NikGariel
commented
Jun 26, 2025
- Modified WebAppController.swift to check for .ton domains and convert to tonsite scheme
- Added TonSchemeHandler in WebAppWebView.swift to handle tonsite URL scheme
- Ensures proper loading of .ton URLs without introducing new features
- Modified WebAppController.swift to check for .ton domains and convert to tonsite scheme - Added TonSchemeHandler in WebAppWebView.swift to handle tonsite URL scheme - Ensures proper loading of .ton URLs without introducing new features Handle .ton domains correctly in WebAppController and WebAppWebView - Modified WebAppController.swift to check for .ton domains and convert to tonsite scheme - Added TonSchemeHandler in WebAppWebView.swift to handle tonsite URL scheme - Ensures proper loading of .ton URLs without introducing new features
Sopheap-cloud
approved these changes
Jul 1, 2025
sergeykonar
suggested changes
Aug 19, 2025
Comment on lines
+434
to
+445
| if let host = parsedUrl.host, host.lowercased().hasSuffix(".ton") { | ||
| // Convert to tonsite scheme | ||
| var urlComponents = URLComponents(string: url) | ||
| urlComponents?.scheme = "tonsite" | ||
| if let updatedUrl = urlComponents?.url { | ||
| self.webView?.load(URLRequest(url: updatedUrl)) | ||
| } else { | ||
| self.webView?.load(URLRequest(url: parsedUrl)) | ||
| } | ||
| } else { | ||
| self.webView?.load(URLRequest(url: parsedUrl)) | ||
| } |
There was a problem hiding this comment.
Could this be simplified like this to avoid multiple if-else statements ?
let urlToLoad: URL
if parsedUrl.host?.lowercased().hasSuffix(".ton") == true,
var components = URLComponents(url: parsedUrl, resolvingAgainstBaseURL: false) {
components.scheme = "tonsite"
urlToLoad = components.url ?? parsedUrl
} else {
urlToLoad = parsedUrl
}
self.webView?.load(URLRequest(url: urlToLoad))
Comment on lines
+469
to
+480
| if let host = parsedUrl.host, host.lowercased().hasSuffix(".ton") { | ||
| // Convert to tonsite scheme | ||
| var urlComponents = URLComponents(string: result.url) | ||
| urlComponents?.scheme = "tonsite" | ||
| if let updatedUrl = urlComponents?.url { | ||
| strongSelf.webView?.load(URLRequest(url: updatedUrl)) | ||
| } else { | ||
| strongSelf.webView?.load(URLRequest(url: parsedUrl)) | ||
| } | ||
| } else { | ||
| strongSelf.webView?.load(URLRequest(url: parsedUrl)) | ||
| } |
There was a problem hiding this comment.
this probably also could be simplified.
let urlToLoad: URL
if parsedUrl.host?.lowercased().hasSuffix(".ton") == true,
var components = URLComponents(url: parsedUrl, resolvingAgainstBaseURL: false) {
components.scheme = "tonsite"
urlToLoad = components.url ?? parsedUrl
} else {
urlToLoad = parsedUrl
}
strongSelf.webView?.load(URLRequest(url: urlToLoad))
Comment on lines
+522
to
+535
| // Check if the URL has a .ton domain | ||
| if let host = parsedUrl.host, host.lowercased().hasSuffix(".ton") { | ||
| // Convert to tonsite scheme | ||
| var urlComponents = URLComponents(string: result.url) | ||
| urlComponents?.scheme = "tonsite" | ||
| if let updatedUrl = urlComponents?.url { | ||
| strongSelf.webView?.load(URLRequest(url: updatedUrl)) | ||
| } else { | ||
| strongSelf.webView?.load(URLRequest(url: parsedUrl)) | ||
| } | ||
| } else { | ||
| strongSelf.webView?.load(URLRequest(url: parsedUrl)) | ||
| } | ||
|
|
Comment on lines
+501
to
+512
| if let host = parsedUrl.host, host.lowercased().hasSuffix(".ton") { | ||
| // Convert to tonsite scheme | ||
| var urlComponents = URLComponents(string: result.url) | ||
| urlComponents?.scheme = "tonsite" | ||
| if let updatedUrl = urlComponents?.url { | ||
| self.webView?.load(URLRequest(url: updatedUrl)) | ||
| } else { | ||
| self.webView?.load(URLRequest(url: parsedUrl)) | ||
| } | ||
| } else { | ||
| self.webView?.load(URLRequest(url: parsedUrl)) | ||
| } |
| mappedPath = "/\(mappedPath)" | ||
| } | ||
| } | ||
| let mappedUrl = "https://\(mappedHost).\(proxyServerHost)\(mappedPath)" |
There was a problem hiding this comment.
I would use here a function like this
private static func mappedUrl(from url: URL?, proxyHost: String) -> URL {
let mappedHost = url?.host?
.replacingOccurrences(of: "-", with: "-h")
.replacingOccurrences(of: ".", with: "-d") ?? ""
let mappedPath: String
if let path = url?.path, !path.isEmpty {
mappedPath = path.hasPrefix("/") ? path : "/" + path
} else {
mappedPath = ""
}
return URL(string: "https://\(mappedHost).\(proxyHost)\(mappedPath)")!
}
| } | ||
| let mappedUrl = "https://\(mappedHost).\(proxyServerHost)\(mappedPath)" | ||
| let isCompleted = self.isCompleted | ||
| self.urlSessionTask = URLSession.shared.dataTask(with: URLRequest(url: URL(string: mappedUrl)!), completionHandler: { data, response, error in |
There was a problem hiding this comment.
Suggested change
| self.urlSessionTask = URLSession.shared.dataTask(with: URLRequest(url: URL(string: mappedUrl)!), completionHandler: { data, response, error in | |
| self.urlSessionTask = URLSession.shared.dataTask(with: URLRequest(url: url: mappedUrl), completionHandler: { data, response, error in |
You can the the output of the function above that I suggested mappedUrl(from url: URL?, proxyHost: String) -> URL
scutuatua-crypto
approved these changes
Jan 8, 2026
scutuatua-crypto
approved these changes
Feb 19, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.