Skip to content

Commit

Permalink
#24 check if allowance exists and use it by default
Browse files Browse the repository at this point in the history
  • Loading branch information
motorina0 committed Jun 18, 2021
1 parent 74ee5e3 commit 9f3bd8d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
31 changes: 25 additions & 6 deletions src/components/InvoiceDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export default {
isConfigValid: false,
paymentChecker: null,
currentView: 'invoice',
allowance: null,
paymentStatus: {
isPayed: false,
message: '...',
Expand All @@ -87,6 +88,18 @@ export default {
this.isConfigValid = await configSvc.isConfigValid()
this.activeWallet = await configSvc.getActiveWallet()
this.fetchBalance()
try {
const response = await lnbitsApi(this.serverUrl).getWithdrawLinks(this.activeWallet)
const withdrawLinks = response.data || []
await configSvc.setWithdrawLinks(withdrawLinks)
this.allowance = withdrawLinks.find((link) => link.title === this.requestedBy)
if (this.allowance) {
await this.payInvoice()
}
} catch (err) {
console.error(err)
}
},
computed: {
Expand All @@ -102,25 +115,31 @@ export default {
methods: {
payInvoice: async function () {
try {
this.showPaymentInProgressCard()
const response = await lnbitsApi(this.serverUrl).payInvoice(
this.activeWallet,
this.paymentRequest
)
if (this.allowance) {
console.log('###################### will try to pay using allowance: ', this.allowance)
this.showPaymentInProgressCard('Using allowance for payment')
} else {
this.showPaymentInProgressCard()
await lnbitsApi(this.serverUrl).payInvoice(this.activeWallet, this.paymentRequest)
}
console.log('###################### this.invoice: ', this.invoice)
clearInterval(this.paymentChecker)
setTimeout(() => {
clearInterval(this.paymentChecker)
}, 40000)
const payResponse = await lnbitsApi(this.serverUrl).getPayment(
this.activeWallet,
response.data.payment_hash
this.invoice.hash
)
this.paymentChecker = setInterval(() => {
if (payResponse.data.paid) {
clearInterval(this.paymentChecker)
const preimageHtml = `<p class="text-wrap"><strong>Preimage: </strong> ${payResponse.data.preimage} </p>`
this.showPaymentCompentedCard(preimageHtml)
// show notif if allowance, close
}
}, 1000)
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion src/services/lnbits-api.svc.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function lnbitsApi(serverUrl) {
getWithdrawLinks: function (wallet) {
return this.request(
'get',
'/withdraw/api/v1/links/',
'/withdraw/api/v1/links',
wallet.inkey
)
}
Expand Down

0 comments on commit 9f3bd8d

Please sign in to comment.