Skip to content

Commit

Permalink
feat(wallet): bolt11 invoices encoded in bip21 uri
Browse files Browse the repository at this point in the history
Support lightning invoices that are encoded within a bip21 bitcoin uri.

Fix LN-Zap#200
  • Loading branch information
mrfelton committed Nov 7, 2019
1 parent 571cc35 commit 1ebdb98
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ mainLog.time('Time until app is ready')
* @param {string} input Bitcoin link
*/
const handleBitcoinLink = input => {
mainLog.info('Attempting to process bitcoin uri: %s', input)
try {
const decoded = bip21.decode(input)
zap.sendMessage('bitcoinPaymentUri', decoded)
Expand Down
13 changes: 11 additions & 2 deletions renderer/reducers/pay.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,17 @@ export const lightningPaymentUri = (event, { address }) => (dispatch, getState)
* @param {{ address, options }} options Decoded bip21 payment url
* @returns {Function} Thunk
*/
export const bitcoinPaymentUri = (event, { address, options: { amount } }) => dispatch => {
dispatch(setRedirectPayReq({ address, amount }))
export const bitcoinPaymentUri = (event, { address, options = {} }) => dispatch => {
// If the bip21 data includes a bolt11 invoice in the `lightning` key handle as a lightning payment.
const { lightning } = options
if (lightning) {
dispatch(lightningPaymentUri(event, { address: lightning }))
}
// Otherwise, use the bitcoin address for on-chain payment.
else {
const { amount } = options
dispatch(setRedirectPayReq({ address, amount }))
}
}

/**
Expand Down

0 comments on commit 1ebdb98

Please sign in to comment.