Browse Source

feature(sendcoins): working demo of UX flow

renovate/lint-staged-8.x
Jack Mallers 7 years ago
parent
commit
d8c5623e01
  1. 4
      app/reducers/form.js
  2. 4
      app/routes/app/components/components/Form/Form.js
  3. 104
      app/routes/app/components/components/Form/components/Pay/Pay.js
  4. 29
      app/routes/app/components/components/Form/components/Pay/Pay.scss
  5. 2
      package.json

4
app/reducers/form.js

@ -1,8 +1,8 @@
// Initial State // Initial State
const initialState = { const initialState = {
modalOpen: true, modalOpen: false,
formType: 'pay', formType: 'pay',
paymentType: 'onchain', paymentType: '',
amount: '0', amount: '0',
message: '', message: '',
pubkey: '', pubkey: '',

4
app/routes/app/components/components/Form/Form.js

@ -34,7 +34,9 @@ const Form = ({
<Pay <Pay
paymentType={paymentType} paymentType={paymentType}
setPaymentType={setPaymentType} setPaymentType={setPaymentType}
amount={formInvoice.amount} invoiceAmount={formInvoice.amount}
onchainAmount={amount}
setAmount={setAmount}
payment_request={payment_request} payment_request={payment_request}
setPaymentRequest={setPaymentRequest} setPaymentRequest={setPaymentRequest}
fetchInvoice={fetchInvoice} fetchInvoice={fetchInvoice}

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

@ -8,7 +8,9 @@ import styles from './Pay.scss'
const Pay = ({ const Pay = ({
paymentType, paymentType,
setPaymentType, setPaymentType,
amount, invoiceAmount,
onchainAmount,
setAmount,
payment_request, payment_request,
setPaymentRequest, setPaymentRequest,
fetchInvoice, fetchInvoice,
@ -26,59 +28,84 @@ const Pay = ({
const paymentRequestOnChange = payreq => { const paymentRequestOnChange = payreq => {
setPaymentRequest(payreq) setPaymentRequest(payreq)
if (payreq.length === 124) { fetchInvoice(payreq) } if (payreq.length === 124) {
setPaymentType('ln')
fetchInvoice(payreq)
} else if (payreq.length === 42) {
setPaymentType('onchain')
} else {
setPaymentType('')
}
} }
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}> <section className={`${styles.amountContainer} ${paymentType === 'ln' ? styles.ln : ''}`}>
<label htmlFor='amount'> <label htmlFor='amount'>
<CurrencyIcon currency={currency} crypto={crypto} /> <CurrencyIcon currency={currency} crypto={crypto} />
</label> </label>
<input <input
type='text' type='text'
size='' size=''
style={{ width: '75%', fontSize: '85px' }} style={
value={calculateAmount(amount)} paymentType === 'ln' ?
{ width: '75%', fontSize: '85px' }
:
{ width: `${onchainAmount.length > 1 ? (onchainAmount.length * 15) - 5 : 25}%`, fontSize: `${190 - (onchainAmount.length ** 2)}px` }
}
value={paymentType === 'ln' ? calculateAmount(invoiceAmount) : onchainAmount}
onChange={event => setAmount(event.target.value)}
id='amount' id='amount'
readOnly readOnly={paymentType === 'ln'}
/> />
</section> </section>
<div <div className={styles.inputContainer}>
className={`${styles.onchain} ${paymentType === 'onchain' ? styles.active : null}`} <div className={styles.info}>
onClick={() => setPaymentType('onchain')} {(() => {
> switch(paymentType) {
<aside className={`${styles.paymentIcon} ${styles.chain}`}> case 'onchain':
<span>on-chain</span> return (
<FaChain /> <span>{`You're about to send ${onchainAmount} on-chain which should take around 10 minutes`}</span>
</aside> )
<section className={styles.inputContainer}> case 'ln':
<label htmlFor='paymentRequest'>Address:</label> return (
<input <span>{`You're about to send ${calculateAmount(invoiceAmount)} over the Lightning Network which will be instant`}</span>
type='text' )
placeholder='Bitcoin address' default:
value={payment_request} return null
onChange={event => paymentRequestOnChange(event.target.value)} }
id='paymentRequest' })()}
/> </div>
</section> <aside className={styles.paymentIcon}>
</div> {(() => {
<div className={styles.divider} /> switch(paymentType) {
<div case 'onchain':
className={`${styles.ln} ${paymentType === 'ln' ? styles.active : null}`} return (
onClick={() => setPaymentType('ln')} <i>
> <span>on-chain</span>
<aside className={`${styles.paymentIcon} ${styles.bolt}`}> <FaChain />
<span>lightning network</span> </i>
<FaBolt /> )
case 'ln':
return (
<i>
<span>lightning network</span>
<FaBolt />
</i>
)
default:
return null
}
})()}
</aside> </aside>
<section className={styles.inputContainer}> <section className={styles.input}>
<label htmlFor='paymentRequest'>Request:</label>
<input <input
type='text' type='text'
placeholder='Payment Request' placeholder='Payment request or bitcoin address'
value={payment_request} value={payment_request}
onChange={event => paymentRequestOnChange(event.target.value)} onChange={event => paymentRequestOnChange(event.target.value)}
id='paymentRequest' id='paymentRequest'
@ -95,7 +122,10 @@ const Pay = ({
} }
Pay.propTypes = { Pay.propTypes = {
amount: PropTypes.string.isRequired, amount: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number
]),
setPaymentRequest: PropTypes.func.isRequired, setPaymentRequest: PropTypes.func.isRequired,
fetchInvoice: PropTypes.func.isRequired, fetchInvoice: PropTypes.func.isRequired,
payInvoice: PropTypes.func.isRequired, payInvoice: PropTypes.func.isRequired,

29
app/routes/app/components/components/Form/components/Pay/Pay.scss

@ -15,6 +15,11 @@
justify-content: center; justify-content: center;
min-height: 120px; min-height: 120px;
margin-bottom: 20px; margin-bottom: 20px;
transition: all 0.25s;
&.ln {
opacity: 0.75;
}
label, input[type=text] { label, input[type=text] {
color: inherit; color: inherit;
@ -47,22 +52,23 @@
} }
} }
.onchain, .ln { .inputContainer {
position: relative; position: relative;
width: 100%; width: 100%;
padding: 40px 0; padding: 40px 0;
opacity: 0.25;
cursor: pointer; cursor: pointer;
transition: all 0.25s; transition: all 0.25s;
&.active { .info {
opacity: 1; margin-bottom: 10px;
min-height: 19px;
} }
.paymentIcon { .paymentIcon {
position: absolute; position: absolute;
width: 20%; width: 20%;
left: calc(-12.5% - 75px); left: calc(-12.5% - 75px);
top: 42px;
color: $main; color: $main;
font-size: 50px; font-size: 50px;
text-align: center; text-align: center;
@ -76,20 +82,7 @@
} }
} }
.divider { .input {
height: 1px;
background: $main;
width: 150%;
}
.onchain {
}
.ln {
margin-bottom: 20px;
}
.inputContainer {
display: flex; display: flex;
justify-content: center; justify-content: center;
font-size: 18px; font-size: 18px;

2
package.json

@ -8,7 +8,7 @@
"build-dll": "cross-env NODE_ENV=development node --trace-warnings -r babel-register ./node_modules/webpack/bin/webpack --config webpack.config.renderer.dev.dll.js --colors", "build-dll": "cross-env NODE_ENV=development node --trace-warnings -r babel-register ./node_modules/webpack/bin/webpack --config webpack.config.renderer.dev.dll.js --colors",
"build-main": "cross-env NODE_ENV=production node --trace-warnings -r babel-register ./node_modules/webpack/bin/webpack --config webpack.config.main.prod.js --colors", "build-main": "cross-env NODE_ENV=production node --trace-warnings -r babel-register ./node_modules/webpack/bin/webpack --config webpack.config.main.prod.js --colors",
"build-renderer": "cross-env NODE_ENV=production node --trace-warnings -r babel-register ./node_modules/webpack/bin/webpack --config webpack.config.renderer.prod.js --colors", "build-renderer": "cross-env NODE_ENV=production node --trace-warnings -r babel-register ./node_modules/webpack/bin/webpack --config webpack.config.renderer.prod.js --colors",
"dev": "cross-env START_HOT=1 concurrently \"npm run start-renderer-dev\" \"npm run lnd\"", "dev": "cross-env START_HOT=1 concurrently \"npm run start-renderer-dev\"",
"flow": "flow", "flow": "flow",
"flow-typed": "rimraf flow-typed/npm && flow-typed install --overwrite || true", "flow-typed": "rimraf flow-typed/npm && flow-typed install --overwrite || true",
"lint": "eslint --cache --format=node_modules/eslint-formatter-pretty .", "lint": "eslint --cache --format=node_modules/eslint-formatter-pretty .",

Loading…
Cancel
Save