diff --git a/lnbits/extensions/cashu/templates/cashu/wallet.html b/lnbits/extensions/cashu/templates/cashu/wallet.html index 3939d1648..59adf5d95 100644 --- a/lnbits/extensions/cashu/templates/cashu/wallet.html +++ b/lnbits/extensions/cashu/templates/cashu/wallet.html @@ -3,7 +3,7 @@ endraw %} {% endblock %} {% block footer %}{% endblock %} {% block page_container %} -
+
@@ -18,11 +18,18 @@ page_container %}
-
+
- - All mints: {% raw %}{{ getTotalBalance }} {{tickerShort}} {% - endraw %} + Balance on all mints: {% raw %} + {{ getTotalBalance }} {{tickerShort}} {% endraw %} +
+
+ @@ -35,7 +42,7 @@ page_container %}
- Cashu mints + Mints You can use use multiple Cashu mints in this wallet. - Add the mint URL and select the mint you want to + >You can connect your wallet to multiple Cashu mints. + Enter a mint URL and select the mint your want to use. @@ -213,14 +220,15 @@ page_container %} > Pending - - Check - + Check status +
{{props.row.hash}}
+ +
{{props.row.mint}}
+
{% endraw %} @@ -288,14 +299,15 @@ page_container %} > Pending
- - Check - + Check status +
+ >Warning
+
-
+ +
{{ payInvoiceData.invoice.fsat }}{% endraw %} - {{LNBITS_DENOMINATION}} {% raw %} + {{LNBITS_DENOMINATION}} {% raw %} asdasdsd

@@ -649,6 +664,66 @@ page_container %} + + + + + + + Cashu + wallet + + +

Please take a moment to read the following information.

+ +

+ Open this wallet on your device's native browser + Cashu stores your ecash on your device locally. For the best + experience, use this wallet with your device's native web browser + (for example Safari for iOS, Chrome for Android). +

+

+ Add to home screen. + Add Cashu to your home screen as a progressive web app (PWA). On + Android Chrome, click the hamburger menu at the upper right. On + iOS Safari, click the share button. Now press the Add to Home + screen button. +

+

+ This software is in BETA! We hold no + responsibility for people losing access to funds. Use at your own + risk! Ecash is a bearer asset, meaning losing access to this + wallet will mean you will lose the funds. This wallet stores ecash + tokens in its database. If you lose the link or delete your your + data without backing up, you will lose your tokens. Press the + Backup button to download a copy of your tokens. +

+
+ Copy wallet URL + Continue +
+ + + +
Warning
@@ -668,7 +743,7 @@ page_container %} Home screen button.

- This service is in BETA! We hold no responsibility + This software is in BETA! We hold no responsibility for people losing access to funds. Use at your own risk!

