From 837175452072aec4afa1879966d5b8dab511d939 Mon Sep 17 00:00:00 2001 From: William Chong Date: Thu, 9 Nov 2023 19:12:25 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=91=EF=B8=8F=20Fix=20android=20cannot?= =?UTF-8?q?=20complete=20wc=20in=20webview,=20support=20intent://?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/components/nft-web-view/nft-web-view.tsx | 8 ++++++++ .../wallet-connect-v2-client.ts | 6 +++++- .../nft-notification-screen.tsx | 17 ++++++++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/app/components/nft-web-view/nft-web-view.tsx b/app/components/nft-web-view/nft-web-view.tsx index 71982f67..633c1413 100644 --- a/app/components/nft-web-view/nft-web-view.tsx +++ b/app/components/nft-web-view/nft-web-view.tsx @@ -36,6 +36,13 @@ export function NFTWebView({ style, onPressRefresh, ...props }: NFTWebViewProps) Linking.openURL(url) return false } + if (url.startsWith("intent://") && url.includes('package=com.oice')) { + Linking.openURL( + url.replace("intent://", "com.oice://") + .replace('#Intent;package=com.oice;scheme=com.oice;end;', '') + ).catch(err => { console.error(err) }); + return false + } return true } @@ -71,6 +78,7 @@ export function NFTWebView({ style, onPressRefresh, ...props }: NFTWebViewProps) {...props} sharedCookiesEnabled={true} decelerationRate={0.998} + originWhitelist={['https://*', 'http://*', 'intent://*']} // TODO: remove HACK after applicationNameForUserAgent type is fixed {...{ applicationNameForUserAgent: COMMON_API_CONFIG.userAgent }} onShouldStartLoadWithRequest={handleShouldStartLoadWithRequest} diff --git a/app/models/wallet-connect-v2-client/wallet-connect-v2-client.ts b/app/models/wallet-connect-v2-client/wallet-connect-v2-client.ts index f7467cfd..0611d5ab 100644 --- a/app/models/wallet-connect-v2-client/wallet-connect-v2-client.ts +++ b/app/models/wallet-connect-v2-client/wallet-connect-v2-client.ts @@ -1,3 +1,4 @@ +import { Platform } from "react-native" import { NavigationActions } from 'react-navigation' import { flow, Instance, SnapshotOut, types } from 'mobx-state-tree' import SignClient from '@walletconnect/sign-client' @@ -251,7 +252,10 @@ export const WalletConnectV2ClientModel = types method: 'session_proposal', ...proposal, } - if (!checkIsInAppBrowser(proposal)) { + + /* auto approve is broken in android due to navigation to intent:// */ + const isIos = Platform.OS === "ios" + if (!isIos || !checkIsInAppBrowser(proposal)) { // Show WalletConnect Modal for loading UX self.navigationStore.navigateTo({ routeName: 'App', diff --git a/app/screens/nft-notification-screen/nft-notification-screen.tsx b/app/screens/nft-notification-screen/nft-notification-screen.tsx index 55728b05..ec5c7a34 100644 --- a/app/screens/nft-notification-screen/nft-notification-screen.tsx +++ b/app/screens/nft-notification-screen/nft-notification-screen.tsx @@ -1,5 +1,5 @@ import * as React from "react" -import { SafeAreaView, StatusBar } from "react-native" +import { Linking, SafeAreaView, StatusBar } from "react-native" import { inject } from "mobx-react" import styled from "styled-components/native" @@ -7,6 +7,7 @@ import { NFTWebView as NFTWebViewBase } from "../../components/nft-web-view" import { WalletConnectStore } from "../../models/wallet-connect-store" import { UserStore } from "../../models/user-store" +import { WebViewNavigation } from "react-native-webview" interface NFTNotificationScreenProps { userStore: UserStore @@ -41,6 +42,18 @@ export class NFTNotificationScreen extends React.Component { console.error(err) }); + return false + } + + return true + } + render() { return ( @@ -53,6 +66,8 @@ export class NFTNotificationScreen extends React.Component )