Skip to content

Commit

Permalink
fixup!
Browse files Browse the repository at this point in the history
  • Loading branch information
dni committed Oct 22, 2024
1 parent 889a5fa commit fb8517a
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 137 deletions.
120 changes: 51 additions & 69 deletions static/js/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
const mapCards = obj => {
obj.date = Quasar.utils.date.formatDate(
new Date(obj.time * 1000),
'YYYY-MM-DD HH:mm'
)

obj.date = Quasar.date.formatDate(new Date(obj.time), 'YYYY-MM-DD HH:mm')
return obj
}

window.app = Vue.createApp({
el: '#vue',
mixins: [windowMixin],
data: function () {
data() {
return {
toggleAdvanced: false,
nfcTagReading: false,
Expand Down Expand Up @@ -153,13 +149,11 @@ window.app = Vue.createApp({
}
},
methods: {
readNfcTag: function () {
readNfcTag() {
try {
const self = this

if (typeof NDEFReader == 'undefined') {
throw {
toString: function () {
toString() {
return 'NFC not supported on this device or browser.'
}
}
Expand All @@ -179,7 +173,7 @@ window.app = Vue.createApp({

return ndef.scan({signal: readerAbortController.signal}).then(() => {
ndef.onreadingerror = () => {
self.nfcTagReading = false
this.nfcTagReading = false

this.$q.notify({
type: 'negative',
Expand All @@ -191,8 +185,7 @@ window.app = Vue.createApp({

ndef.onreading = ({message, serialNumber}) => {
//Decode NDEF data from tag
var self = this
self.cardDialog.data.uid = serialNumber
this.cardDialog.data.uid = serialNumber
.toUpperCase()
.replaceAll(':', '')
this.$q.notify({
Expand All @@ -211,49 +204,45 @@ window.app = Vue.createApp({
})
}
},
getCards: function () {
var self = this

getCards() {
LNbits.api
.request(
'GET',
'/boltcards/api/v1/cards?all_wallets=true',
this.g.user.wallets[0].inkey
)
.then(function (response) {
self.cards = response.data.map(function (obj) {
.then(response => {
this.cards = response.data.map(function (obj) {
return mapCards(obj)
})
})
.then(function () {
self.getHits()
.then(() => {
this.getHits()
})
},
getHits: function () {
var self = this
getHits() {
LNbits.api
.request(
'GET',
'/boltcards/api/v1/hits?all_wallets=true',
this.g.user.wallets[0].inkey
)
.then(function (response) {
self.hits = response.data.map(function (obj) {
obj.card_name = self.cards.find(d => d.id == obj.card_id).card_name
.then(response => {
this.hits = response.data.map(function (obj) {
obj.card_name = this.cards.find(d => d.id == obj.card_id).card_name
return mapCards(obj)
})
})
},
getRefunds: function () {
var self = this
getRefunds() {
LNbits.api
.request(
'GET',
'/boltcards/api/v1/refunds?all_wallets=true',
this.g.user.wallets[0].inkey
)
.then(function (response) {
self.refunds = response.data.map(function (obj) {
.then(response => {
this.refunds = response.data.map(function (obj) {
return mapCards(obj)
})
})
Expand Down Expand Up @@ -285,12 +274,11 @@ window.app = Vue.createApp({
this.qrCodeDialog.wipe = wipe
this.qrCodeDialog.show = true
},
addCardOpen: function () {
addCardOpen() {
this.cardDialog.show = true
this.generateKeys()
},
generateKeys: function () {
var self = this
generateKeys() {
const genRandomHexBytes = size =>
crypto
.getRandomValues(new Uint8Array(size))
Expand All @@ -300,22 +288,22 @@ window.app = Vue.createApp({
typeof this.cardDialog.data.card_name === 'string' &&
this.cardDialog.data.card_name.search('debug') > -1

self.cardDialog.data.k0 = debugcard
this.cardDialog.data.k0 = debugcard
? '11111111111111111111111111111111'
: genRandomHexBytes(16)

self.cardDialog.data.k1 = debugcard
this.cardDialog.data.k1 = debugcard
? '22222222222222222222222222222222'
: genRandomHexBytes(16)

self.cardDialog.data.k2 = debugcard
this.cardDialog.data.k2 = debugcard
? '33333333333333333333333333333333'
: genRandomHexBytes(16)
},
closeFormDialog: function () {
closeFormDialog() {
this.cardDialog.data = {}
},
sendFormData: function () {
sendFormData() {
let wallet = _.findWhere(this.g.user.wallets, {
id: this.cardDialog.data.wallet
})
Expand All @@ -326,21 +314,19 @@ window.app = Vue.createApp({
this.createCard(wallet, data)
}
},
createCard: function (wallet, data) {
var self = this

createCard(wallet, data) {
LNbits.api
.request('POST', '/boltcards/api/v1/cards', wallet.adminkey, data)
.then(function (response) {
self.cards.push(mapCards(response.data))
self.cardDialog.show = false
self.cardDialog.data = {}
.then(response => {
this.cards.push(mapCards(response.data))
this.cardDialog.show = false
this.cardDialog.data = {}
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
},
updateCardDialog: function (formId) {
updateCardDialog(formId) {
var card = _.findWhere(this.cards, {id: formId})
this.cardDialog.data = _.clone(card)

Expand All @@ -350,9 +336,7 @@ window.app = Vue.createApp({

this.cardDialog.show = true
},
updateCard: function (wallet, data) {
var self = this

updateCard(wallet, data) {
if (
this.cardDialog.temp.k0 != data.k0 ||
this.cardDialog.temp.k1 != data.k1 ||
Expand All @@ -370,21 +354,20 @@ window.app = Vue.createApp({
wallet.adminkey,
data
)
.then(function (response) {
self.cards = _.reject(self.cards, function (obj) {
.then(response => {
this.cards = _.reject(this.cards, function (obj) {
return obj.id == data.id
})
self.cards.push(mapCards(response.data))
self.cardDialog.show = false
self.cardDialog.data = {}
this.cards.push(mapCards(response.data))
this.cardDialog.show = false
this.cardDialog.data = {}
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
},
enableCard: function (wallet, card_id, enable) {
var self = this
let fullWallet = _.findWhere(self.g.user.wallets, {
enableCard(wallet, card_id, enable) {
let fullWallet = _.findWhere(this.g.user.wallets, {
id: wallet
})
LNbits.api
Expand All @@ -393,19 +376,18 @@ window.app = Vue.createApp({
'/boltcards/api/v1/cards/enable/' + card_id + '/' + enable,
fullWallet.adminkey
)
.then(function (response) {
.then(response => {
console.log(response.data)
self.cards = _.reject(self.cards, function (obj) {
this.cards = _.reject(this.cards, function (obj) {
return obj.id == response.data.id
})
self.cards.push(mapCards(response.data))
this.cards.push(mapCards(response.data))
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
},
deleteCard: function (cardId) {
let self = this
deleteCard(cardId) {
let cards = _.findWhere(this.cards, {id: cardId})

Quasar.utils.exportFile(
Expand All @@ -418,15 +400,15 @@ window.app = Vue.createApp({
.confirmDialog(
"Are you sure you want to delete this card? Without access to the card keys you won't be able to reset them in the future!"
)
.onOk(function () {
.onOk(() => {
LNbits.api
.request(
'DELETE',
'/boltcards/api/v1/cards/' + cardId,
_.findWhere(self.g.user.wallets, {id: cards.wallet}).adminkey
_.findWhere(this.g.user.wallets, {id: cards.wallet}).adminkey
)
.then(function (response) {
self.cards = _.reject(self.cards, function (obj) {
.then(response => {
this.cards = _.reject(this.cards, function (obj) {
return obj.id == cardId
})
})
Expand All @@ -435,17 +417,17 @@ window.app = Vue.createApp({
})
})
},
exportCardsCSV: function () {
exportCardsCSV() {
LNbits.utils.exportCSV(this.cardsTable.columns, this.cards)
},
exportHitsCSV: function () {
exportHitsCSV() {
LNbits.utils.exportCSV(this.hitsTable.columns, this.hits)
},
exportRefundsCSV: function () {
exportRefundsCSV() {
LNbits.utils.exportCSV(this.refundsTable.columns, this.refunds)
}
},
created: function () {
created() {
if (this.g.user.wallets.length) {
this.getCards()
this.getRefunds()
Expand Down
4 changes: 2 additions & 2 deletions templates/boltcards/display.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@
},
methods: {
copyText(text, message, position) {
Quasar.utils.copyToClipboard(text).then(() => {
this.$q.notify({
Quasar.copyToClipboard(text).then(() => {
Quasar.Notify.create({
message: message || 'Copied to clipboard!',
position: position || 'bottom'
})
Expand Down
Loading

0 comments on commit fb8517a

Please sign in to comment.