Changed how web3 is passed in

Web3 from embarkjs-plasma (currently v55) is always used so that signatures can be created properly.
This commit is contained in:
emizzle 2019-06-21 17:45:46 +10:00
parent a0623e6e0f
commit 4ffa5a78e2
No known key found for this signature in database
GPG Key ID: 1FD4BAB3C37EE9BA
1 changed files with 10 additions and 4 deletions

View File

@ -41,18 +41,24 @@ export default class EmbarkJSPlasma {
};
}
async init(web3, useGivenWeb3 = false) {
async init(embarkWeb3, useEmbarkWeb3 = false) {
try {
if (this.initing) {
const message = "Already intializing the Plasma chain, please wait...";
throw new Error(message);
}
this.initing = true;
if (useGivenWeb3) {
this.web3 = web3;
if (useEmbarkWeb3) { // web3 is being passed in and we should use that
this.web3 = new Web3(embarkWeb3.currentProvider || embarkWeb3.givenProvider, null, web3Options); // embark main process
}
else {
this.web3 = new Web3(web3.currentProvider || web3.givenProvider, null, web3Options);
// web3 being passed in could be metamask or could be coming from Embark
const embarkJsWeb3Provider = EmbarkJS.Blockchain.Providers["web3"];
if (!embarkJsWeb3Provider) { throw new Error("web3 cannot be found. Please ensure you have the 'embarkjs-connector-web3' plugin installed in your DApp."); }
const { web3 } = embarkJsWeb3Provider;
this.web3 = new Web3(web3.currentProvider || web3.givenProvider, null, web3Options); // running in the browser
}
// set up the Plasma chain