Skip to content

Commit

Permalink
Fix import within truffle (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
armaniferrante authored Feb 21, 2019
1 parent f5927b5 commit fb63a23
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
24 changes: 21 additions & 3 deletions web3c/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
/* globals Web3 */
const MraeBox = require('../crypto/subtle/mrae_box');
let MraeBox = undefined;
if (typeof window === 'undefined' ) {
MraeBox = require('../crypto/node/mrae_box');
} else {
MraeBox = require('../crypto/subtle/mrae_box');
}

const Oasis = require('./oasis');

let localWeb3 = undefined;
Expand All @@ -11,11 +17,23 @@ let rejectWeb3 = () => {};
/**
* Web3c is a wrapper that can be invoked in the same way as Web3.
* Expects Web3 v1.0
*
* @param {Object} provider is an object conforming to the web3 provider interface.
* @param {Object?} web3 is an optional web3 object to override the localWeb3.
*/
module.exports = function (provider) {
module.exports = function (provider, web3) {
if (web3) {
localWeb3 = web3;
}

let storage = undefined;
if (typeof localStorage !== 'undefined') {
storage = localStorage;
}

localWeb3.call(this, provider);
if (this.version && !this.version.api) { // v1.0 series
this.oasis = new Oasis(this, localStorage, MraeBox);
this.oasis = new Oasis(this, storage, MraeBox);
} else {
throw new Error('Unexpected web3 version. Web3c Expects Web3 1.0');
}
Expand Down
6 changes: 1 addition & 5 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ module.exports = env => {
path.resolve(__dirname, 'crypto'),
path.resolve(__dirname, 'web3c')
],
extensions: ['.js'],
alias: {
'../crypto/node': '../crypto/subtle',
'./crypto/node': './crypto/subtle',
}
extensions: ['.js']
},
output: {
path: path.join(__dirname, 'output'),
Expand Down

0 comments on commit fb63a23

Please sign in to comment.