Skip to content

Commit 9f3bd8d

Browse files
committed
#24 check if allowance exists and use it by default
1 parent 74ee5e3 commit 9f3bd8d

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

src/components/InvoiceDetails.vue

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export default {
7070
isConfigValid: false,
7171
paymentChecker: null,
7272
currentView: 'invoice',
73+
allowance: null,
7374
paymentStatus: {
7475
isPayed: false,
7576
message: '...',
@@ -87,6 +88,18 @@ export default {
8788
this.isConfigValid = await configSvc.isConfigValid()
8889
this.activeWallet = await configSvc.getActiveWallet()
8990
this.fetchBalance()
91+
92+
try {
93+
const response = await lnbitsApi(this.serverUrl).getWithdrawLinks(this.activeWallet)
94+
const withdrawLinks = response.data || []
95+
await configSvc.setWithdrawLinks(withdrawLinks)
96+
this.allowance = withdrawLinks.find((link) => link.title === this.requestedBy)
97+
if (this.allowance) {
98+
await this.payInvoice()
99+
}
100+
} catch (err) {
101+
console.error(err)
102+
}
90103
},
91104
92105
computed: {
@@ -102,25 +115,31 @@ export default {
102115
methods: {
103116
payInvoice: async function () {
104117
try {
105-
this.showPaymentInProgressCard()
106-
const response = await lnbitsApi(this.serverUrl).payInvoice(
107-
this.activeWallet,
108-
this.paymentRequest
109-
)
118+
119+
if (this.allowance) {
120+
console.log('###################### will try to pay using allowance: ', this.allowance)
121+
this.showPaymentInProgressCard('Using allowance for payment')
122+
} else {
123+
this.showPaymentInProgressCard()
124+
await lnbitsApi(this.serverUrl).payInvoice(this.activeWallet, this.paymentRequest)
125+
}
126+
127+
console.log('###################### this.invoice: ', this.invoice)
110128
clearInterval(this.paymentChecker)
111129
setTimeout(() => {
112130
clearInterval(this.paymentChecker)
113131
}, 40000)
114132
const payResponse = await lnbitsApi(this.serverUrl).getPayment(
115133
this.activeWallet,
116-
response.data.payment_hash
134+
this.invoice.hash
117135
)
118136
119137
this.paymentChecker = setInterval(() => {
120138
if (payResponse.data.paid) {
121139
clearInterval(this.paymentChecker)
122140
const preimageHtml = `<p class="text-wrap"><strong>Preimage: </strong> ${payResponse.data.preimage} </p>`
123141
this.showPaymentCompentedCard(preimageHtml)
142+
// show notif if allowance, close
124143
}
125144
}, 1000)
126145
} catch (err) {

src/services/lnbits-api.svc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function lnbitsApi(serverUrl) {
6363
getWithdrawLinks: function (wallet) {
6464
return this.request(
6565
'get',
66-
'/withdraw/api/v1/links/',
66+
'/withdraw/api/v1/links',
6767
wallet.inkey
6868
)
6969
}

0 commit comments

Comments
 (0)