@@ -706,12 +781,12 @@ page_container %} class="q-mb-lg" @keyup.enter="requestMintButton" > - + > -->
-
+
@@ -818,7 +893,8 @@ page_container %} > Copy link
@@ -851,12 +927,6 @@ page_container %}
Receive - - - - +
m.url != url) localStorage.setItem('cashu.mints', JSON.stringify(this.mints)) + // todo: we always reset to the first mint, improve this this.activateMint(this.mints[0].url) this.notifySuccess('Mint removed.') }, @@ -1244,7 +1327,26 @@ page_container %} } return balance }, - activateMint: async function (url, verbose = false) { + getActiveMintUrlShort: function () { + url = this.activeMintURL.replace('https://', '') + + const cut_param = 40 + if (url.length > cut_param && url.indexOf('/') != -1) { + url = + url.substring(0, url.indexOf('/') + 1) + + '...' + + url.substring(url.length - cut_param / 2, url.length) + } + return url + }, + activateMint: async function (url, verbose = false, stop_workers = true) { + if (url == this.activeMintURL) { + return + } + if (stop_workers) { + // we need to stop workers because they will reset the activeMint again + this.clearAllWorkers() + } let presiouvURL = this.activeMintURL try { this.activeMintURL = url @@ -1253,13 +1355,13 @@ page_container %} this.activeProofs = this.proofs.filter(p => this.keysets.includes(p.id) ) - if (verbose) { this.notifySuccess('Mint added.') } + console.log('### activateMint: Mint activated: ', this.activeMintURL) } catch (error) { this.activeMintURL = presiouvURL - this.notifyError('Could not add mint.') + this.notifyError('Could not connect to mint.') throw error } }, @@ -1324,6 +1426,18 @@ page_container %} this.camera.show = false this.focusInput('pasteInput') }, + showWelcomeDialog: function () { + if (localStorage.getItem('cashu.welcomeDialogSeen') != 'seen') { + this.welcomeDialog.show = true + } + }, + setWelcomeDialogSeen: function () { + localStorage.setItem('cashu.welcomeDialogSeen', 'seen') + // kick of notification that no mints are present + // we have to do this because we disabled this notification since it + // covers the dialog + this.showNoMintsWarning() + }, showDisclaimerDialog: function () { this.disclaimerDialog.show = true }, @@ -1391,9 +1505,9 @@ page_container %} // } else if (req.indexOf('cashu:') !== 1) { // this.receiveData.tokensBase64 = req.slice(req.indexOf('cashu:')) // reqtype = 'cashu' - } else if (req.indexOf('W3siaWQ') !== 1) { + } else if (req.indexOf('eyJwcm') !== 1) { // very dirty way of parsing cashu tokens - this.receiveData.tokensBase64 = req.slice(req.indexOf('W3siaWQ')) + this.receiveData.tokensBase64 = req.slice(req.indexOf('eyJwcm')) reqtype = 'cashu' } @@ -1532,11 +1646,10 @@ page_container %} this.invoiceCheckWorker() }, - showTokenDialog: function (token) { + showTokenDialog: function (tokensBase64) { console.log('##### showTokenDialog') - // TODO: this must be decoded and desiarlized! - this.sendData.tokens = _.clone(token) - this.sendData.tokensBase64 = _.clone(token) + this.sendData.tokens = JSON.parse(atob(tokensBase64)).proofs + this.sendData.tokensBase64 = _.clone(tokensBase64) this.showSendTokens = true // kick off token check worker this.checkTokenSpendableWorker() @@ -1672,7 +1785,8 @@ page_container %} this.invoicesCashu.push({ ..._.clone(this.invoiceData), date: currentDateStr(), - status: 'pending' + status: 'pending', + mint: this.activeMintURL }) this.storeinvoicesCashu() this.tab = 'invoices' @@ -2030,7 +2144,8 @@ page_container %} hash: this.payInvoiceData.data.hash, memo: this.payInvoiceData.data.memo, date: currentDateStr(), - status: 'paid' + status: 'paid', + mint: this.activeMintURL }) this.storeinvoicesCashu() this.tab = 'invoices' @@ -2170,10 +2285,13 @@ page_container %} console.log('### checkInvoice.hash', payment_hash) const invoice = this.invoicesCashu.find(i => i.hash === payment_hash) try { + if (invoice.mint != null) { + this.activateMint(invoice.mint, false, false) + } proofs = await this.mint(invoice.amount, invoice.hash, verbose) return proofs } catch (error) { - console.log('Invoice still pending') + console.log('Invoice still pending', invoice.hash) throw error } }, @@ -2208,8 +2326,14 @@ page_container %} checks whether a base64-encoded token (from the history table) has been spent already. if it is spent, the appropraite entry in the history table is set to paid. */ - const tokenJson = atob(token) - const proofs = JSON.parse(tokenJson).proofs + const tokenJson = JSON.parse(atob(token)) + const proofs = tokenJson.proofs + + if (tokenJson.mints != null && tokenJson.mints[0].url != null) { + // todo: we activate only the first mint in the token + this.activateMint(tokenJson.mints[0].url) + } + const spendable = await this.checkProofsSpendable(proofs) let paid = false if (spendable.includes(false)) { @@ -2224,7 +2348,7 @@ page_container %} if (verbose) { this.notify('Token still pending', (color = 'grey')) } - this.sendData.tokens = token + // this.sendData.tokens = token } return paid }, @@ -2328,12 +2452,30 @@ page_container %} throw new Error(`Mint error: ${response.error}`) } }, + showNoMintsWarning: function () { + if (!this.activeMintURL) { + this.walletURL = this.baseURL + // we have to check whether the welcome dialog was pressed away because + // otherwise quasar falsely covers the welcome dialog with this notify + if (localStorage.getItem('cashu.welcomeDialogSeen') == 'seen') { + this.notifyWarning( + 'You are not connected to any mints yet.', + 'Add a new mint URL in the settings.', + 30000 + ) + } + + this.tab = 'settings' + } + }, + notifySuccess: async function (message, position = 'top') { this.$q.notify({ timeout: 5000, type: 'positive', message: message, position: position, + progress: true, actions: [ { icon: 'close', @@ -2349,6 +2491,7 @@ page_container %} message: message, caption: caption, position: 'top', + progress: true, actions: [ { icon: 'close', @@ -2365,10 +2508,11 @@ page_container %} message: message, caption: caption, position: 'top', + progress: true, actions: [ { icon: 'close', - color: 'white', + color: 'black', handler: () => {} } ] @@ -2515,15 +2659,7 @@ page_container %} activeMintURL = localStorage.getItem('cashu.activeMintURL') this.addMint(activeMintURL) } - if (!this.activeMintURL) { - this.walletURL = this.baseURL - this.notifyWarning( - 'You are not connected to any mints yet.', - 'Add a new mint URL in the settings.', - 20000 - ) - this.tab = 'settings' - } + this.showNoMintsWarning() // todo: remove: if (!this.mintId.length) { @@ -2533,6 +2669,8 @@ page_container %} console.log('Mint URL ' + this.activeMintURL) console.log('Wallet URL ' + this.walletURL) + const startupMintUrl = this.activeMintURL + // get name if (params.get('mint_name')) { this.mintName = params.get('mint_name') @@ -2608,6 +2746,13 @@ page_container %} this.checkPendingTokens().catch(err => { return }) + + // reset to the mint from settings after workers have run + if (startupMintUrl != null) { + this.activateMint(startupMintUrl) + } + + this.showWelcomeDialog() } })