Skip to content
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
3 changes: 1 addition & 2 deletions app/components/UI/Navbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ const styles = StyleSheet.create({
optinHeaderLeft: {
flexDirection: 'row',
alignItems: 'center',
marginLeft: Platform.OS === 'ios' ? 20 : 0,
marginRight: Platform.OS === 'ios' ? 20 : 0
marginHorizontal: Platform.OS === 'ios' ? 20 : 0
},
tabIconAndroid: {
marginTop: 13,
Expand Down
11 changes: 8 additions & 3 deletions app/components/UI/NavbarBrowserTitle/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ const styles = StyleSheet.create({
currentUrl: {
...fontStyles.normal,
fontSize: 14,
textAlign: 'center',
paddingHorizontal: Platform.OS === 'android' ? 30 : 0
textAlign: 'center'
},
currentUrlAndroid: {
maxWidth: '60%'
}
});

Expand Down Expand Up @@ -83,7 +85,10 @@ class NavbarBrowserTitle extends Component {
<TouchableOpacity onPress={this.openNetworkList} style={styles.wrapper}>
<View style={styles.currentUrlWrapper}>
{https ? <Icon name="lock" size={14} style={styles.lockIcon} /> : null}
<Text numberOfLines={1} style={styles.currentUrl}>
<Text
numberOfLines={1}
style={[styles.currentUrl, Platform.OS === 'android' ? styles.currentUrlAndroid : {}]}
>
{hostname}
</Text>
</View>
Expand Down
30 changes: 14 additions & 16 deletions app/components/UI/WebsiteIcon/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,22 @@

exports[`WebsiteIcon should render correctly 1`] = `
<View>
<View>
<FadeIn
placeholderStyle={
<FadeIn
placeholderStyle={
Object {
"backgroundColor": "#FFFFFF",
}
}
useNativeDriver={true}
>
<Image
onError={[Function]}
source={
Object {
"backgroundColor": "#FFFFFF",
"uri": "https://api.faviconkit.com//64",
}
}
useNativeDriver={true}
>
<Image
onError={[Function]}
source={
Object {
"uri": "https://api.faviconkit.com//64",
}
}
/>
</FadeIn>
</View>
/>
</FadeIn>
</View>
`;
26 changes: 12 additions & 14 deletions app/components/UI/WebsiteIcon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,27 @@ export default class WebsiteIcon extends Component {
renderIconUrlError: false
};

componentDidMount = () => {
this.getIconUrl(this.props.url);
};

/**
* Get image url from favicon api
*/
getIconUrl = url => {
const iconUrl = `https://api.faviconkit.com/${getHost(url)}/64`;
this.setState({ apiLogoUrl: { uri: iconUrl } });
return iconUrl;
};

/**
* Sets component state to renderIconUrlError to render placeholder image
*/
onRenderIconUrlError = async () => {
await this.setState({ renderIconUrlError: true });
};

renderIconWithFallback = error => {
const { viewStyle, style, title, textStyle } = this.props;
const { apiLogoUrl } = this.state;
render = () => {
const { renderIconUrlError } = this.state;
const { url, viewStyle, style, title, textStyle } = this.props;
const apiLogoUrl = { uri: this.getIconUrl(url) };

if (error && title) {
if (renderIconUrlError && title) {
return (
<View style={viewStyle}>
<View style={[styles.fallback, style]}>
Expand All @@ -88,9 +91,4 @@ export default class WebsiteIcon extends Component {
</View>
);
};

render = () => {
const { renderIconUrlError } = this.state;
return <View>{this.renderIconWithFallback(renderIconUrlError)}</View>;
};
}
149 changes: 39 additions & 110 deletions app/components/Views/BrowserTab/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ import { colors, baseStyles, fontStyles } from '../../../styles/common';
import Networks from '../../../util/networks';
import Logger from '../../../util/Logger';
import onUrlSubmit, { getHost } from '../../../util/browser';
import {
SPA_urlChangeListener,
JS_WINDOW_INFORMATION,
JS_WINDOW_INFORMATION_HEIGHT
} from '../../../util/browserSripts';
import resolveEnsToIpfsContentId from '../../../lib/ens-ipfs/resolver';
import Button from '../../UI/Button';
import { strings } from '../../../../locales/i18n';
Expand Down Expand Up @@ -582,60 +587,7 @@ export class BrowserTab extends PureComponent {
? `'${this.props.network}'`
: `'${Networks[this.props.networkType].networkId}'`
);

const SPA_urlChangeListener = `(function () {
var __mmHistory = window.history;
var __mmPushState = __mmHistory.pushState;
var __mmReplaceState = __mmHistory.replaceState;
function __mm__updateUrl(){
const siteName = document.querySelector('head > meta[property="og:site_name"]');
const title = siteName || document.querySelector('head > meta[name="title"]') || document.title;
const height = Math.max(document.documentElement.clientHeight, document.documentElement.scrollHeight, document.body.clientHeight, document.body.scrollHeight);

window.postMessageToNative(
{
type: 'NAV_CHANGE',
payload: {
url: location.href,
title: title,
}
}
);

setTimeout(() => {
const height = Math.max(document.documentElement.clientHeight, document.documentElement.scrollHeight, document.body.clientHeight, document.body.scrollHeight);
window.postMessageToNative(
{
type: 'GET_HEIGHT',
payload: {
height: height
}
})
}, 500);
}

__mmHistory.pushState = function(state) {
setTimeout(function () {
__mm__updateUrl();
}, 100);
return __mmPushState.apply(history, arguments);
};

__mmHistory.replaceState = function(state) {
setTimeout(function () {
__mm__updateUrl();
}, 100);
return __mmReplaceState.apply(history, arguments);
};

window.onpopstate = function(event) {
__mm__updateUrl();
};
})();
`;

await this.setState({ entryScriptWeb3: updatedentryScriptWeb3 + SPA_urlChangeListener });

Engine.context.AssetsController.hub.on('pendingSuggestedAsset', suggestedAssetMeta => {
if (!this.isTabActive()) return false;
this.setState({ watchAsset: true, suggestedAssetMeta });
Expand Down Expand Up @@ -999,35 +951,43 @@ export class BrowserTab extends PureComponent {
}
};

bookmark = () => {
addBookmark = () => {
this.toggleOptionsIfNeeded();
// Check it doesn't exist already
if (this.props.bookmarks.filter(i => i.url === this.state.inputValue).length) {
Alert.alert(strings('browser.error'), strings('browser.bookmark_already_exists'));
return false;
}

this.props.navigation.push('AddBookmarkView', {
title: this.state.currentPageTitle || '',
url: this.state.inputValue,
onAddBookmark: async ({ name, url }) => {
this.props.addBookmark({ name, url });
if (Platform.OS === 'ios') {
const item = {
uniqueIdentifier: url,
title: name || url,
contentDescription: `Launch ${name || url} on MetaMask`,
keywords: [name.split(' '), url, 'dapp'],
thumbnail: { uri: `https://api.faviconkit.com/${getHost(url)}/256` }
};
try {
SearchApi.indexSpotlightItem(item);
} catch (e) {
Logger.error('Error adding to spotlight', e);
if (!this.state.currentPageTitle) {
// We need to get the title to add bookmark
const { current } = this.webview;
Platform.OS === 'ios'
? current.evaluateJavaScript(JS_WINDOW_INFORMATION)
: current.injectJavaScript(JS_WINDOW_INFORMATION);
}
setTimeout(() => {
this.props.navigation.push('AddBookmarkView', {
title: this.state.currentPageTitle || '',
url: this.state.inputValue,
onAddBookmark: async ({ name, url }) => {
this.props.addBookmark({ name, url });
if (Platform.OS === 'ios') {
const item = {
uniqueIdentifier: url,
title: name || url,
contentDescription: `Launch ${name || url} on MetaMask`,
keywords: [name.split(' '), url, 'dapp'],
thumbnail: { uri: `https://api.faviconkit.com/${getHost(url)}/256` }
};
try {
SearchApi.indexSpotlightItem(item);
} catch (e) {
Logger.error('Error adding to spotlight', e);
}
}
}
}
});
});
}, 500);
};

share = () => {
Expand Down Expand Up @@ -1219,41 +1179,10 @@ export class BrowserTab extends PureComponent {

// We need to get the title of the page and the height
const { current } = this.webview;
const js = `
(function () {
const shortcutIcon = window.document.querySelector('head > link[rel="shortcut icon"]');
const icon = shortcutIcon || Array.from(window.document.querySelectorAll('head > link[rel="icon"]')).find((icon) => Boolean(icon.href));

const siteName = document.querySelector('head > meta[property="og:site_name"]');
const title = siteName || document.querySelector('head > meta[name="title"]');

window.postMessageToNative(
{
type: 'GET_TITLE_FOR_BOOKMARK',
payload: {
title: title ? title.content : document.title,
url: location.href,
icon: icon && icon.href
}
}
)
${
Platform.OS === 'ios'
? `setTimeout(() => {
const height = Math.max(document.documentElement.clientHeight, document.documentElement.scrollHeight, document.body.clientHeight, document.body.scrollHeight);
window.postMessageToNative(
{
type: 'GET_HEIGHT',
payload: {
height: height
}
})
}, 500)`
: ''
}
})();
`;
Platform.OS === 'ios' ? current.evaluateJavaScript(js) : current.injectJavaScript(js);

Platform.OS === 'ios'
? current.evaluateJavaScript(JS_WINDOW_INFORMATION_HEIGHT)
: current.injectJavaScript(JS_WINDOW_INFORMATION_HEIGHT);
clearTimeout(this.timeoutHandler);
};

Expand Down Expand Up @@ -1303,7 +1232,7 @@ export class BrowserTab extends PureComponent {
{strings('browser.home')}
</Text>
</Button>
<Button onPress={this.bookmark} style={styles.option}>
<Button onPress={this.addBookmark} style={styles.option}>
<Icon name="star" size={15} style={styles.optionIcon} />
<Text style={styles.optionText} numberOfLines={1}>
{strings('browser.add_to_favorites')}
Expand Down
Loading