From dd5ef86dc93d8a20cc2b9b86c30c818ea1af0ead Mon Sep 17 00:00:00 2001 From: Jack Mallers Date: Wed, 20 Sep 2017 16:13:30 -0500 Subject: [PATCH] feature(activity modal): add activity reducer and basic activity modal functionality --- app/reducers/activity.js | 50 +++++++++++++++++++ app/reducers/index.js | 4 +- app/routes/activity/components/Activity.js | 19 ++++--- .../components/components/Invoice/Invoice.js | 4 +- .../components/{ => Modal}/Modal.js | 16 +++--- .../components/components/Modal/index.js | 3 ++ .../components/components/Payment/Payment.js | 4 +- .../components/Transaction/Transaction.js | 4 +- .../activity/containers/ActivityContainer.js | 5 +- 9 files changed, 87 insertions(+), 22 deletions(-) create mode 100644 app/reducers/activity.js rename app/routes/activity/components/components/{ => Modal}/Modal.js (70%) create mode 100644 app/routes/activity/components/components/Modal/index.js diff --git a/app/reducers/activity.js b/app/reducers/activity.js new file mode 100644 index 00000000..e1af749c --- /dev/null +++ b/app/reducers/activity.js @@ -0,0 +1,50 @@ +// ------------------------------------ +// Initial State +// ------------------------------------ +const initialState = { + filter: 'ALL_ACTIVITY', + modal: { + modalType: null, + modalProps: {} + } +} + +// ------------------------------------ +// Constants +// ------------------------------------ +export const SHOW_ACTIVITY_MODAL = 'SHOW_ACTIVITY_MODAL' +export const HIDE_ACTIVITY_MODAL = 'HIDE_ACTIVITY_MODAL' + +// ------------------------------------ +// Actions +// ------------------------------------ +export function showActivityModal(modalType, modalProps) { + return { + type: SHOW_ACTIVITY_MODAL, + modalType, + modalProps + } +} + +export function hideActivityModal() { + return { + type: HIDE_ACTIVITY_MODAL + } +} + +// ------------------------------------ +// Action Handlers +// ------------------------------------ +const ACTION_HANDLERS = { + [SHOW_ACTIVITY_MODAL]: (state, { modalType, modalProps }) => ({ ...state, modal: { modalType, modalProps } }), + [HIDE_ACTIVITY_MODAL]: (state) => ({ ...state, modal: { modalType: null, modalProps: {} } }) +} + +// ------------------------------------ +// Reducer +// ------------------------------------ +export default function activityReducer(state = initialState, action) { + const handler = ACTION_HANDLERS[action.type] + + return handler ? handler(state, action) : state +} diff --git a/app/reducers/index.js b/app/reducers/index.js index 75b0597e..4c906733 100644 --- a/app/reducers/index.js +++ b/app/reducers/index.js @@ -12,6 +12,7 @@ import invoice from './invoice' import modal from './modal' import address from './address' import transaction from './transaction' +import activity from './activity' const rootReducer = combineReducers({ router, @@ -25,7 +26,8 @@ const rootReducer = combineReducers({ invoice, modal, address, - transaction + transaction, + activity }) export default rootReducer diff --git a/app/routes/activity/components/Activity.js b/app/routes/activity/components/Activity.js index 3ff58af9..11602edc 100644 --- a/app/routes/activity/components/Activity.js +++ b/app/routes/activity/components/Activity.js @@ -9,6 +9,8 @@ import Invoice from './components/Invoice' import Payment from './components/Payment' import Transaction from './components/Transaction' +import Modal from './components/Modal' + import styles from './Activity.scss' class Activity extends Component { @@ -30,18 +32,17 @@ class Activity extends Component { } renderActivity(activity) { - const { ticker, currentTicker } = this.props + const { ticker, currentTicker, showActivityModal } = this.props if (activity.hasOwnProperty('block_hash')) { // activity is an on-chain tx - return + return } else if (activity.hasOwnProperty('payment_request')) { // activity is an LN invoice - console.log('activity: ', activity) - return + return } else { // activity is an LN payment - return + return } } @@ -58,11 +59,17 @@ class Activity extends Component { paymentModalOpen, invoiceModalOpen, currentTicker, - sortedActivity + sortedActivity, + activity: { modal }, + hideActivityModal } = this.props + if (invoiceLoading || paymentLoading) { return
Loading...
} + return (
+ +