Added qrdialogue

This commit is contained in:
ben 2022-10-07 11:29:06 +01:00
parent ff98b87eca
commit 52dc528a8a
3 changed files with 61 additions and 32 deletions

View File

@ -94,18 +94,17 @@
</q-td> </q-td>
<q-td> <q-td>
<q-btn <q-btn
v-if="props.row.device == 'switch'" v-if="props.row.device == 'switch'"
flat :disable="protocol == 'http:'"
dense flat
size="xs" unelevated
icon="qr_code" dense
color="grey" size="xs"
type="a" icon="visibility"
:href="'/lnurldevice/img/' + props.row.id" :color="($q.dark.isActive) ? 'grey-7' : 'grey-5'"
target="_blank" @click="openQrCodeDialog(props.row.id)"
> ><q-tooltip v-if="protocol == 'http:'"> LNURLs only work over HTTPS </q-tooltip><q-tooltip v-else> view LNURL </q-tooltip></q-btn
<q-tooltip> bitcoinSwitch embeddable QRCode </q-tooltip> >
</q-btn>
</q-td> </q-td>
<q-td <q-td
v-for="col in props.cols" v-for="col in props.cols"
@ -279,6 +278,34 @@
</q-form> </q-form>
</q-card> </q-card>
</q-dialog> </q-dialog>
<q-dialog v-model="qrCodeDialog.show" position="top">
<q-card v-if="qrCodeDialog.data" class="q-pa-lg lnbits__dialog-card">
<q-responsive :ratio="1" class="q-mx-xl q-mb-md">
<qrcode
:value="qrCodeDialog.data.url + '/?lightning=' + qrCodeDialog.data.lnurl"
:options="{width: 800}"
class="rounded-borders"
></qrcode>
{% raw %}
</q-responsive>
<p style="word-break: break-all">
<strong>ID:</strong> {{ qrCodeDialog.data.id }}<br />
</p>
{% endraw %}
<div class="row q-mt-lg q-gutter-sm">
<q-btn
outline
color="grey"
@click="copyText(qrCodeDialog.data.lnurl, 'LNURL copied to clipboard!')"
class="q-ml-sm"
>Copy LNURL</q-btn
>
<q-btn v-close-popup flat color="grey" class="q-ml-auto">Close</q-btn>
</div>
</q-card>
</q-dialog>
</div> </div>
{% endblock %} {% block scripts %} {{ window_vars(user) }} {% endblock %} {% block scripts %} {{ window_vars(user) }}
@ -306,6 +333,7 @@
mixins: [windowMixin], mixins: [windowMixin],
data: function () { data: function () {
return { return {
protocol: window.location.protocol,
location: window.location.hostname, location: window.location.hostname,
wslocation: window.location.hostname, wslocation: window.location.hostname,
filter: '', filter: '',
@ -404,6 +432,14 @@
} }
}, },
methods: { methods: {
openQrCodeDialog: function (lnurldevice_id) {
var lnurldevice = _.findWhere(this.lnurldeviceLinks, {id: lnurldevice_id})
console.log(lnurldevice)
this.qrCodeDialog.data = _.clone(lnurldevice)
this.qrCodeDialog.data.url =
window.location.protocol + '//' + window.location.host
this.qrCodeDialog.show = true
},
cancellnurldevice: function (data) { cancellnurldevice: function (data) {
var self = this var self = this
self.formDialoglnurldevice.show = false self.formDialoglnurldevice.show = false
@ -460,6 +496,7 @@
.then(function (response) { .then(function (response) {
if (response.data) { if (response.data) {
self.lnurldeviceLinks = response.data.map(maplnurldevice) self.lnurldeviceLinks = response.data.map(maplnurldevice)
console.log(response.data)
} }
}) })
.catch(function (error) { .catch(function (error) {

View File

@ -64,23 +64,8 @@ async def img(request: Request, lnurldevice_id):
raise HTTPException( raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="LNURLDevice does not exist." status_code=HTTPStatus.NOT_FOUND, detail="LNURLDevice does not exist."
) )
qr = pyqrcode.create(lnurldevice.lnurl(request)) return lnurldevice.lnurl(request)
stream = BytesIO()
qr.svg(stream, scale=3)
stream.seek(0)
async def _generator(stream: BytesIO):
yield stream.getvalue()
return StreamingResponse(
_generator(stream),
headers={
"Content-Type": "image/svg+xml",
"Cache-Control": "no-cache, no-store, must-revalidate",
"Pragma": "no-cache",
"Expires": "0",
},
)
##################WEBSOCKET ROUTES######################## ##################WEBSOCKET ROUTES########################

View File

@ -45,14 +45,21 @@ async def api_lnurldevice_create_or_update(
@lnurldevice_ext.get("/api/v1/lnurlpos") @lnurldevice_ext.get("/api/v1/lnurlpos")
async def api_lnurldevices_retrieve(wallet: WalletTypeInfo = Depends(get_key_type)): async def api_lnurldevices_retrieve(req: Request, wallet: WalletTypeInfo = Depends(get_key_type)):
wallet_ids = (await get_user(wallet.wallet.user)).wallet_ids wallet_ids = (await get_user(wallet.wallet.user)).wallet_ids
try: try:
return [ return [
{**lnurldevice.dict()} for lnurldevice in await get_lnurldevices(wallet_ids) {**lnurldevice.dict(), **{"lnurl": lnurldevice.lnurl(req)}}
for lnurldevice in await get_lnurldevices(wallet_ids)
] ]
except: except:
return "" try:
return [
{**lnurldevice.dict()}
for lnurldevice in await get_lnurldevices(wallet_ids)
]
except:
return ""
@lnurldevice_ext.get("/api/v1/lnurlpos/{lnurldevice_id}") @lnurldevice_ext.get("/api/v1/lnurlpos/{lnurldevice_id}")