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

Retry ethereum.enable after 1 sec if bridge not ready #963

Merged
merged 4 commits into from
Jul 30, 2019
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
5 changes: 3 additions & 2 deletions app/components/UI/AccountApproval/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ class AccountApproval extends PureComponent {
selectedAddress,
identities
} = this.props;
const host = getHost(url);
return (
<View style={styles.root}>
<View style={styles.titleWrapper}>
Expand All @@ -258,9 +259,9 @@ class AccountApproval extends PureComponent {
<View style={styles.wrapper}>
<View style={styles.header}>
<View style={styles.dapp}>
<WebsiteIcon style={styles.icon} title={title} url={url} />
<WebsiteIcon style={styles.icon} title={title || host} url={url} />
<Text style={styles.headerTitle} numberOfLines={1}>
{title || getHost(url)}
{title || host}
</Text>
<Text style={styles.headerUrl} numberOfLines={1}>
{url}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ exports[`Browser should render correctly 1`] = `
Object {
"icon": undefined,
"title": "",
"url": "",
"url": "https://metamask.io",
}
}
onCancel={[Function]}
Expand Down
7 changes: 5 additions & 2 deletions app/components/Views/BrowserTab/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1536,7 +1536,10 @@ export class BrowserTab extends PureComponent {
};

renderApprovalModal = () => {
const { showApprovalDialog, currentPageTitle, currentPageUrl, currentPageIcon } = this.state;
const { showApprovalDialog, currentPageTitle, currentPageUrl, currentPageIcon, inputValue } = this.state;
const url =
currentPageUrl && currentPageUrl.length && currentPageUrl !== 'localhost' ? currentPageUrl : inputValue;

return (
<Modal
isVisible={showApprovalDialog}
Expand All @@ -1553,7 +1556,7 @@ export class BrowserTab extends PureComponent {
<AccountApproval
onCancel={this.onAccountsReject}
onConfirm={this.onAccountsConfirm}
currentPageInformation={{ title: currentPageTitle, url: currentPageUrl, icon: currentPageIcon }}
currentPageInformation={{ title: currentPageTitle, url, icon: currentPageIcon }}
/>
</Modal>
);
Expand Down
33 changes: 27 additions & 6 deletions app/core/InpageBridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ class InpageBridge {
* @param {Function} callback - Function called when operation completes
*/
sendAsync(payload, callback) {
if (!window.postMessageToNative) {
throw new Error('Bridge not ready');
}
const random = Math.floor(Math.random() * 100 + 1);
if (typeof payload === 'string') {
// Support dapps calling sendAsync('some_method') even though this is not
Expand Down Expand Up @@ -220,13 +223,31 @@ class InpageBridge {
// Temporary fix for peepeth calling
// ethereum.enable with the wrong context
const self = this || window.ethereum;
self.sendAsync({ method: 'eth_requestAccounts', params }, (error, result) => {
if (error) {
reject(error);
return;
try {
self.sendAsync({ method: 'eth_requestAccounts', params }, (error, result) => {
if (error) {
reject(error);
return;
}
resolve(result);
});
} catch (e) {
if (e.toString().indexOf('Bridge not ready') !== -1) {
// Wait 1s and retry

setTimeout(() => {
self.sendAsync({ method: 'eth_requestAccounts', params }, (error, result) => {
if (error) {
reject(error);
return;
}
resolve(result);
});
}, 1000);
} else {
throw e;
}
resolve(result);
});
}
});
}

Expand Down