Skip to content
This repository was archived by the owner on Mar 11, 2024. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/store/src/Drizzle.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export const getOrCreateWeb3Contract = (store, contractConfig, web3) => {
class Drizzle {
constructor (givenOptions, store) {
const options = merge(defaultOptions, givenOptions)
// console.log("Using Local Drizzle")
// debugger

// Variables
this.contracts = {}
Expand All @@ -54,6 +56,8 @@ class Drizzle {

this.loadingContract = {}

console.log("Drizzle instance initializes")

// Wait for window load event in case of injected web3.
isEnvReadyPromise.then(() => {
// Begin Drizzle initialization.
Expand Down Expand Up @@ -140,4 +144,9 @@ class Drizzle {
}
}




// console.log("Using Local Drizzle")
// console.log("locally")
export default Drizzle
3 changes: 2 additions & 1 deletion packages/store/src/defaultOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const defaultOptions = {
fallback: {
type: 'ws',
url: 'ws://127.0.0.1:8545'
}
},
delayConnection: false
},
contracts: [],
events: {},
Expand Down
2 changes: 2 additions & 0 deletions packages/store/src/drizzle-middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ export const drizzleMiddleware = drizzleInstance => store => next => action => {
const { type } = action

if (type === 'DRIZZLE_INITIALIZING') {
console.log("initializing middleware")
// debugger
drizzleInstance = action.drizzle
}

Expand Down
2 changes: 2 additions & 0 deletions packages/store/src/drizzleStatus/drizzleStatusSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import { NETWORK_IDS, NETWORK_MISMATCH } from '../web3/constants'
export function * initializeDrizzle (action) {
try {
const { drizzle, options } = action
// debugger

// Initialize web3 and get the current network ID.
console.log("initializing Status Saga")
const web3 = yield call(initializeWeb3, options.web3)
drizzle.web3 = web3

Expand Down
1 change: 1 addition & 0 deletions packages/store/src/web3/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export const WEB3_INITIALIZING = 'WEB3_INITIALIZING'
export const WEB3_INITIALIZED = 'WEB3_INITIALIZED'
export const WEB3_FAILED = 'WEB3_FAILED'
export const WEB3_USER_DENIED = 'WEB3_USER_DENIED'
export const WEB3_CONNECTION_DELAYED = 'WEB3_CONNECTION_DELAYED'

export const NETWORK_ID_FETCHED = 'NETWORK_ID_FETCHED'
export const NETWORK_ID_FAILED = 'NETWORK_ID_FAILED'
Expand Down
7 changes: 7 additions & 0 deletions packages/store/src/web3/web3Reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ const web3Reducer = (state = initialState, action) => {
}
}

if (action.type === Action.WEB3_CONNECTION_DELAYED) {
return {
...state,
status: 'ConnectionDelayed'
}
}

if (action.type === Action.NETWORK_ID_FETCHED) {
return {
...state,
Expand Down
5 changes: 5 additions & 0 deletions packages/store/src/web3/web3Saga.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export function * initializeWeb3 (options) {
const { ethereum } = window
web3 = new Web3(ethereum)
try {

if (options.delayConnection) {
yield put({ type: Action.WEB3_CONNECTION_DELAYED })
return
}
// ethereum.enable() will return the selected account
// unless user opts out and then it will return undefined
const selectedAccount = yield call([ethereum, 'enable'])
Expand Down