Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
fix(invoice-amt-paid): settled invoices show amt_paid
Browse files Browse the repository at this point in the history
Settled invoices show the amount paid by the payee instead of the requested
value from the invoice. This involves using an updated version of the lnd rpc
protocol.

This is in response to issue #654.

amt_paid is exposed to users via invoice.finalAmount, which is constructed
via a new invoice decorator.
  • Loading branch information
wraithm committed Aug 21, 2018
1 parent 8457549 commit cdcd5b7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/components/Activity/InvoiceModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const InvoiceModal = ({
<section className={styles.amount}>
<h1>
<Value
value={invoice.value}
value={invoice.finalAmount}
currency={ticker.currency}
currentTicker={currentTicker}
/>
Expand Down
12 changes: 12 additions & 0 deletions app/lib/utils/btc.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ export function satoshisToUsd(satoshis, price) {
return btcToUsd(satoshisToBtc(satoshis), price)
}

////////////////////////////////
// millisatoshis to satoshis //
//////////////////////////////

export function millisatoshisToSatoshis(millisatoshis) {
if (millisatoshis === undefined || millisatoshis === null || millisatoshis === '') return null

return Math.round(millisatoshis / 1000)
}


export function renderCurrency(currency) {
switch (currency) {
Expand Down Expand Up @@ -139,6 +149,8 @@ export default {
satoshisToBits,
satoshisToUsd,

millisatoshisToSatoshis,

renderCurrency,

convert
Expand Down
21 changes: 20 additions & 1 deletion app/reducers/invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ export const INVOICE_FAILED = 'INVOICE_FAILED'

export const UPDATE_INVOICE = 'UPDATE_INVOICE'

// ------------------------------------
// Helpers
// ------------------------------------

// Decorate invoice object with custom/computed properties.
const decorateInvoice = invoice => {
invoice.finalAmount = invoice.value
if (invoice.amt_paid) {
invoice.finalAmount = btc.millisatoshisToSatoshis(invoice.amt_paid)
}
return invoice
}

// ------------------------------------
// Actions
// ------------------------------------
Expand Down Expand Up @@ -94,8 +107,10 @@ export const fetchInvoices = () => dispatch => {
}

// Receive IPC event for invoices
export const receiveInvoices = (event, { invoices }) => dispatch =>
export const receiveInvoices = (event, { invoices }) => dispatch => {
dispatch({ type: RECEIVE_INVOICES, invoices })
invoices.forEach(decorateInvoice)
}

// Send IPC event for creating an invoice
export const createInvoice = (amount, memo, currency) => dispatch => {
Expand All @@ -111,6 +126,8 @@ export const createdInvoice = (event, invoice) => dispatch => {
// Close the form modal once the payment was succesful
dispatch(setFormType(null))

decorateInvoice(invoice)

// Add new invoice to invoices list
dispatch({ type: INVOICE_SUCCESSFUL, invoice })

Expand All @@ -136,6 +153,8 @@ export const invoiceUpdate = (event, { invoice }) => dispatch => {
// Fetch new balance
dispatch(fetchBalance())

decorateInvoice(invoice)

if (invoice.settled) {
// HTML 5 desktop notification for the invoice update
const notifTitle = "You've been Zapped"
Expand Down
8 changes: 6 additions & 2 deletions app/routes/activity/components/components/Invoice/Invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ const Invoice = ({ invoice, ticker, currentTicker, showActivityModal, currencyNa
>
<span>
<i className={styles.plus}>+</i>
<Value value={invoice.value} currency={ticker.currency} currentTicker={currentTicker} />
<Value
value={invoice.finalAmount}
currency={ticker.currency}
currentTicker={currentTicker}
/>
<i> {currencyName}</i>
</span>
<span>
<span>${btc.convert('sats', 'usd', invoice.value, currentTicker.price_usd)}</span>
<span>${btc.convert('sats', 'usd', invoice.finalAmount, currentTicker.price_usd)}</span>
</span>
</div>
</div>
Expand Down

0 comments on commit cdcd5b7

Please sign in to comment.