From 5a3e1d7fbbcc035e5b9bda142ab9508e4d923b66 Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Fri, 8 Jul 2022 15:47:48 +0300 Subject: [PATCH] feat: add expanding details to rows --- lnbits/extensions/satspay/static/js/utils.js | 9 +- .../satspay/templates/satspay/index.html | 218 ++++++++++++++---- 2 files changed, 179 insertions(+), 48 deletions(-) diff --git a/lnbits/extensions/satspay/static/js/utils.js b/lnbits/extensions/satspay/static/js/utils.js index a2aaa0f0d..535615af5 100644 --- a/lnbits/extensions/satspay/static/js/utils.js +++ b/lnbits/extensions/satspay/static/js/utils.js @@ -13,19 +13,22 @@ const retryWithDelay = async function (fn, retryCount = 0) { } } -const mapCharge = obj => { +const mapCharge = (obj, oldObj = {}) => { obj._data = _.clone(obj) obj.theTime = obj.time * 60 - (Date.now() / 1000 - obj.timestamp) - obj.time = obj.time + 'mins' + obj.time = obj.time + ' min' if (obj.time_elapsed) { - obj.date = 'Time elapsed' + obj.date = '' } else { obj.date = Quasar.utils.date.formatDate( new Date((obj.theTime - 3600) * 1000), 'HH:mm:ss' ) } + obj.expanded = false obj.displayUrl = ['/satspay/', obj.id].join('') + obj.expanded = oldObj.expanded + obj.pendingBalance = oldObj.pendingBalance || 0 return obj } diff --git a/lnbits/extensions/satspay/templates/satspay/index.html b/lnbits/extensions/satspay/templates/satspay/index.html index 464b5107b..7c0f36ce4 100644 --- a/lnbits/extensions/satspay/templates/satspay/index.html +++ b/lnbits/extensions/satspay/templates/satspay/index.html @@ -58,17 +58,14 @@ @@ -77,53 +74,162 @@ - Payment link - + @click="props.row.expanded= !props.row.expanded" + :icon="props.row.expanded? 'remove' : 'add'" + /> + - - Delete charge - - expired + expired - paid + paid - waiting + waiting + - -
-
{{ col.value }}
+ + {{props.row.description}} + + +
{{props.row.date}}
+
+ +
{{props.row.time}}
+
+ +
{{props.row.amount}}
+
+ +
{{props.row.balance}}
+
+ +
+ {{props.row.pendingBalance ? props.row.pendingBalance : ''}} +
+
+ + {{props.row.onchainaddress}} + +
+ + +
+
Onchain Wallet:
+
+ {{getOnchainWalletName(props.row.onchainwallet)}} +
+
+
+
LNbits Wallet:
+
+ {{getLNbitsWalletName(props.row.lnbitswallet)}} +
+
+ + + +
+
ID:
+
{{props.row.id}}
+
+
+
+
+ Details
+
+ Delete +
+
+
+
@@ -330,6 +436,12 @@ label: 'Balance', field: 'balance' }, + { + name: 'pendingBalance', + align: 'left', + label: 'Pending Balance', + field: 'pendingBalance' + }, { name: 'onchain address', align: 'left', @@ -394,7 +506,7 @@ ) this.walletLinks = data.map(w => ({ id: w.id, - label: w.title + label: w.title + ' - ' + w.id })) } catch (error) { LNbits.utils.notifyApiError(error) @@ -413,6 +525,16 @@ LNbits.utils.notifyApiError(error) } }, + getOnchainWalletName: function (walletId) { + const wallet = this.walletLinks.find(w => w.id === walletId) + if (!wallet) return 'unknown' + return wallet.label + }, + getLNbitsWalletName: function (walletId) { + const wallet = this.g.user.walletOptions.find(w => w.value === walletId) + if (!wallet) return 'unknown' + return wallet.label + }, getCharges: async function () { try { @@ -421,7 +543,13 @@ '/satspay/api/v1/charges', this.g.user.wallets[0].inkey ) - this.chargeLinks = data.map(mapCharge) + this.chargeLinks = data.map(c => + mapCharge( + c, + this.chargeLinks.find(old => old.id === c.id) + ) + ) + console.log('### this.chargeLinks', this.chargeLinks) } catch (error) { LNbits.utils.notifyApiError(error) } @@ -466,7 +594,7 @@ }) const utxos = await retryWithDelay(fn) - charge.balance = utxos.reduce((t, u) => t + u.value, 0) + charge.pendingBalance = utxos.reduce((t, u) => t + u.value, 0) } } catch (error) { console.error(error)