Browse Source

feature(activity modal): add activity reducer and basic activity modal functionality

renovate/lint-staged-8.x
Jack Mallers 7 years ago
parent
commit
dd5ef86dc9
  1. 50
      app/reducers/activity.js
  2. 4
      app/reducers/index.js
  3. 19
      app/routes/activity/components/Activity.js
  4. 4
      app/routes/activity/components/components/Invoice/Invoice.js
  5. 16
      app/routes/activity/components/components/Modal/Modal.js
  6. 3
      app/routes/activity/components/components/Modal/index.js
  7. 4
      app/routes/activity/components/components/Payment/Payment.js
  8. 4
      app/routes/activity/components/components/Transaction/Transaction.js
  9. 5
      app/routes/activity/containers/ActivityContainer.js

50
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
}

4
app/reducers/index.js

@ -12,6 +12,7 @@ import invoice from './invoice'
import modal from './modal' import modal from './modal'
import address from './address' import address from './address'
import transaction from './transaction' import transaction from './transaction'
import activity from './activity'
const rootReducer = combineReducers({ const rootReducer = combineReducers({
router, router,
@ -25,7 +26,8 @@ const rootReducer = combineReducers({
invoice, invoice,
modal, modal,
address, address,
transaction transaction,
activity
}) })
export default rootReducer export default rootReducer

19
app/routes/activity/components/Activity.js

@ -9,6 +9,8 @@ import Invoice from './components/Invoice'
import Payment from './components/Payment' import Payment from './components/Payment'
import Transaction from './components/Transaction' import Transaction from './components/Transaction'
import Modal from './components/Modal'
import styles from './Activity.scss' import styles from './Activity.scss'
class Activity extends Component { class Activity extends Component {
@ -30,18 +32,17 @@ class Activity extends Component {
} }
renderActivity(activity) { renderActivity(activity) {
const { ticker, currentTicker } = this.props const { ticker, currentTicker, showActivityModal } = this.props
if (activity.hasOwnProperty('block_hash')) { if (activity.hasOwnProperty('block_hash')) {
// activity is an on-chain tx // activity is an on-chain tx
return <Transaction transaction={activity} ticker={ticker} currentTicker={currentTicker} /> return <Transaction transaction={activity} ticker={ticker} currentTicker={currentTicker} showActivityModal={showActivityModal} />
} else if (activity.hasOwnProperty('payment_request')) { } else if (activity.hasOwnProperty('payment_request')) {
// activity is an LN invoice // activity is an LN invoice
console.log('activity: ', activity) return <Invoice invoice={activity} ticker={ticker} currentTicker={currentTicker} showActivityModal={showActivityModal} />
return <Invoice invoice={activity} ticker={ticker} currentTicker={currentTicker} />
} else { } else {
// activity is an LN payment // activity is an LN payment
return <Payment payment={activity} ticker={ticker} currentTicker={currentTicker} /> return <Payment payment={activity} ticker={ticker} currentTicker={currentTicker} showActivityModal={showActivityModal} />
} }
} }
@ -58,11 +59,17 @@ class Activity extends Component {
paymentModalOpen, paymentModalOpen,
invoiceModalOpen, invoiceModalOpen,
currentTicker, currentTicker,
sortedActivity sortedActivity,
activity: { modal },
hideActivityModal
} = this.props } = this.props
if (invoiceLoading || paymentLoading) { return <div>Loading...</div> } if (invoiceLoading || paymentLoading) { return <div>Loading...</div> }
return ( return (
<div> <div>
<Modal modalType={modal.modalType} modalProps={modal.modalProps} hideActivityModal={hideActivityModal} />
<div className={styles.search}> <div className={styles.search}>
<label className={`${styles.label} ${styles.input}`} htmlFor='invoiceSearch'> <label className={`${styles.label} ${styles.input}`} htmlFor='invoiceSearch'>
<MdSearch /> <MdSearch />

4
app/routes/activity/components/components/Invoice/Invoice.js

@ -7,8 +7,8 @@ import { btc } from '../../../../../utils'
import CurrencyIcon from '../../../../../components/CurrencyIcon' import CurrencyIcon from '../../../../../components/CurrencyIcon'
import styles from '../Activity.scss' import styles from '../Activity.scss'
const Invoice = ({ invoice, ticker, currentTicker }) => ( const Invoice = ({ invoice, ticker, currentTicker, showActivityModal }) => (
<div className={styles.container}> <div className={styles.container} onClick={() => showActivityModal('INVOICE', { invoice })}>
<div className={styles.label}> <div className={styles.label}>
<i className={`${styles.icon} hint--top`} data-hint='Lightning Network transaction'> <i className={`${styles.icon} hint--top`} data-hint='Lightning Network transaction'>
<FaBolt /> <FaBolt />

16
app/routes/activity/components/components/Modal.js → app/routes/activity/components/components/Modal/Modal.js

@ -2,7 +2,7 @@ import React from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import ReactModal from 'react-modal' import ReactModal from 'react-modal'
const Modal = ({ isOpen, resetObject, children }) => { const Modal = ({ modalType, modalProps, hideActivityModal }) => {
const customStyles = { const customStyles = {
overlay: { overlay: {
cursor: 'pointer' cursor: 'pointer'
@ -16,26 +16,26 @@ const Modal = ({ isOpen, resetObject, children }) => {
margin: '50px auto' margin: '50px auto'
} }
} }
if (!modalType) { return null }
return ( return (
<ReactModal <ReactModal
isOpen={isOpen} isOpen
contentLabel='No Overlay Click Modal'
ariaHideApp ariaHideApp
shouldCloseOnOverlayClick shouldCloseOnOverlayClick
onRequestClose={() => resetObject(null)} contentLabel='No Overlay Click Modal'
onRequestClose={() => hideActivityModal()}
parentSelector={() => document.body} parentSelector={() => document.body}
style={customStyles} style={customStyles}
> >
{children} <h1>hi!</h1>
</ReactModal> </ReactModal>
) )
} }
Modal.propTypes = { Modal.propTypes = {
isOpen: PropTypes.bool.isRequired, modalType: PropTypes.string
resetObject: PropTypes.func.isRequired,
children: PropTypes.object
} }
export default Modal export default Modal

3
app/routes/activity/components/components/Modal/index.js

@ -0,0 +1,3 @@
import Modal from './Modal'
export default Modal

4
app/routes/activity/components/components/Payment/Payment.js

@ -7,8 +7,8 @@ import { btc } from '../../../../../utils'
import CurrencyIcon from '../../../../../components/CurrencyIcon' import CurrencyIcon from '../../../../../components/CurrencyIcon'
import styles from '../Activity.scss' import styles from '../Activity.scss'
const Payment = ({ payment, ticker, currentTicker }) => ( const Payment = ({ payment, ticker, currentTicker, showActivityModal }) => (
<div className={styles.container}> <div className={styles.container} onClick={() => showActivityModal('PAYMENT', { payment })}>
<div className={styles.label}> <div className={styles.label}>
<i className={`${styles.icon} hint--top`} data-hint='Lightning Network transaction'> <i className={`${styles.icon} hint--top`} data-hint='Lightning Network transaction'>
<FaBolt /> <FaBolt />

4
app/routes/activity/components/components/Transaction/Transaction.js

@ -7,8 +7,8 @@ import { btc } from '../../../../../utils'
import CurrencyIcon from '../../../../../components/CurrencyIcon' import CurrencyIcon from '../../../../../components/CurrencyIcon'
import styles from '../Activity.scss' import styles from '../Activity.scss'
const Transaction = ({ transaction, ticker, currentTicker }) => ( const Transaction = ({ transaction, ticker, currentTicker, showActivityModal }) => (
<div className={styles.container}> <div className={styles.container} onClick={() => showActivityModal('TRANSACTION', { transaction })}>
<div className={styles.label}> <div className={styles.label}>
<i className={`${styles.icon} hint--top`} data-hint='On-chain transaction'> <i className={`${styles.icon} hint--top`} data-hint='On-chain transaction'>
<FaChain /> <FaChain />

5
app/routes/activity/containers/ActivityContainer.js

@ -12,6 +12,7 @@ import {
paymentSelectors paymentSelectors
} from '../../../reducers/payment' } from '../../../reducers/payment'
import { fetchTransactions } from '../../../reducers/transaction' import { fetchTransactions } from '../../../reducers/transaction'
import { showActivityModal, hideActivityModal } from '../../../reducers/activity'
import { activitySelectors } from '../../../selectors' import { activitySelectors } from '../../../selectors'
import Activity from '../components/Activity' import Activity from '../components/Activity'
@ -21,7 +22,9 @@ const mapDispatchToProps = {
fetchPayments, fetchPayments,
fetchInvoices, fetchInvoices,
fetchTransactions, fetchTransactions,
searchInvoices searchInvoices,
showActivityModal,
hideActivityModal
} }
const mapStateToProps = state => ({ const mapStateToProps = state => ({

Loading…
Cancel
Save