You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
1.8 KiB
83 lines
1.8 KiB
// Constants
|
|
// ------------------------------------
|
|
export const SET_FORM = 'SET_FORM'
|
|
export const SET_AMOUNT = 'SET_AMOUNT'
|
|
export const SET_MESSAGE = 'SET_MESSAGE'
|
|
export const SET_PUBKEY = 'SET_PUBKEY'
|
|
export const SET_PAYMENT_REQUEST = 'SET_PAYMENT_REQUEST'
|
|
export const RESET_FORM = 'RESET_FORM'
|
|
|
|
// ------------------------------------
|
|
// Actions
|
|
// ------------------------------------
|
|
export function setForm({ modalOpen, formType }) {
|
|
return {
|
|
type: SET_FORM,
|
|
modalOpen,
|
|
formType
|
|
}
|
|
}
|
|
|
|
export function setAmount(amount) {
|
|
return {
|
|
type: SET_AMOUNT,
|
|
amount
|
|
}
|
|
}
|
|
|
|
export function setMessage(message) {
|
|
return {
|
|
type: SET_MESSAGE,
|
|
message
|
|
}
|
|
}
|
|
|
|
export function setPubkey(pubkey) {
|
|
return {
|
|
type: SET_PUBKEY,
|
|
pubkey
|
|
}
|
|
}
|
|
|
|
export function setPaymentRequest(payment_request) {
|
|
return {
|
|
type: SET_PAYMENT_REQUEST,
|
|
payment_request
|
|
}
|
|
}
|
|
|
|
export function resetForm() {
|
|
return {
|
|
type: RESET_FORM
|
|
}
|
|
}
|
|
|
|
// ------------------------------------
|
|
// Action Handlers
|
|
// ------------------------------------
|
|
const ACTION_HANDLERS = {
|
|
[SET_FORM]: (state, { modalOpen, formType }) => ({ ...state, modalOpen, formType }),
|
|
[SET_AMOUNT]: (state, { amount }) => ({ ...state, amount }),
|
|
[SET_MESSAGE]: (state, { message }) => ({ ...state, message }),
|
|
[SET_PUBKEY]: (state, { pubkey }) => ({ ...state, pubkey }),
|
|
[SET_PAYMENT_REQUEST]: (state, { payment_request }) => ({ ...state, payment_request }),
|
|
[RESET_FORM]: () => (initialState)
|
|
}
|
|
|
|
// ------------------------------------
|
|
// Reducer
|
|
// ------------------------------------
|
|
const initialState = {
|
|
modalOpen: false,
|
|
formType: 'pay',
|
|
amount: '0',
|
|
message: '',
|
|
pubkey: '',
|
|
payment_request: ''
|
|
}
|
|
|
|
export default function formReducer(state = initialState, action) {
|
|
const handler = ACTION_HANDLERS[action.type]
|
|
|
|
return handler ? handler(state, action) : state
|
|
}
|