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

bugfix: inpage enable #1065

Merged
merged 2 commits into from
Sep 9, 2019
Merged
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
77 changes: 38 additions & 39 deletions app/core/InpageBridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,44 @@ class InpageBridge {
this._network = undefined; // INITIAL_NETWORK
this._selectedAddress = undefined; // INITIAL_SELECTED_ADDRESS
this._subscribe();

/**
* Called by dapps to request access to user accounts
*
* @param {object} params - Configuration object for account access
* @returns {Promise<Array<string>>} - Promise resolving to array of user accounts
*/
this.enable = params =>
new Promise((resolve, reject) => {
// Temporary fix for peepeth calling
// ethereum.enable with the wrong context
const self = this || window.ethereum;
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;
}
}
});
}

/**
Expand Down Expand Up @@ -212,45 +250,6 @@ class InpageBridge {
});
}

/**
* Called by dapps to request access to user accounts
*
* @param {object} params - Configuration object for account access
* @returns {Promise<Array<string>>} - Promise resolving to array of user accounts
*/
enable(params) {
return new Promise((resolve, reject) => {
// Temporary fix for peepeth calling
// ethereum.enable with the wrong context
const self = this || window.ethereum;
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;
}
}
});
}

/**
* Called by dapps to use the QR scanner
*
Expand Down