Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Commit 9e3e2c8

Browse files
kaplanmaxebryanvu
authored andcommitted
decoding payment request descriptions properly
1 parent 9014e80 commit 9e3e2c8

File tree

3 files changed

+45
-13
lines changed

3 files changed

+45
-13
lines changed

apps/desktop/rpc.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,4 +602,7 @@ message PayReq {
602602
string destination = 1 [json_name = "destination"];
603603
string payment_hash = 2 [json_name = "payment_hash"];
604604
int64 num_satoshis = 3 [json_name = "num_satoshis"];
605+
uint32 timestamp = 4 [json_name = "timestamp"];
606+
uint32 expiry = 5 [json_name = "expiry"];
607+
string description = 6 [json_name = "description"];
605608
}

packages/lightning-core/pay/index.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,16 @@ export const Pay = ({ onMakePayment, onDecodePaymentRequest, onEditForm,
2727
required: true,
2828
component: CurrencyInput,
2929
},
30+
{
31+
name: 'description',
32+
placeholder: 'Description',
33+
component: Input,
34+
hide: true,
35+
disabled: true,
36+
},
3037
]
38+
// If current form is a payment request
39+
let requestActive = false
3140

3241
const menu = new Menu()
3342
menu.append(new MenuItem({ label: 'Paste', role: 'paste' }))
@@ -47,16 +56,34 @@ export const Pay = ({ onMakePayment, onDecodePaymentRequest, onEditForm,
4756
console.log('error', errors)
4857
}
4958

50-
const handleChange = (change) => {
59+
// Clear all fields in form
60+
const clearForm = () => {
61+
onEditForm('pay', {
62+
address: '',
63+
amount: '',
64+
description: '',
65+
})
5166
fields[1].disabled = false
67+
fields[2].hide = true
68+
}
69+
70+
// Handle change on payment form
71+
const handleChange = (change) => {
72+
if (requestActive === true) {
73+
clearForm()
74+
requestActive = false
75+
}
5276
if (change.address) {
5377
const paymentRequest = sanitizePaymentRequest(change.address)
5478
onDecodePaymentRequest({ paymentRequest })
5579
.then((decoded) => {
80+
requestActive = true
5681
const amount = decoded.num_satoshis
82+
const description = decoded.description
5783
// Disable the amount field when using payment requests
5884
fields[1].disabled = true
59-
onEditForm('pay', { amount })
85+
if (description) { fields[2].hide = false }
86+
onEditForm('pay', { amount, description: decoded.description })
6087
})
6188
.catch(console.error)
6289
}

packages/lightning-forms/components/Field.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react'
22
import reactCSS from 'reactcss'
33

44
export const Field = ({ name, type, placeholder, value, component, onChange,
5-
disabled, errorText, error }) => {
5+
disabled, errorText, error, hide }) => {
66
const styles = reactCSS({
77
'default': {
88
field: {
@@ -25,16 +25,18 @@ export const Field = ({ name, type, placeholder, value, component, onChange,
2525

2626
return (
2727
<div style={ styles.field }>
28-
<Component
29-
style={ styles.field }
30-
name={ name }
31-
type={ type }
32-
placeholder={ placeholder }
33-
value={ value }
34-
disabled={ disabled }
35-
onChange={ handleChange }
36-
outlineColor={ error && 'rgba(213, 61, 80, 0.3)' }
37-
/>
28+
{!hide && (
29+
<Component
30+
style={ styles.field }
31+
name={ name }
32+
type={ type }
33+
placeholder={ placeholder }
34+
value={ value }
35+
disabled={ disabled }
36+
onChange={ handleChange }
37+
outlineColor={ error && 'rgba(213, 61, 80, 0.3)' }
38+
/>
39+
)}
3840
{ errorText ? <div style={ styles.error }>{ errorText }</div> : null }
3941
</div>
4042
)

0 commit comments

Comments
 (0)