Skip to content

Commit

Permalink
🚑️ Fix android cannot complete wc in webview, support intent://
Browse files Browse the repository at this point in the history
  • Loading branch information
williamchong committed Nov 9, 2023
1 parent 9a71732 commit 482f723
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
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
Expand Up @@ -8,6 +8,7 @@ import { SignDoc } from 'cosmjs-types/cosmos/tx/v1beta1/tx'
import { DirectSignResponse } from '@cosmjs/proto-signing'

import { logError } from '../../utils/error'
import { Platform } from "react-native"
import { checkIsInAppBrowser } from '../../utils/wallet-connect';

import { withCurrentUser, withEnvironment, withNavigationStore } from '../extensions'
Expand Down Expand Up @@ -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',
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

0 comments on commit 482f723

Please sign in to comment.