Skip to content

Instantly share code, notes, and snippets.

#nothing much

...
const drizzleOptions = {
contracts: [SimpleStorage]
};
const initialState = {
contracts: generateContractsInitialState(drizzleOptions)
};
// Redux DevTools
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const sagaMiddleware = createSagaMiddleware();
@alant
alant / App.js
Last active December 24, 2018 10:50
...
class App extends Component {
constructor(props, context) {
super(props);
const { onSetDrizzleState } = this.props;
onSetDrizzleState(context.drizzle);
}
render() {
const { classes, onCheckingTxDone } = this.props;
@alant
alant / Home.js
Last active December 24, 2018 10:56
...
class Home extends Component {
componentDidUpdate(prevProps) {
const { onGetStoredValue } = this.props;
if (this.props.SimpleStorage.initialized && this.props.SimpleStorage.initialized !== prevProps.SimpleStorage.initialized) {
onGetStoredValue();
}
if (this.props.txSuccessful && prevProps.txSuccessful === false) {
onGetStoredValue();
}
@alant
alant / Edit.js
Last active December 24, 2018 11:11
...
class Edit extends Component {
...
handleSubmit = (event) => {
this.contracts.SimpleStorage.methods.set.cacheSend(this.state.newVal);
event.preventDefault();
}
componentDidUpdate(prevProps) {
const { onRedirectToHomeDone } = this.props;
@alant
alant / sagas.js
Last active December 24, 2018 11:14
...
function* showMetaMaskOverlay() {
yield put({ type: 'CHECK_METAMASK' });
}
function* showTxErrorMsg() {
yield put({ type: 'TX_ERROR_METAMASK' });
}
function* showCheckingTxMsg() {
@alant
alant / reducers.js
Last active December 24, 2018 11:16
...
// reducer with initial state
const initialState = {
checkMetaMask: false,
metaMaskReject: false,
checkingTx: false,
txSuccessful: false,
redirectToHome: false,
drizzle: null,
gotStoredValue: false,
var SimpleStorage = artifacts.require("./SimpleStorage.sol");
contract('SimpleStorage', function(accounts) {
it("...should start with the value 0.", async function() {
let simpleStorage = await SimpleStorage.deployed();
let storedData = await simpleStorage.storedData_();
assert.equal(storedData.valueOf(), 0, "0 wasn't stored in contract");
});
it("...should store the value 89.", async function() {
let simpleStorage = await SimpleStorage.deployed();
...
function* pollSagaWorker(dataKey) {
while (true) {
const contracts = yield select(getContracts);
if (contracts.SimpleStorage.synced) {
const storedValueObj = contracts.SimpleStorage.storedData_[dataKey];
if (storedValueObj && storedValueObj.value) {
yield put({ type: 'GOT_STORED_VALUE', storedValue: storedValueObj.value });
}
}
@alant
alant / Login.jsx
Last active December 3, 2019 17:26
function Login(props) {
const { state, dispatch } = React.useContext(AuthContext);
const GITHUB_CLIENT_ID = "6e0b5f325ac2e324312c";
const GITHUB_REDIRECT_URI = process.env.REACT_APP_FRONTEND_URL + "/callback";
const handleGithubLogin = event => {
event.preventDefault();
window.open(`https://github.com/login/oauth/authorize?client_id=${GITHUB_CLIENT_ID}&scope=user&redirect_uri=${GITHUB_REDIRECT_URI}`, "_self");
}