Skip to content

Commit

Permalink
Merge pull request #1069 from WalletConnect/hotfix/w3i-logout
Browse files Browse the repository at this point in the history
[W3I] Redirects fix
  • Loading branch information
flypaper0 authored Sep 4, 2023
2 parents fdbfd82 + 68a6353 commit 49725d0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class Web3InboxViewController: UIViewController {
}

@objc func refreshTapped() {
webView?.reload()
Web3Inbox.instance.reload()
}

@objc func getUrlPressed(_ sender: UIBarItem) {
Expand Down
4 changes: 4 additions & 0 deletions Sources/Web3Inbox/Web3InboxClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public final class Web3InboxClient {
public func register(deviceToken: Data) async throws {
try await notifyClient.register(deviceToken: deviceToken)
}

public func reload() {
webviewSubscriber.reload(webView)
}
}

// MARK: - Privates
Expand Down
19 changes: 8 additions & 11 deletions Sources/Web3Inbox/WebView/WebViewRequestSubscriber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ final class WebViewRequestSubscriber: NSObject, WKScriptMessageHandler {
}
}
}

func reload(_ webView: WKWebView) {
webView.load(URLRequest(url: url))
}
}

extension WebViewRequestSubscriber: WKUIDelegate {
Expand All @@ -55,25 +59,18 @@ extension WebViewRequestSubscriber: WKUIDelegate {
func webView(_ webView: WKWebView, requestMediaCapturePermissionFor origin: WKSecurityOrigin, initiatedByFrame frame: WKFrameInfo, type: WKMediaCaptureType, decisionHandler: @escaping (WKPermissionDecision) -> Void) {
decisionHandler(.grant)
}

#endif
}

extension WebViewRequestSubscriber: WKNavigationDelegate {

func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {

guard
let from = webView.url,
let to = navigationAction.request.url
else { return decisionHandler(.cancel) }

if from.absoluteString.contains("/login") || to.absoluteString.contains("/login") {
decisionHandler(.cancel)
webView.load(URLRequest(url: url))
} else {
if navigationAction.request.url == url {
decisionHandler(.allow)
} else {
decisionHandler(.cancel)
}
}
}

0 comments on commit 49725d0

Please sign in to comment.