Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TAS-691] 🚑️ Fix Android cannot complete WC in webview, support intent:// #402

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/components/nft-web-view/nft-web-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -25,7 +26,7 @@
.extend(withEnvironment)
.extend(withNavigationStore)
.extend(withCurrentUser)
.views(_ => ({

Check warning on line 29 in app/models/wallet-connect-v2-client/wallet-connect-v2-client.ts

View workflow job for this annotation

GitHub Actions / lint

'_' is defined but never used
get isInAppBrowser() {
return false; // TODO: implement user agent checking
},
Expand All @@ -33,7 +34,7 @@
return 2;
},
}))
.views(_ => ({

Check warning on line 37 in app/models/wallet-connect-v2-client/wallet-connect-v2-client.ts

View workflow job for this annotation

GitHub Actions / lint

'_' is defined but never used
shouldShowWalletConnectModal(payload: any) {
return (
(
Expand All @@ -56,7 +57,7 @@
self.sessions = self.connector.session.getAll();
}),
handleDisconnect(
requestEvent: SignClientTypes.EventArguments['session_delete']

Check warning on line 60 in app/models/wallet-connect-v2-client/wallet-connect-v2-client.ts

View workflow job for this annotation

GitHub Actions / lint

'requestEvent' is defined but never used
) {
self.sessions = self.connector.session.getAll();
},
Expand Down Expand Up @@ -251,7 +252,10 @@
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',
Expand Down
17 changes: 16 additions & 1 deletion app/screens/nft-notification-screen/nft-notification-screen.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
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"

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
Expand Down Expand Up @@ -41,6 +42,18 @@ export class NFTNotificationScreen extends React.Component<NFTNotificationScreen
this.props.userStore.loadUnseenEventCount()
}

handleShouldStartLoadWithRequest({ url }: WebViewNavigation) {
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
}

render() {
return (
<RootView>
Expand All @@ -53,6 +66,8 @@ export class NFTNotificationScreen extends React.Component<NFTNotificationScreen
key={this.webViewURL}
source={{ uri: this.webViewURL }}
onPressRefresh={this.handlePressRefresh}
originWhitelist={['https://*', 'http://*', 'intent://*']}
onShouldStartLoadWithRequest={this.handleShouldStartLoadWithRequest}
/>
</RootView>
)
Expand Down
Loading