Skip to content

Commit

Permalink
feat: web3 browser useragent
Browse files Browse the repository at this point in the history
  • Loading branch information
iGroza committed Jun 23, 2023
1 parent 5565fb9 commit 679a552
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
4 changes: 2 additions & 2 deletions ios/haqq.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
CA97D1A6FCC0490AA0E660A8 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 8D52915C768145E4B5007D44 /* [email protected] */; };
CD8E3B4D34F041E8824FC13F /* InpageBridgeWeb3.js in Resources */ = {isa = PBXBuildFile; fileRef = EB5972ABD10C480FB1400A0F /* InpageBridgeWeb3.js */; };
CEBA4969BB874AF6B924DA37 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = F5FCD1005E8E4C08BB4782E3 /* [email protected] */; };
CF0D49E2FABD41D9A34AB04C /* (null) in Resources */ = {isa = PBXBuildFile; };
CF0D49E2FABD41D9A34AB04C /* BuildFile in Resources */ = {isa = PBXBuildFile; };
CF3BD3A1F0A24224948734D3 /* ElMessiri-Medium.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 6B48442C371E4A5CB312ED9E /* ElMessiri-Medium.ttf */; };
CF6F3ED1E5A54155A2507F94 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 60F20D8762B94A298A8895E3 /* [email protected] */; };
D2EF8B9028754ED2AA9994E5 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 8D9E0B76C3074F8DB59AA2BB /* [email protected] */; };
Expand Down Expand Up @@ -750,7 +750,7 @@
BEFF23B4E9FE4A40BD7E5624 /* SF-ProText-Regular.ttf in Resources */,
F57AEFB435FF4249932EF918 /* SF-ProText-Semibold.ttf in Resources */,
2129B78329CACF69005C0CCA /* overview.storyboard in Resources */,
CF0D49E2FABD41D9A34AB04C /* (null) in Resources */,
CF0D49E2FABD41D9A34AB04C /* BuildFile in Resources */,
1A6D4E352A149298001B1549 /* staking_on_earn_page_dark.riv in Resources */,
7CE3C371577D43A6BAA1DF94 /* backup-notification-dark.png in Resources */,
8EF155B29CA4479AA8E82E4A /* [email protected] in Resources */,
Expand Down
10 changes: 4 additions & 6 deletions src/components/web3-browser/web3-browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {Wallet} from '@app/models/wallet';
import {Web3BrowserBookmark} from '@app/models/web3-browser-bookmark';
import {Web3BrowserSearchHistory} from '@app/models/web3-browser-search-history';
import {Web3BrowserSession} from '@app/models/web3-browser-session';
import {getUserAgent} from '@app/services/version';

import {
InpageBridgeWeb3,
Expand All @@ -32,11 +33,7 @@ import {
} from './web3-browser-header';
import {Web3BrowserHelper} from './web3-browser-helper';

import {
WebViewUserAgent,
clearUrl,
getOriginFromUrl,
} from '../../helpers/web3-browser-utils';
import {clearUrl, getOriginFromUrl} from '../../helpers/web3-browser-utils';
import {BrowserError} from '../browser-error';

export interface Web3BrowserProps {
Expand Down Expand Up @@ -108,6 +105,7 @@ export const Web3Browser = ({
onPressRemoveBookmark,
addSiteToSearchHistory,
}: Web3BrowserProps) => {
const userAgent = useRef(getUserAgent()).current;
const [inpageBridgeWeb3, setInpageBridgeWeb3] = useState('');
const [selectedAccount, setSelectedAccount] = useState<string | undefined>();
const [windowInfo, setWindowInfo] = useState<WindowInfoEvent['payload']>();
Expand Down Expand Up @@ -303,7 +301,7 @@ export const Web3Browser = ({
dataDetectorTypes={'all'}
originWhitelist={['*']}
ref={webviewRef}
userAgent={WebViewUserAgent}
userAgent={userAgent}
onMessage={helper.handleMessage}
onLoad={onLoad}
onLoadEnd={helper.onLoadEnd}
Expand Down
8 changes: 1 addition & 7 deletions src/helpers/web3-browser-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {JsonRpcRequest} from 'json-rpc-engine';
import {Alert, Linking, Platform} from 'react-native';
import {Alert, Linking} from 'react-native';
import {WebViewMessageEvent} from 'react-native-webview';

import {isValidUrl} from '@app/utils';
Expand Down Expand Up @@ -89,12 +89,6 @@ export const changeWebViewUrlJS = (href: string) => {
return `(function(){window.location.href = '${href}' })()`;
};

export const WebViewUserAgent = Platform.select({
android:
'Mozilla/5.0 (Linux; Android 10; Android SDK built for x86 Build/OSM1.180201.023) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.92 Mobile Safari/537.36',
ios: 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/76.0.3809.123 Mobile/15E148 Safari/605.1',
});

// Checking whether an application can navigate to another application through a deep link.
// return true if deeplink detected
export const detectDeeplinkAndNavigate = async (url: string) => {
Expand Down
13 changes: 11 additions & 2 deletions src/screens/settings-test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, {useCallback, useState} from 'react';

import {useActionSheet} from '@expo/react-native-action-sheet';
import Clipboard from '@react-native-clipboard/clipboard';
import messaging from '@react-native-firebase/messaging';
import BN from 'bn.js';
import {utils} from 'ethers';
Expand Down Expand Up @@ -390,8 +391,16 @@ export const SettingsTestScreen = () => {

return (
<ScrollView style={styles.container}>
<Text t11>userAgent: {getUserAgent()}</Text>
<Spacer height={20} />
<Title text="user agent" />
<Text
t11
onPress={() => {
Clipboard.setString(getUserAgent());
toastMessage('Copied to clipboard');
}}>
{getUserAgent()}
</Text>
<Spacer height={8} />
<Title text="WalletConnect" />
<Input
placeholder="wc:"
Expand Down
2 changes: 1 addition & 1 deletion src/services/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ export const getAdId = () => RNVersion.adId;

export const getIsTrackingEnabled = () => RNVersion.isTrackingEnabled;

export const getUserAgent = () => RNVersion.userAgent;
export const getUserAgent = () => RNVersion.userAgent as string;

0 comments on commit 679a552

Please sign in to comment.