notification

This commit is contained in:
callebtc
2022-11-07 21:59:58 +01:00
parent d955e434b0
commit 55f8c0b1a7
2 changed files with 163 additions and 42 deletions

View File

@@ -16,7 +16,7 @@ page_container %}
icon="bolt" icon="bolt"
rectangle rectangle
color="primary" color="primary"
@click="showInvoicesDialog" @click="showInvoiceCreateDialog"
><strong>Get invoice</strong> ><strong>Get invoice</strong>
</q-btn> </q-btn>
</div> </div>
@@ -152,7 +152,7 @@ page_container %}
<q-td key="status" :props="props"> <q-td key="status" :props="props">
<div v-if="props.row.status == 'pending'"> <div v-if="props.row.status == 'pending'">
<q-icon <q-icon
@click="showInvoiceDialog(props.row)" @click="showInvoicInfoDialog(props.row)"
name="settings_ethernet" name="settings_ethernet"
color="grey" color="grey"
> >
@@ -314,7 +314,7 @@ page_container %}
class="q-pa-none" class="q-pa-none"
icon="bolt" icon="bolt"
label="Get invoice" label="Get invoice"
@click="showInvoicesDialog" @click="showInvoiceCreateDialog"
> >
</q-tab> </q-tab>
<q-tab icon="photo_camera" v-if="hasCamera" @click="showCamera"> <q-tab icon="photo_camera" v-if="hasCamera" @click="showCamera">
@@ -494,7 +494,7 @@ page_container %}
dense dense
v-model.trim="payInvoiceData.data.request" v-model.trim="payInvoiceData.data.request"
type="textarea" type="textarea"
label="Enter an invoice *" label="Enter a Lightning invoice *"
> >
</q-input> </q-input>
<div class="row q-mt-lg"> <div class="row q-mt-lg">
@@ -1194,7 +1194,15 @@ page_container %}
timeout: 5000, timeout: 5000,
type: 'warning', type: 'warning',
message: `${this.receive.lnurl.domain} lnurl-withdraw call failed.`, message: `${this.receive.lnurl.domain} lnurl-withdraw call failed.`,
caption: response.data.lnurl_response caption: response.data.lnurl_response,
position: 'top',
actions: [
{
icon: 'close',
color: 'white',
handler: () => {}
}
]
}) })
return return
} else if (response.data.lnurl_response === true) { } else if (response.data.lnurl_response === true) {
@@ -1202,7 +1210,15 @@ page_container %}
this.$q.notify({ this.$q.notify({
timeout: 5000, timeout: 5000,
message: `Invoice sent to ${this.receive.lnurl.domain}!`, message: `Invoice sent to ${this.receive.lnurl.domain}!`,
spinner: true spinner: true,
position: 'top',
actions: [
{
icon: 'close',
color: 'white',
handler: () => {}
}
]
}) })
} }
} }
@@ -1276,7 +1292,15 @@ page_container %}
timeout: 3000, timeout: 3000,
type: 'warning', type: 'warning',
message: error + '.', message: error + '.',
caption: '400 BAD REQUEST' caption: 'Failed to decode invoice',
position: 'top',
actions: [
{
icon: 'close',
color: 'white',
handler: () => {}
}
]
}) })
this.payInvoiceData.show = false this.payInvoiceData.show = false
throw error throw error
@@ -1322,19 +1346,43 @@ page_container %}
payInvoice: function () { payInvoice: function () {
let dismissPaymentMsg = this.$q.notify({ let dismissPaymentMsg = this.$q.notify({
timeout: 0, timeout: 0,
message: 'Processing payment...' message: 'Processing payment...',
position: 'top',
actions: [
{
icon: 'close',
color: 'white',
handler: () => {}
}
]
}) })
}, },
payLnurl: function () { payLnurl: function () {
let dismissPaymentMsg = this.$q.notify({ let dismissPaymentMsg = this.$q.notify({
timeout: 0, timeout: 0,
message: 'Processing payment...' message: 'Processing payment...',
position: 'top',
actions: [
{
icon: 'close',
color: 'white',
handler: () => {}
}
]
}) })
}, },
authLnurl: function () { authLnurl: function () {
let dismissAuthMsg = this.$q.notify({ let dismissAuthMsg = this.$q.notify({
timeout: 10, timeout: 10,
message: 'Performing authentication...' message: 'Performing authentication...',
position: 'top',
actions: [
{
icon: 'close',
color: 'white',
handler: () => {}
}
]
}) })
}, },
@@ -1364,8 +1412,8 @@ page_container %}
}, },
/////////////////////////////////// WALLET /////////////////////////////////// /////////////////////////////////// WALLET ///////////////////////////////////
showInvoicesDialog: async function () { showInvoiceCreateDialog: async function () {
console.log('##### showInvoicesDialog') console.log('##### showInvoiceCreateDialog')
this.invoiceData.amount = '' this.invoiceData.amount = ''
this.invoiceData.bolt11 = '' this.invoiceData.bolt11 = ''
this.invoiceData.hash = '' this.invoiceData.hash = ''
@@ -1373,21 +1421,21 @@ page_container %}
this.showInvoiceDetails = true this.showInvoiceDetails = true
}, },
showInvoiceDialog: function (data) { showInvoicInfoDialog: function (data) {
console.log('##### showInvoiceDialog') console.log('##### showInvoicInfoDialog')
this.invoiceData = _.clone(data) this.invoiceData = _.clone(data)
this.showInvoiceDetails = true this.showInvoiceDetails = true
// kick off invoice check worker // kick off invoice check worker
this.invoiceCheckWorker() this.invoiceCheckWorker()
}, },
showPayInvoiceDialog: function () { // showPayInvoiceDialog: function () {
console.log('### showPayInvoiceDialog') // console.log('### showPayInvoiceDialog')
this.payInvoiceData.invoice = '' // this.payInvoiceData.invoice = ''
this.payInvoiceData.data.request = '' // this.payInvoiceData.data.request = ''
this.showPayInvoice = true // this.showPayInvoice = true
this.camera.show = false // this.camera.show = false
}, // },
showTokenDialog: function (token) { showTokenDialog: function (token) {
console.log('##### showTokenDialog') console.log('##### showTokenDialog')
@@ -1502,7 +1550,15 @@ page_container %}
this.$q.notify({ this.$q.notify({
timeout: 5000, timeout: 5000,
type: 'positive', type: 'positive',
message: 'Payment received' message: 'Payment received',
position: 'top',
actions: [
{
icon: 'close',
color: 'white',
handler: () => {}
}
]
}) })
} catch (error) { } catch (error) {
console.log('not paid yet') console.log('not paid yet')
@@ -1595,7 +1651,15 @@ page_container %}
this.$q.notify({ this.$q.notify({
timeout: 5000, timeout: 5000,
type: 'warning', type: 'warning',
message: 'Balance too low' message: 'Balance too low',
position: 'top',
actions: [
{
icon: 'close',
color: 'white',
handler: () => {}
}
]
}) })
throw Error('balance too low.') throw Error('balance too low.')
} }
@@ -1730,7 +1794,15 @@ page_container %}
this.$q.notify({ this.$q.notify({
timeout: 5000, timeout: 5000,
type: 'positive', type: 'positive',
message: 'Tokens received' message: 'Tokens received',
position: 'top',
actions: [
{
icon: 'close',
color: 'white',
handler: () => {}
}
]
}) })
} catch (error) { } catch (error) {
console.error(error) console.error(error)
@@ -1827,7 +1899,15 @@ page_container %}
this.$q.notify({ this.$q.notify({
timeout: 5000, timeout: 5000,
type: 'positive', type: 'positive',
message: 'Invoice paid' message: 'Invoice paid',
position: 'top',
actions: [
{
icon: 'close',
color: 'white',
handler: () => {}
}
]
}) })
// delete spent tokens from db // delete spent tokens from db
this.proofs = fristProofs this.proofs = fristProofs
@@ -1955,7 +2035,15 @@ page_container %}
this.$q.notify({ this.$q.notify({
timeout: 5000, timeout: 5000,
type: 'positive', type: 'positive',
message: 'Token paid' message: 'Token paid',
position: 'top',
actions: [
{
icon: 'close',
color: 'white',
handler: () => {}
}
]
}) })
} else { } else {
console.log('### token not paid yet') console.log('### token not paid yet')
@@ -1963,7 +2051,15 @@ page_container %}
this.$q.notify({ this.$q.notify({
timeout: 5000, timeout: 5000,
color: 'grey', color: 'grey',
message: 'Token still pending' message: 'Token still pending',
position: 'top',
actions: [
{
icon: 'close',
color: 'white',
handler: () => {}
}
]
}) })
} }
this.sendData.tokens = token this.sendData.tokens = token
@@ -2049,7 +2145,15 @@ page_container %}
timeout: 5000, timeout: 5000,
type: 'warning', type: 'warning',
message: 'Could not decode invoice', message: 'Could not decode invoice',
caption: error + '' caption: error + '',
position: 'top',
actions: [
{
icon: 'close',
color: 'white',
handler: () => {}
}
]
}) })
throw error throw error
} }
@@ -2129,7 +2233,8 @@ page_container %}
} else { } else {
this.$q.notify({ this.$q.notify({
color: 'red', color: 'red',
message: 'No mint set!' message: 'No mint set!',
position: 'center'
}) })
} }
@@ -2190,6 +2295,7 @@ page_container %}
// get recv_token to receive tokens from a link // get recv_token to receive tokens from a link
if (params.get('recv_token')) { if (params.get('recv_token')) {
tokenBase64 = params.get('recv_token') tokenBase64 = params.get('recv_token')
// make sure to react only to tokens not in the users history
let seen = false let seen = false
for (var i = 0; i < this.historyTokens.length; i++) { for (var i = 0; i < this.historyTokens.length; i++) {
var thisToken = this.historyTokens[i].token var thisToken = this.historyTokens[i].token
@@ -2198,24 +2304,17 @@ page_container %}
} }
} }
if (!seen) { if (!seen) {
// show receive token dialog
this.receiveData.tokensBase64 = params.get('recv_token') this.receiveData.tokensBase64 = params.get('recv_token')
this.showReceiveTokens = true this.showReceiveTokens = true
} }
} }
var body = document.body, // get lightning invoice from a link
html = document.documentElement if (params.get('lightning')) {
this.showParseDialog()
var height = Math.max( this.payInvoiceData.data.request = params.get('lightning')
body.scrollHeight, }
body.offsetHeight,
html.clientHeight,
html.scrollHeight,
html.offsetHeight
)
console.log('height', height)
this.height = height
console.log('### invoicesCashu', this.invoicesCashu) console.log('### invoicesCashu', this.invoicesCashu)
console.table('### tokens', this.proofs) console.table('### tokens', this.proofs)
@@ -2224,6 +2323,24 @@ page_container %}
this.recheckPendingInvoices() this.recheckPendingInvoices()
this.recheckPendingTokens() this.recheckPendingTokens()
// register lightning: link
// Intercept any `lightning:` requests
window.addEventListener('click', ev => {
// Use composedPath() for detecting links inside a Shadow DOM
// https://developer.mozilla.org/en-US/docs/Web/API/Event/composedPath
const target = ev.composedPath()[0]
if (!target || !target.closest) {
return
}
const lightningLink = target.closest('[href^="lightning:" i]')
if (lightningLink) {
href = lightningLink.getAttribute('href').toLowerCase()
paymentRequest = href.replace('lightning:', '')
link = lightningLink
}
})
} }
}) })
</script> </script>

View File

@@ -78,6 +78,10 @@ async def manifest(cashu_id: str):
"display": "standalone", "display": "standalone",
"scope": "/cashu/", "scope": "/cashu/",
"theme_color": "#1F2234", "theme_color": "#1F2234",
"protocol_handlers": [
{"protocol": "cashu", "url": "&recv_token=%s"},
{"protocol": "lightning", "url": "&lightning=%s"},
],
"shortcuts": [ "shortcuts": [
{ {
"name": "Cashu" + " - " + cashu.name, "name": "Cashu" + " - " + cashu.name,