Browse Source

feature(sendcoins): add onchainAmount as own field in form reducer

renovate/lint-staged-8.x
Jack Mallers 7 years ago
parent
commit
96a435f59a
  1. 10
      app/reducers/form.js
  2. 3
      app/routes/app/components/App.js
  3. 8
      app/routes/app/components/components/Form/Form.js
  4. 7
      app/routes/app/components/components/Form/components/Pay/Pay.js
  5. 2
      app/routes/app/containers/AppContainer.js

10
app/reducers/form.js

@ -4,6 +4,7 @@ const initialState = {
formType: 'pay', formType: 'pay',
paymentType: '', paymentType: '',
amount: '0', amount: '0',
onchainAmount: '0',
message: '', message: '',
pubkey: '', pubkey: '',
payment_request: '' payment_request: ''
@ -13,6 +14,7 @@ const initialState = {
// ------------------------------------ // ------------------------------------
export const SET_FORM = 'SET_FORM' export const SET_FORM = 'SET_FORM'
export const SET_AMOUNT = 'SET_AMOUNT' export const SET_AMOUNT = 'SET_AMOUNT'
export const SET_ONCHAIN_AMOUNT = 'SET_ONCHAIN_AMOUNT'
export const SET_MESSAGE = 'SET_MESSAGE' export const SET_MESSAGE = 'SET_MESSAGE'
export const SET_PUBKEY = 'SET_PUBKEY' export const SET_PUBKEY = 'SET_PUBKEY'
export const SET_PAYMENT_TYPE = 'SET_PAYMENT_TYPE' export const SET_PAYMENT_TYPE = 'SET_PAYMENT_TYPE'
@ -44,6 +46,13 @@ export function setAmount(amount) {
} }
} }
export function setOnchainAmount(onchainAmount) {
return {
type: SET_ONCHAIN_AMOUNT,
onchainAmount
}
}
export function setMessage(message) { export function setMessage(message) {
return { return {
type: SET_MESSAGE, type: SET_MESSAGE,
@ -77,6 +86,7 @@ export function resetForm() {
const ACTION_HANDLERS = { const ACTION_HANDLERS = {
[SET_FORM]: (state, { modalOpen, formType }) => ({ ...state, modalOpen, formType }), [SET_FORM]: (state, { modalOpen, formType }) => ({ ...state, modalOpen, formType }),
[SET_AMOUNT]: (state, { amount }) => ({ ...state, amount }), [SET_AMOUNT]: (state, { amount }) => ({ ...state, amount }),
[SET_ONCHAIN_AMOUNT]: (state, { onchainAmount }) => ({ ...state, onchainAmount }),
[SET_MESSAGE]: (state, { message }) => ({ ...state, message }), [SET_MESSAGE]: (state, { message }) => ({ ...state, message }),
[SET_PUBKEY]: (state, { pubkey }) => ({ ...state, pubkey }), [SET_PUBKEY]: (state, { pubkey }) => ({ ...state, pubkey }),
[SET_PAYMENT_TYPE]: (state, { paymentType }) => ({ ...state, paymentType }), [SET_PAYMENT_TYPE]: (state, { paymentType }) => ({ ...state, paymentType }),

3
app/routes/app/components/App.js

@ -20,6 +20,7 @@ class App extends Component {
invoice: { formInvoice }, invoice: { formInvoice },
form, form,
setAmount, setAmount,
setOnchainAmount,
setMessage, setMessage,
setPubkey, setPubkey,
setPaymentRequest, setPaymentRequest,
@ -44,6 +45,7 @@ class App extends Component {
close={() => setForm({ modalOpen: false })} close={() => setForm({ modalOpen: false })}
setPaymentType={setPaymentType} setPaymentType={setPaymentType}
setAmount={setAmount} setAmount={setAmount}
setOnchainAmount={setOnchainAmount}
setMessage={setMessage} setMessage={setMessage}
setPubkey={setPubkey} setPubkey={setPubkey}
setPaymentRequest={setPaymentRequest} setPaymentRequest={setPaymentRequest}
@ -80,6 +82,7 @@ App.propTypes = {
invoice: PropTypes.object.isRequired, invoice: PropTypes.object.isRequired,
form: PropTypes.object.isRequired, form: PropTypes.object.isRequired,
setAmount: PropTypes.func.isRequired, setAmount: PropTypes.func.isRequired,
setOnchainAmount: PropTypes.func.isRequired,
setMessage: PropTypes.func.isRequired, setMessage: PropTypes.func.isRequired,
setPubkey: PropTypes.func.isRequired, setPubkey: PropTypes.func.isRequired,
setPaymentRequest: PropTypes.func.isRequired, setPaymentRequest: PropTypes.func.isRequired,

8
app/routes/app/components/components/Form/Form.js

@ -8,9 +8,10 @@ import { btc } from '../../../../../utils'
import styles from './Form.scss' import styles from './Form.scss'
const Form = ({ const Form = ({
form: { formType, paymentType, amount, message, payment_request }, form: { formType, paymentType, amount, onchainAmount, message, payment_request },
setPaymentType, setPaymentType,
setAmount, setAmount,
setOnchainAmount,
setMessage, setMessage,
setPaymentRequest, setPaymentRequest,
ticker: { currency, crypto }, ticker: { currency, crypto },
@ -35,8 +36,8 @@ const Form = ({
paymentType={paymentType} paymentType={paymentType}
setPaymentType={setPaymentType} setPaymentType={setPaymentType}
invoiceAmount={formInvoice.amount} invoiceAmount={formInvoice.amount}
onchainAmount={amount} onchainAmount={onchainAmount}
setAmount={setAmount} setOnchainAmount={setOnchainAmount}
payment_request={payment_request} payment_request={payment_request}
setPaymentRequest={setPaymentRequest} setPaymentRequest={setPaymentRequest}
fetchInvoice={fetchInvoice} fetchInvoice={fetchInvoice}
@ -71,6 +72,7 @@ Form.propTypes = {
setPaymentType: PropTypes.func.isRequired, setPaymentType: PropTypes.func.isRequired,
ticker: PropTypes.object.isRequired, ticker: PropTypes.object.isRequired,
setAmount: PropTypes.func.isRequired, setAmount: PropTypes.func.isRequired,
setOnchainAmount: PropTypes.func.isRequired,
setMessage: PropTypes.func.isRequired, setMessage: PropTypes.func.isRequired,
setPaymentRequest: PropTypes.func.isRequired, setPaymentRequest: PropTypes.func.isRequired,
isOpen: PropTypes.bool.isRequired, isOpen: PropTypes.bool.isRequired,

7
app/routes/app/components/components/Form/components/Pay/Pay.js

@ -10,7 +10,7 @@ const Pay = ({
setPaymentType, setPaymentType,
invoiceAmount, invoiceAmount,
onchainAmount, onchainAmount,
setAmount, setOnchainAmount,
payment_request, payment_request,
setPaymentRequest, setPaymentRequest,
fetchInvoice, fetchInvoice,
@ -40,8 +40,6 @@ const Pay = ({
const calculateAmount = value => (currency === 'usd' ? btc.satoshisToUsd(value, currentTicker.price_usd) : btc.satoshisToBtc(value)) const calculateAmount = value => (currency === 'usd' ? btc.satoshisToUsd(value, currentTicker.price_usd) : btc.satoshisToBtc(value))
console.log('paymentType: ', paymentType)
console.log('onchainAmount: ', onchainAmount)
return ( return (
<div className={styles.container}> <div className={styles.container}>
<section className={`${styles.amountContainer} ${paymentType === 'ln' ? styles.ln : ''}`}> <section className={`${styles.amountContainer} ${paymentType === 'ln' ? styles.ln : ''}`}>
@ -58,7 +56,7 @@ const Pay = ({
{ width: `${onchainAmount.length > 1 ? (onchainAmount.length * 15) - 5 : 25}%`, fontSize: `${190 - (onchainAmount.length ** 2)}px` } { width: `${onchainAmount.length > 1 ? (onchainAmount.length * 15) - 5 : 25}%`, fontSize: `${190 - (onchainAmount.length ** 2)}px` }
} }
value={paymentType === 'ln' ? calculateAmount(invoiceAmount) : onchainAmount} value={paymentType === 'ln' ? calculateAmount(invoiceAmount) : onchainAmount}
onChange={event => setAmount(event.target.value)} onChange={event => setOnchainAmount(event.target.value)}
id='amount' id='amount'
readOnly={paymentType === 'ln'} readOnly={paymentType === 'ln'}
/> />
@ -126,6 +124,7 @@ Pay.propTypes = {
PropTypes.string, PropTypes.string,
PropTypes.number PropTypes.number
]), ]),
setOnchainAmount: PropTypes.func.isRequired,
setPaymentRequest: PropTypes.func.isRequired, setPaymentRequest: PropTypes.func.isRequired,
fetchInvoice: PropTypes.func.isRequired, fetchInvoice: PropTypes.func.isRequired,
payInvoice: PropTypes.func.isRequired, payInvoice: PropTypes.func.isRequired,

2
app/routes/app/containers/AppContainer.js

@ -10,6 +10,7 @@ import {
setForm, setForm,
setPaymentType, setPaymentType,
setAmount, setAmount,
setOnchainAmount,
setMessage, setMessage,
setPubkey, setPubkey,
setPaymentRequest setPaymentRequest
@ -21,6 +22,7 @@ const mapDispatchToProps = {
fetchBalance, fetchBalance,
fetchInfo, fetchInfo,
setAmount, setAmount,
setOnchainAmount,
setMessage, setMessage,
setPubkey, setPubkey,
setPaymentRequest, setPaymentRequest,

Loading…
Cancel
Save