From e6b46301dfbc5f70c9614cb39668a50d054b9dc6 Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Mon, 25 Jul 2022 15:58:18 +0300 Subject: [PATCH] refactor: extract `utxo-list` component --- .../components/address-list/address-list.js | 1 - .../static/components/history/history.js | 2 +- .../components/utxo-list/utxo-list.html | 153 +++++++++++++++ .../static/components/utxo-list/utxo-list.js | 84 +++++++++ .../extensions/watchonly/static/js/index.js | 4 +- .../extensions/watchonly/static/js/tables.js | 52 ----- .../watchonly/templates/watchonly/index.html | 178 ++---------------- 7 files changed, 253 insertions(+), 221 deletions(-) create mode 100644 lnbits/extensions/watchonly/static/components/utxo-list/utxo-list.html create mode 100644 lnbits/extensions/watchonly/static/components/utxo-list/utxo-list.js diff --git a/lnbits/extensions/watchonly/static/components/address-list/address-list.js b/lnbits/extensions/watchonly/static/components/address-list/address-list.js index 010a97b6b..6a77422c6 100644 --- a/lnbits/extensions/watchonly/static/components/address-list/address-list.js +++ b/lnbits/extensions/watchonly/static/components/address-list/address-list.js @@ -74,7 +74,6 @@ async function addressList(path) { } }, - methods: { satBtc(val, showUnit = true) { return satOrBtc(val, showUnit, this['sats_denominated']) diff --git a/lnbits/extensions/watchonly/static/components/history/history.js b/lnbits/extensions/watchonly/static/components/history/history.js index 29bdda300..503169eec 100644 --- a/lnbits/extensions/watchonly/static/components/history/history.js +++ b/lnbits/extensions/watchonly/static/components/history/history.js @@ -4,7 +4,7 @@ async function history(path) { name: 'history', template, - props: ['history', 'mempool_endpoint'], + props: ['history', 'mempool_endpoint', 'sats_denominated'], data: function () { return { historyTable: { diff --git a/lnbits/extensions/watchonly/static/components/utxo-list/utxo-list.html b/lnbits/extensions/watchonly/static/components/utxo-list/utxo-list.html new file mode 100644 index 000000000..97b889e38 --- /dev/null +++ b/lnbits/extensions/watchonly/static/components/utxo-list/utxo-list.html @@ -0,0 +1,153 @@ + + +
+ + +
+
+ + + +
+
+ + + + + +
diff --git a/lnbits/extensions/watchonly/static/components/utxo-list/utxo-list.js b/lnbits/extensions/watchonly/static/components/utxo-list/utxo-list.js new file mode 100644 index 000000000..40f1016a1 --- /dev/null +++ b/lnbits/extensions/watchonly/static/components/utxo-list/utxo-list.js @@ -0,0 +1,84 @@ +async function utxoList(path) { + const template = await loadTemplateAsync(path) + Vue.component('utxo-list', { + name: 'utxo-list', + template, + + props: ['utxos', 'accounts', 'sats_denominated', 'mempool_endpoint'], + + data: function () { + return { + utxosTable: { + columns: [ + { + name: 'expand', + align: 'left', + label: '' + }, + { + name: 'selected', + align: 'left', + label: '' + }, + { + name: 'status', + align: 'center', + label: 'Status', + sortable: true + }, + { + name: 'address', + align: 'left', + label: 'Address', + field: 'address', + sortable: true + }, + { + name: 'amount', + align: 'left', + label: 'Amount', + field: 'amount', + sortable: true + }, + { + name: 'date', + align: 'left', + label: 'Date', + field: 'date', + sortable: true + }, + { + name: 'wallet', + align: 'left', + label: 'Account', + field: 'wallet', + sortable: true + } + ], + pagination: { + rowsPerPage: 10 + }, + filter: '' + } + } + }, + + methods: { + satBtc(val, showUnit = true) { + return satOrBtc(val, showUnit, this['sats_denominated']) + }, + getWalletName: function (walletId) { + const wallet = (this.accounts || []).find(wl => wl.id === walletId) + return wallet ? wallet.title : 'unknown' + }, + getTotalSelectedUtxoAmount: function () { + const total = this.utxos + .filter(u => u.selected) + .reduce((t, a) => t + (a.amount || 0), 0) + return total + } + }, + + created: async function () {} + }) +} diff --git a/lnbits/extensions/watchonly/static/js/index.js b/lnbits/extensions/watchonly/static/js/index.js index 611abbd6c..62442665b 100644 --- a/lnbits/extensions/watchonly/static/js/index.js +++ b/lnbits/extensions/watchonly/static/js/index.js @@ -5,6 +5,7 @@ const watchOnly = async () => { await walletList('static/components/wallet-list/wallet-list.html') await addressList('static/components/address-list/address-list.html') await history('static/components/history/history.html') + await utxoList('static/components/utxo-list/utxo-list.html') Vue.filter('reverse', function (value) { // slice to make a copy of array, then reverse the copy @@ -795,7 +796,7 @@ const watchOnly = async () => { this.utxos.data = [] this.utxos.total = 0 this.history = [] - console.log('### scanAddressWithAmount1', this.addresses) + console.log('### scanAddressWithAmount1', this.addresses) const addresses = this.addresses.filter(a => a.hasActivity) console.log('### scanAddressWithAmount2', addresses) await this.updateUtxosForAddresses(addresses) @@ -872,6 +873,7 @@ const watchOnly = async () => { ) this.updateAmountForAddress(addressData, addressTotal) }, + // todo: move/dedup getTotalSelectedUtxoAmount: function () { const total = this.utxos.data .filter(u => u.selected) diff --git a/lnbits/extensions/watchonly/static/js/tables.js b/lnbits/extensions/watchonly/static/js/tables.js index 2f7315712..01a98cdbb 100644 --- a/lnbits/extensions/watchonly/static/js/tables.js +++ b/lnbits/extensions/watchonly/static/js/tables.js @@ -1,56 +1,4 @@ const tables = { - utxosTable: { - columns: [ - { - name: 'expand', - align: 'left', - label: '' - }, - { - name: 'selected', - align: 'left', - label: '' - }, - { - name: 'status', - align: 'center', - label: 'Status', - sortable: true - }, - { - name: 'address', - align: 'left', - label: 'Address', - field: 'address', - sortable: true - }, - { - name: 'amount', - align: 'left', - label: 'Amount', - field: 'amount', - sortable: true - }, - { - name: 'date', - align: 'left', - label: 'Date', - field: 'date', - sortable: true - }, - { - name: 'wallet', - align: 'left', - label: 'Account', - field: 'wallet', - sortable: true - } - ], - pagination: { - rowsPerPage: 10 - }, - filter: '' - }, paymentTable: { columns: [ { diff --git a/lnbits/extensions/watchonly/templates/watchonly/index.html b/lnbits/extensions/watchonly/templates/watchonly/index.html index 0dca1ae38..a35aeedcf 100644 --- a/lnbits/extensions/watchonly/templates/watchonly/index.html +++ b/lnbits/extensions/watchonly/templates/watchonly/index.html @@ -73,6 +73,7 @@ ref="addressList" :accounts="walletAccounts" :mempool_endpoint="config.data.mempool_endpoint" + :sats-denominated="config.data.sats_denominated" @update:addresses="handleAddressesUpdated" @scan:address="scanAddress" @show-address-details="showAddressDetails" @@ -81,7 +82,11 @@ - +
@@ -204,171 +209,11 @@
- - -
-
- -
-
- -
-
-
-
- - - -
-
- - - - - -
+
+ {% endblock %}