From 89b1b5ffe0d85089b0bf949240477f8cc96fbf50 Mon Sep 17 00:00:00 2001 From: apanizo Date: Tue, 22 May 2018 11:23:41 +0200 Subject: [PATCH] WA-238 adding transactions property to redux store --- .../safe/store/actions/addTransactions.js | 6 ++++++ src/routes/safe/store/reducer/transactions.js | 17 +++++++++++++++++ src/routes/safe/store/test/granted.selector.js | 2 ++ src/routes/safe/store/test/safe.selector.js | 2 ++ .../safeList/store/test/safes.selector.js | 5 +++++ src/store/index.js | 4 ++++ 6 files changed, 36 insertions(+) create mode 100644 src/routes/safe/store/actions/addTransactions.js create mode 100644 src/routes/safe/store/reducer/transactions.js diff --git a/src/routes/safe/store/actions/addTransactions.js b/src/routes/safe/store/actions/addTransactions.js new file mode 100644 index 00000000..e8a2afee --- /dev/null +++ b/src/routes/safe/store/actions/addTransactions.js @@ -0,0 +1,6 @@ +// @flow +import { createAction } from 'redux-actions' + +export const ADD_TRANSACTIONS = 'ADD_TRANSACTIONS' + +export default createAction(ADD_TRANSACTIONS) diff --git a/src/routes/safe/store/reducer/transactions.js b/src/routes/safe/store/reducer/transactions.js new file mode 100644 index 00000000..81961a95 --- /dev/null +++ b/src/routes/safe/store/reducer/transactions.js @@ -0,0 +1,17 @@ +// @flow +import { List, Map } from 'immutable' +import { handleActions, type ActionType } from 'redux-actions' +import addTransactions, { ADD_TRANSACTIONS } from '~/routes/safe/store/actions/addTransactions' +import { type Transaction } from '~/routes/safe/store/model/transaction' +import { loadSafeTransactions } from '~/routes/safe/component/Transactions/transactions' + +export const TRANSACTIONS_REDUCER_ID = 'transactions' + +export type State = Map> + +export const transactionsInitialState = () => loadSafeTransactions() + +export default handleActions({ + [ADD_TRANSACTIONS]: (state: State, action: ActionType): State => + action.payload, +}, Map()) diff --git a/src/routes/safe/store/test/granted.selector.js b/src/routes/safe/store/test/granted.selector.js index 0f91cd8d..2a984643 100644 --- a/src/routes/safe/store/test/granted.selector.js +++ b/src/routes/safe/store/test/granted.selector.js @@ -27,6 +27,7 @@ const grantedSelectorTests = () => { [SAFE_REDUCER_ID]: map, providers: makeProvider(provider), balances: undefined, + transactions: undefined, } // WHEN @@ -47,6 +48,7 @@ const grantedSelectorTests = () => { [SAFE_REDUCER_ID]: map, providers: makeProvider(provider), balances: undefined, + transactions: undefined, } // WHEN diff --git a/src/routes/safe/store/test/safe.selector.js b/src/routes/safe/store/test/safe.selector.js index 1626665b..0306d6f9 100644 --- a/src/routes/safe/store/test/safe.selector.js +++ b/src/routes/safe/store/test/safe.selector.js @@ -15,6 +15,7 @@ const safeSelectorTests = () => { [SAFE_REDUCER_ID]: Map(), providers: undefined, balances: undefined, + transactions: undefined, } const match: Match = buildMathPropsFrom('fooAddress') @@ -38,6 +39,7 @@ const safeSelectorTests = () => { [SAFE_REDUCER_ID]: map, providers: undefined, balances: undefined, + transactions: undefined, } // WHEN diff --git a/src/routes/safeList/store/test/safes.selector.js b/src/routes/safeList/store/test/safes.selector.js index f268154c..b5946457 100644 --- a/src/routes/safeList/store/test/safes.selector.js +++ b/src/routes/safeList/store/test/safes.selector.js @@ -22,6 +22,7 @@ const safesListSelectorTests = () => { [PROVIDER_REDUCER_ID]: walletRecord, [SAFE_REDUCER_ID]: Map(), balances: undefined, + transactions: undefined, } const emptyList = List([]) @@ -42,6 +43,7 @@ const safesListSelectorTests = () => { [PROVIDER_REDUCER_ID]: walletRecord, [SAFE_REDUCER_ID]: map, balances: undefined, + transactions: undefined, } // WHEN @@ -61,6 +63,7 @@ const safesListSelectorTests = () => { [PROVIDER_REDUCER_ID]: walletRecord, [SAFE_REDUCER_ID]: map, balances: undefined, + transactions: undefined, } // WHEN @@ -81,6 +84,7 @@ const safesListSelectorTests = () => { [SAFE_REDUCER_ID]: map, [PROVIDER_REDUCER_ID]: walletRecord, balances: undefined, + transactions: undefined, } // WHEN @@ -102,6 +106,7 @@ const safesListSelectorTests = () => { [SAFE_REDUCER_ID]: map, [PROVIDER_REDUCER_ID]: walletRecord, balances: undefined, + transactions: undefined, } // WHEN diff --git a/src/store/index.js b/src/store/index.js index 8eca5d8c..61528341 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -6,6 +6,7 @@ import thunk from 'redux-thunk' import provider, { PROVIDER_REDUCER_ID, type State as ProviderState } from '~/wallets/store/reducer/provider' import safe, { SAFE_REDUCER_ID, safeInitialState, type State as SafeState } from '~/routes/safe/store/reducer/safe' import balances, { BALANCE_REDUCER_ID, type State as BalancesState } from '~/routes/safe/store/reducer/balances' +import transactions, { type State as TransactionsState, transactionsInitialState, TRANSACTIONS_REDUCER_ID } from '~/routes/safe/store/reducer/transactions' export const history = createBrowserHistory() @@ -20,6 +21,7 @@ export type GlobalState = { providers: ProviderState, safes: SafeState, balances: BalancesState, + transactions: TransactionsState, } const reducers: Reducer = combineReducers({ @@ -27,10 +29,12 @@ const reducers: Reducer = combineReducers({ [PROVIDER_REDUCER_ID]: provider, [SAFE_REDUCER_ID]: safe, [BALANCE_REDUCER_ID]: balances, + [TRANSACTIONS_REDUCER_ID]: transactions, }) const initialState = { [SAFE_REDUCER_ID]: safeInitialState(), + [TRANSACTIONS_REDUCER_ID]: transactionsInitialState(), } export const store: Store = createStore(reducers, initialState, finalCreateStore)