Browse Source

fix(form reducer): delete all unused code from form reducer

renovate/lint-staged-8.x
Jack Mallers 7 years ago
parent
commit
c3dd7d41ce
  1. 109
      app/reducers/form.js
  2. 21
      app/routes/app/containers/AppContainer.js

109
app/reducers/form.js

@ -3,33 +3,13 @@ import bitcoin from 'bitcoinjs-lib'
// Initial State
const initialState = {
formType: null,
modalOpen: false,
amount: '0',
onchainAmount: '0',
message: '',
pubkey: '',
payment_request: ''
formType: null
}
// Constants
// ------------------------------------
export const SET_FORM_TYPE = 'SET_FORM_TYPE'
export const SET_FORM = 'SET_FORM'
export const SET_AMOUNT = 'SET_AMOUNT'
export const SET_ONCHAIN_AMOUNT = 'SET_ONCHAIN_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
// ------------------------------------
@ -40,98 +20,13 @@ export function setFormType(formType) {
}
}
export function setForm({ modalOpen, formType }) {
return {
type: SET_FORM,
modalOpen,
formType
}
}
export function setAmount(amount) {
return {
type: SET_AMOUNT,
amount
}
}
export function setOnchainAmount(onchainAmount) {
return {
type: SET_ONCHAIN_AMOUNT,
onchainAmount
}
}
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_TYPE]: (state, { formType }) => ({ ...state, formType }),
[SET_FORM]: (state, { modalOpen, formType }) => ({ ...state, modalOpen, formType }),
[SET_AMOUNT]: (state, { amount }) => ({ ...state, amount }),
[SET_ONCHAIN_AMOUNT]: (state, { onchainAmount }) => ({ ...state, onchainAmount }),
[SET_MESSAGE]: (state, { message }) => ({ ...state, message }),
[SET_PUBKEY]: (state, { pubkey }) => ({ ...state, pubkey }),
[SET_PAYMENT_REQUEST]: (state, { payment_request }) => ({ ...state, payment_request }),
[RESET_FORM]: () => (initialState)
[SET_FORM_TYPE]: (state, { formType }) => ({ ...state, formType })
}
// ------------------------------------
// Selector
// ------------------------------------
const formSelectors = {}
const paymentRequestSelector = state => state.form.payment_request
formSelectors.isOnchain = createSelector(
paymentRequestSelector,
(paymentRequest) => {
// TODO: work with bitcoin-js to fix p2wkh error and make testnet/mainnet dynamic
try {
bitcoin.address.toOutputScript(paymentRequest, bitcoin.networks.testnet)
return true
} catch (e) {
return false
}
}
)
// TODO: Add more robust logic to detect a LN payment request
formSelectors.isLn = createSelector(
paymentRequestSelector,
paymentRequest => paymentRequest.length === 124
)
export { formSelectors }
// ------------------------------------
// Reducer
// ------------------------------------

21
app/routes/app/containers/AppContainer.js

@ -7,18 +7,7 @@ import { showModal, hideModal } from 'reducers/modal'
import { payInvoice } from 'reducers/payment'
import { sendCoins } from 'reducers/transaction'
import { fetchChannels } from 'reducers/channels'
import {
setFormType,
setForm,
setPaymentType,
setAmount,
setOnchainAmount,
setMessage,
setPubkey,
setPaymentRequest,
formSelectors
} from 'reducers/form'
import { setFormType } from 'reducers/form'
import { setPayAmount, setPayInput, payFormSelectors } from 'reducers/payform'
import { setRequestAmount, setRequestMemo } from 'reducers/requestform'
@ -31,13 +20,7 @@ const mapDispatchToProps = {
setCurrency,
fetchBalance,
fetchInfo,
setAmount,
setOnchainAmount,
setMessage,
setPubkey,
setPaymentRequest,
setForm,
setPaymentType,
createInvoice,
hideModal,
payInvoice,

Loading…
Cancel
Save