|
|
|
// Initial State
|
|
|
|
const initialState = {
|
|
|
|
amount: '',
|
|
|
|
memo: '',
|
|
|
|
showCurrencyFilters: false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Constants
|
|
|
|
// ------------------------------------
|
|
|
|
export const SET_REQUEST_AMOUNT = 'SET_REQUEST_AMOUNT'
|
|
|
|
export const SET_REQUEST_MEMO = 'SET_REQUEST_MEMO'
|
|
|
|
export const SET_PAY_INVOICE = 'SET_PAY_INVOICE'
|
|
|
|
|
|
|
|
export const SET_REQUEST_CURRENCY_FILTERS = 'SET_REQUEST_CURRENCY_FILTERS'
|
|
|
|
|
|
|
|
export const RESET_FORM = 'RESET_FORM'
|
|
|
|
|
|
|
|
// ------------------------------------
|
|
|
|
// Actions
|
|
|
|
// ------------------------------------
|
|
|
|
export function setRequestAmount(amount) {
|
|
|
|
return {
|
|
|
|
type: SET_REQUEST_AMOUNT,
|
|
|
|
amount
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setRequestMemo(memo) {
|
|
|
|
return {
|
|
|
|
type: SET_REQUEST_MEMO,
|
|
|
|
memo
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function resetRequestForm() {
|
|
|
|
return {
|
|
|
|
type: RESET_FORM
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setRequestCurrencyFilters(showCurrencyFilters) {
|
|
|
|
return {
|
|
|
|
type: SET_REQUEST_CURRENCY_FILTERS,
|
|
|
|
showCurrencyFilters
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------
|
|
|
|
// Action Handlers
|
|
|
|
// ------------------------------------
|
|
|
|
const ACTION_HANDLERS = {
|
|
|
|
[SET_REQUEST_AMOUNT]: (state, { amount }) => ({ ...state, amount }),
|
|
|
|
[SET_REQUEST_MEMO]: (state, { memo }) => ({ ...state, memo }),
|
|
|
|
[SET_REQUEST_CURRENCY_FILTERS]: (state, { showCurrencyFilters }) => ({ ...state, showCurrencyFilters }),
|
|
|
|
|
|
|
|
[RESET_FORM]: () => (initialState)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------
|
|
|
|
// Reducer
|
|
|
|
// ------------------------------------
|
|
|
|
export default function payFormReducer(state = initialState, action) {
|
|
|
|
const handler = ACTION_HANDLERS[action.type]
|
|
|
|
|
|
|
|
return handler ? handler(state, action) : state
|
|
|
|
}
|