multiple mints

This commit is contained in:
callebtc 2022-11-05 16:54:40 +01:00 committed by dni ⚡
parent 5d6d9ca956
commit 6dc23f9246

View file

@ -1565,6 +1565,15 @@ page_container %}
} }
}, },
fetchMintKeys: async function () {
const {data} = await LNbits.api.request(
'GET',
`/cashu/api/v1/${this.mintId}/keys`
)
this.keys = data
localStorage.setItem(this.mintKey(this.mintId, 'keys'), JSON.stringify(data))
},
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -1625,34 +1634,32 @@ page_container %}
this.$q.notify({ this.$q.notify({
timeout: 5000, timeout: 5000,
type: 'warning', type: 'warning',
message: 'Cannot decode invoice', message: 'Could not decode invoice',
caption: error + '' caption: error + ''
}) })
throw error throw error
} }
}, },
fetchMintKeys: async function () {
const {data} = await LNbits.api.request(
'GET',
`/cashu/api/v1/${this.mintId}/keys`
)
this.keys = data
localStorage.setItem('cashu.keys', JSON.stringify(data))
},
storeinvoicesCashu: function () { storeinvoicesCashu: function () {
localStorage.setItem( localStorage.setItem(
'cashu.invoicesCashu', this.mintKey(this.mintId, 'invoicesCashu'),
JSON.stringify(this.invoicesCashu) JSON.stringify(this.invoicesCashu)
) )
}, },
storeProofs: function () { storeProofs: function () {
localStorage.setItem( localStorage.setItem(
'cashu.proofs', this.mintKey(this.mintId, 'proofs'),
JSON.stringify(this.proofs, bigIntStringify) JSON.stringify(this.proofs, bigIntStringify)
) )
} },
mintKey: function(mintId, key) {
// returns a key for the local storage
// depending on the current mint
return "cashu." + mintId + "." + key
},
}, },
watch: { watch: {
payments: function () { payments: function () {
@ -1663,20 +1670,6 @@ page_container %}
created: function () { created: function () {
let params = new URL(document.location).searchParams let params = new URL(document.location).searchParams
// get ticker
if (
!params.get('tsh') &&
!this.$q.localStorage.getItem('cashu.tickershort')
) {
this.$q.localStorage.set('cashu.tickershort', 'sats')
this.tickershort = 'sats'
} else if (params.get('tsh')) {
this.$q.localStorage.set('cashu.tickershort', params.get('tsh'))
this.tickershort = params.get('tsh')
} else if (this.$q.localStorage.getItem('cashu.tickershort')) {
this.tickershort = this.$q.localStorage.getItem('cashu.tickershort')
}
// get mint // get mint
if (params.get('mint_id')) { if (params.get('mint_id')) {
this.mintId = params.get('mint_id') this.mintId = params.get('mint_id')
@ -1693,12 +1686,26 @@ page_container %}
// get name // get name
if (params.get('mint_name')) { if (params.get('mint_name')) {
this.mintName = params.get('mint_name') this.mintName = params.get('mint_name')
this.$q.localStorage.set('cashu.mintName', params.get('mint_name')) this.$q.localStorage.set(this.mintKey(this.mintId, 'mintName'), this.mintName)
} else if (this.$q.localStorage.getItem('cashu.name')) { } else if (this.$q.localStorage.getItem('cashu.name')) {
this.mintName = this.$q.localStorage.getItem('cashu.name') this.mintName = this.$q.localStorage.getItem('cashu.name')
} }
const keysJson = localStorage.getItem('cashu.keys') // get ticker
if (
!params.get('tsh') &&
!this.$q.localStorage.getItem(this.mintKey(this.mintId, 'tickershort'))
) {
this.$q.localStorage.set(this.mintKey(this.mintId, 'tickershort'), 'sats')
this.tickershort = 'sats'
} else if (params.get('tsh')) {
this.$q.localStorage.set(this.mintKey(this.mintId, 'tickershort'), params.get('tsh'))
this.tickershort = params.get('tsh')
} else if (this.$q.localStorage.getItem(this.mintKey(this.mintId, 'tickershort'))) {
this.tickershort = this.$q.localStorage.getItem(this.mintKey(this.mintId, 'tickershort'))
}
const keysJson = localStorage.getItem(this.mintKey(this.mintId, 'keys'))
if (!keysJson) { if (!keysJson) {
this.fetchMintKeys() this.fetchMintKeys()
} else { } else {
@ -1706,9 +1713,9 @@ page_container %}
} }
this.invoicesCashu = JSON.parse( this.invoicesCashu = JSON.parse(
localStorage.getItem('cashu.invoicesCashu') || '[]' localStorage.getItem(this.mintKey(this.mintId, 'invoicesCashu')) || '[]'
) )
this.proofs = JSON.parse(localStorage.getItem('cashu.proofs') || '[]') this.proofs = JSON.parse(localStorage.getItem(this.mintKey(this.mintId, 'proofs')) || '[]')
console.log('### invoicesCashu', this.invoicesCashu) console.log('### invoicesCashu', this.invoicesCashu)
console.table('### tokens', this.proofs) console.table('### tokens', this.proofs)
console.log('#### this.mintId', this.mintId) console.log('#### this.mintId', this.mintId)