Skip to content

Commit

Permalink
Moving transaction and locks to top level of store (#249)
Browse files Browse the repository at this point in the history
* Moving transaction and locks to top level of store

* Updating tests
  • Loading branch information
benwerd committed Sep 18, 2018
1 parent 48b5b09 commit c179410
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion unlock-app/src/__tests__/reducers/accountReducer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('account reducer', () => {
const balance = '1337'

it('should return the initial state', () => {
expect(reducer(undefined, {})).toEqual({ 'locks': [], transactions: {all: {}, lastUpdated: 0, latest: null} })
expect(reducer(undefined, {})).toEqual({})
})

it('should set the account accordingly when receiving SET_ACCOUNT', () => {
Expand Down
5 changes: 1 addition & 4 deletions unlock-app/src/__tests__/reducers/networkReducer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ describe('network reducer', () => {

it('should return the initial state', () => {
expect(reducer(undefined, {})).toEqual({
account: {
locks: [],
transactions: {all: {}, lastUpdated: 0, latest: null},
},
account: {},
key: {
data: '',
expiration: 0,
Expand Down
2 changes: 1 addition & 1 deletion unlock-app/src/components/consumer/Lock.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const mapStateToProps = state => {
currentKey: state.network.key, // key is a reserved props name
account: state.network.account,
lock: state.network.lock,
transaction: state.network.account && state.network.account.transactions.latest,
transaction: state.network.account && state.transactions.latest,
}
}

Expand Down
2 changes: 1 addition & 1 deletion unlock-app/src/components/creator/Locks.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Locks.propTypes = {
}

const mapStateToProps = state => {
const locks = state.network.account.locks || []
const locks = state.locks || []
return {
locks,
}
Expand Down
2 changes: 1 addition & 1 deletion unlock-app/src/components/creator/TransactionModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ TransactionModal.propTypes = {

const mapStateToProps = state => {
return {
transaction: state.network.account.transactions.latest,
transaction: state.transactions.latest,
}
}

Expand Down
10 changes: 10 additions & 0 deletions unlock-app/src/createUnlockStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { routerReducer, routerMiddleware } from 'react-router-redux'
// Reducers
import networkReducer from './reducers/networkReducer'
import providerReducer from './reducers/providerReducer'
import transactionReducer from './reducers/transactionReducer'
import locksReducer from './reducers/locksReducer'

// Middlewares
import lockMiddleware from './middlewares/lockMiddleware'
Expand All @@ -15,6 +17,8 @@ export default function createUnlockStore(config, browserHistory) {
router: routerReducer,
provider: providerReducer,
network: networkReducer,
transactions: transactionReducer,
locks: locksReducer,
}

const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose
Expand All @@ -23,6 +27,12 @@ export default function createUnlockStore(config, browserHistory) {
network: {
name: 0,
},
transactions: {
latest: null,
all: {},
lastUpdated: 0,
},
locks: [],
}, loadState())

const middlewares = [
Expand Down
4 changes: 0 additions & 4 deletions unlock-app/src/reducers/accountReducer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { SET_ACCOUNT, RESET_ACCOUNT_BALANCE } from '../actions/accounts'
import locksReducer from './locksReducer'
import transactionReducer from './transactionReducer'

const initialState = {}

Expand All @@ -19,8 +17,6 @@ const accountReducer = (state = initialState, action) => {

return {
...state,
locks: locksReducer(state.locks, action),
transactions: transactionReducer(state.transactions, action),
}
}

Expand Down

0 comments on commit c179410

Please sign in to comment.