mirror of https://gitlab.com/ecentrics/concordia
Ezerous
7 years ago
12 changed files with 97 additions and 107 deletions
@ -0,0 +1,14 @@ |
|||
import Home from './Home' |
|||
import { drizzleConnect } from 'drizzle-react' |
|||
|
|||
// May still need this even with data function to refresh component on updates for this contract.
|
|||
const mapStateToProps = state => { |
|||
return { |
|||
Forum: state.contracts.Forum, |
|||
drizzleStatus: state.drizzleStatus |
|||
} |
|||
}; |
|||
|
|||
const HomeContainer = drizzleConnect(Home, mapStateToProps); |
|||
|
|||
export default HomeContainer |
@ -1,12 +1,12 @@ |
|||
import { combineReducers } from 'redux' |
|||
import { routerReducer } from 'react-router-redux' |
|||
import userReducer from './user/userReducer' |
|||
import web3Reducer from './util/web3/web3Reducer' |
|||
import { drizzleReducers } from 'drizzle' |
|||
|
|||
const reducer = combineReducers({ |
|||
routing: routerReducer, |
|||
user: userReducer, |
|||
web3: web3Reducer |
|||
...drizzleReducers |
|||
}); |
|||
|
|||
export default reducer |
|||
|
@ -1,22 +1,34 @@ |
|||
import { browserHistory } from 'react-router' |
|||
import { createStore, applyMiddleware, compose } from 'redux' |
|||
import {browserHistory} from 'react-router' |
|||
import {createStore, applyMiddleware, compose} from 'redux' |
|||
import thunkMiddleware from 'redux-thunk' |
|||
import { routerMiddleware } from 'react-router-redux' |
|||
import {routerMiddleware} from 'react-router-redux' |
|||
import reducer from './reducer' |
|||
import rootSaga from './util/drizzle/rootSaga' |
|||
import createSagaMiddleware from 'redux-saga' |
|||
import {generateContractsInitialState} from 'drizzle' |
|||
import drizzleOptions from './util/drizzle/drizzleOptions' |
|||
|
|||
// Redux DevTools (see also https://github.com/zalmoxisus/redux-devtools-extension#12-advanced-store-setup)
|
|||
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; |
|||
|
|||
const routingMiddleware = routerMiddleware(browserHistory); |
|||
const sagaMiddleware = createSagaMiddleware(); |
|||
|
|||
const initialState = { |
|||
contracts: generateContractsInitialState(drizzleOptions) |
|||
}; |
|||
|
|||
const store = createStore( |
|||
reducer, |
|||
composeEnhancers( |
|||
reducer, |
|||
initialState, |
|||
composeEnhancers( |
|||
applyMiddleware( |
|||
thunkMiddleware, |
|||
routingMiddleware |
|||
thunkMiddleware, |
|||
routingMiddleware, |
|||
sagaMiddleware |
|||
) |
|||
) |
|||
); |
|||
|
|||
sagaMiddleware.run(rootSaga); |
|||
export default store |
|||
|
@ -0,0 +1,18 @@ |
|||
import Forum from './../../build/contracts/Forum.json' |
|||
|
|||
const drizzleOptions = { |
|||
web3: { |
|||
fallback: { |
|||
type: 'ws', |
|||
url: 'ws://127.0.0.1:8545' |
|||
} |
|||
}, |
|||
contracts: [ |
|||
Forum |
|||
], |
|||
events: { |
|||
Forum: ['UserSignedUp'] |
|||
} |
|||
}; |
|||
|
|||
export default drizzleOptions |
@ -0,0 +1,8 @@ |
|||
import { all, fork } from 'redux-saga/effects' |
|||
import { drizzleSagas } from 'drizzle' |
|||
|
|||
export default function* root() { |
|||
yield all( |
|||
drizzleSagas.map(saga => fork(saga)) |
|||
) |
|||
} |
@ -1,51 +0,0 @@ |
|||
import store from '../../store' |
|||
import Web3 from 'web3' |
|||
|
|||
export const WEB3_INITIALIZED = 'WEB3_INITIALIZED'; |
|||
function web3Initialized(results) { |
|||
return { |
|||
type: WEB3_INITIALIZED, |
|||
payload: results |
|||
} |
|||
} |
|||
|
|||
let getWeb3 = new Promise(function(resolve, reject) { |
|||
// Wait for loading completion to avoid race conditions with web3 injection timing.
|
|||
window.addEventListener('load', function(dispatch) { |
|||
var results; |
|||
var web3 = window.web3; |
|||
|
|||
// Checking if Web3 has been injected by the browser (Mist/MetaMask)
|
|||
if (typeof web3 !== 'undefined') { |
|||
// Use Mist/MetaMask's provider.
|
|||
web3 = new Web3(web3.currentProvider); |
|||
|
|||
results = { |
|||
web3Instance: web3 |
|||
}; |
|||
|
|||
console.log('Injected web3 detected.'); |
|||
|
|||
resolve(store.dispatch(web3Initialized(results))) |
|||
} else { |
|||
|
|||
// Fallback to localhost if no web3 injection.
|
|||
|
|||
var provider = new Web3.providers.HttpProvider('http://localhost:8545'); |
|||
|
|||
web3 = new Web3(provider); |
|||
|
|||
results = { |
|||
web3Instance: web3 |
|||
}; |
|||
|
|||
console.log('No web3 instance injected, using Local web3.'); |
|||
|
|||
resolve(store.dispatch(web3Initialized(results))) |
|||
} |
|||
|
|||
// TODO: Error checking.
|
|||
}) |
|||
}); |
|||
|
|||
export default getWeb3 |
@ -1,16 +0,0 @@ |
|||
const initialState = { |
|||
web3Instance: null |
|||
}; |
|||
|
|||
const web3Reducer = (state = initialState, action) => { |
|||
if (action.type === 'WEB3_INITIALIZED') |
|||
{ |
|||
return Object.assign({}, state, { |
|||
web3Instance: action.payload.web3Instance |
|||
}) |
|||
} |
|||
|
|||
return state |
|||
}; |
|||
|
|||
export default web3Reducer |
Loading…
Reference in new issue