Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Commit

Permalink
Refactor .request response to handle success and fails.
Browse files Browse the repository at this point in the history
  • Loading branch information
jessgusclark committed Apr 7, 2021
1 parent bc0553c commit 3788c2d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/pages/dapp/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,20 @@ class DAppBrowser extends Component {
}
// ensure window.ethereum.send and window.ethereum.sendAsync are not undefined
setInterval(() => {
setTimeout(() => {
if (!window.ethereum.send) {
window.ethereum.send = sendAsync;
}
if (!window.ethereum.sendAsync) {
window.ethereum.sendAsync = sendAsync;
}
if (!window.ethereum.request) {
window.ethereum.request = (payload) => sendAsync(payload).then(response => response.result)
window.ethereum.request = (payload) =>
new Promise((resolve, reject) =>
sendAsync(payload).then(response =>
response.result
? resolve(response.result)
: reject(new Error(response.message || 'provider error'))));
}
}, 1000)
}
Expand Down

0 comments on commit 3788c2d

Please sign in to comment.