Browse Source

Hotfix

develop
Ezerous 6 years ago
parent
commit
d53aee5e76
  1. 5
      app/package.json
  2. 2
      app/src/containers/BoardContainer.js
  3. 3
      app/src/redux/sagas/drizzleUtilsSaga.js
  4. 87
      app/src/utils/drizzleUtils.js

5
app/package.json

@ -7,8 +7,6 @@
"url": "https://gitlab.com/Ezerous/Apella.git" "url": "https://gitlab.com/Ezerous/Apella.git"
}, },
"dependencies": { "dependencies": {
"@drizzle-utils/get-contract-instance": "^0.1.6-alpha.0",
"@drizzle-utils/get-web3": "^0.1.6-alpha.0",
"connected-react-router": "^6.3.1", "connected-react-router": "^6.3.1",
"drizzle": "^1.3.3", "drizzle": "^1.3.3",
"history": "^4.7.2", "history": "^4.7.2",
@ -28,7 +26,8 @@
"redux": "^4.0.1", "redux": "^4.0.1",
"redux-saga": "^0.16.2", "redux-saga": "^0.16.2",
"semantic-ui-react": "^0.85.0", "semantic-ui-react": "^0.85.0",
"uuid": "^3.3.2" "uuid": "^3.3.2",
"web3": "1.0.0-beta.35"
}, },
"scripts": { "scripts": {
"start": "react-scripts start", "start": "react-scripts start",

2
app/src/containers/BoardContainer.js

@ -1,7 +1,7 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { drizzle } from '../index'; import { drizzle } from '../index';
import { withRouter } from 'react-router' import { withRouter } from 'react-router-dom'
import { Header } from 'semantic-ui-react'; import { Header } from 'semantic-ui-react';

3
app/src/redux/sagas/drizzleUtilsSaga.js

@ -1,5 +1,4 @@
import getWeb3 from '@drizzle-utils/get-web3'; import { getContractInstance, getWeb3 } from "../../utils/drizzleUtils";
import getContractInstance from '@drizzle-utils/get-contract-instance';
import { call, put, takeLatest, select } from 'redux-saga/effects' import { call, put, takeLatest, select } from 'redux-saga/effects'
import Forum from '../../contracts/Forum'; import Forum from '../../contracts/Forum';

87
app/src/utils/drizzleUtils.js

@ -0,0 +1,87 @@
const Web3 = require("web3");
const resolveWeb3 = (resolve, options, isBrowser) => {
let provider;
if (options.customProvider) {
// use custom provider from options object
provider = options.customProvider;
} else if (isBrowser && window.ethereum) {
// use `ethereum` object injected by MetaMask
provider = window.ethereum;
} else if (isBrowser && typeof window.web3 !== "undefined") {
// use injected web3 object by legacy dapp browsers
provider = window.web3.currentProvider;
} else if (options.fallbackProvider) {
// use fallback provider from options object
provider = options.fallbackProvider;
} else {
// connect to development blockchain from `truffle develop`
provider = new Web3.providers.HttpProvider("http://127.0.0.1:9545");
}
const web3 = new Web3(provider);
resolve(web3);
};
const getWeb3 = (options = {}) =>
new Promise(resolve => {
// handle server-side and React Native environments
const isReactNative =
typeof navigator !== "undefined" && navigator.product === "ReactNative";
const isNode = typeof window === "undefined";
if (isNode || isReactNative) {
return resolveWeb3(resolve, options, false);
}
// if page is ready, resolve for web3 immediately
if (document.readyState === `complete`) {
return resolveWeb3(resolve, options, true);
}
// otherwise, resolve for web3 when page is done loading
return window.addEventListener("load", () =>
resolveWeb3(resolve, options, true),
);
});
const getContractInstance = (options = {}) =>
new Promise(async (resolve, reject) => {
if (!options.web3) {
return reject(new Error("The options object with web3 is required."));
}
const { web3 } = options;
let instance;
try {
if (options.artifact) {
// if artifact exists, attempt to get network ID and the deployed address
const { artifact } = options;
const networkId = await web3.eth.net.getId();
const deployedNetwork = artifact.networks[networkId];
// if no deployed address is found, instantiate without the address
const address = deployedNetwork && deployedNetwork.address;
instance = new web3.eth.Contract(artifact.abi, address);
} else if (options.abi) {
// otherwise, use passed-in ABI and deployed address (optional)
const { abi, address } = options;
instance = new web3.eth.Contract(abi, address);
} else {
return reject(
new Error(
"You must pass in a contract artifact or the ABI of a deployed contract.",
),
);
}
return resolve(instance);
} catch (err) {
return reject(err);
}
});
export { getWeb3, getContractInstance };
Loading…
Cancel
Save