From 5697bd3b31f099270d8783908b8ba01d176a5db2 Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Mon, 1 Aug 2022 13:21:14 +0300 Subject: [PATCH] fix: stop scanning when network changed --- .../components/wallet-list/wallet-list.js | 2 +- .../extensions/watchonly/static/js/index.js | 28 ++++++++++--------- lnbits/extensions/watchonly/static/js/map.js | 21 +++++++------- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/lnbits/extensions/watchonly/static/components/wallet-list/wallet-list.js b/lnbits/extensions/watchonly/static/components/wallet-list/wallet-list.js index 083dbf30..85964f87 100644 --- a/lnbits/extensions/watchonly/static/components/wallet-list/wallet-list.js +++ b/lnbits/extensions/watchonly/static/components/wallet-list/wallet-list.js @@ -50,7 +50,6 @@ async function walletList(path) { watch: { immediate: true, async network(newNet, oldNet) { - console.log('### newNet, oldNet', newNet, oldNet) if (newNet !== oldNet) { await this.refreshWalletAccounts() } @@ -131,6 +130,7 @@ async function walletList(path) { return [] }, refreshWalletAccounts: async function () { + this.walletAccounts = [] const wallets = await this.getWatchOnlyWallets() this.walletAccounts = wallets.map(w => mapWalletAccount(w)) this.$emit('accounts-update', this.walletAccounts) diff --git a/lnbits/extensions/watchonly/static/js/index.js b/lnbits/extensions/watchonly/static/js/index.js index 4b7b87b1..59fec402 100644 --- a/lnbits/extensions/watchonly/static/js/index.js +++ b/lnbits/extensions/watchonly/static/js/index.js @@ -164,7 +164,6 @@ const watchOnly = async () => { //################### PSBT ################### updateSignedPsbt: async function (psbtBase64) { - console.log('### updateSignedPsbt psbtBase64', psbtBase64) this.$refs.paymentRef.updateSignedPsbt(psbtBase64) }, @@ -237,7 +236,6 @@ const watchOnly = async () => { }) this.addresses.push(...uniqueAddresses) } - console.log('### refreshAddresses', this.addresses) this.$emit('update:addresses', this.addresses) }, getAddressesForWallet: async function (walletId) { @@ -324,12 +322,14 @@ const watchOnly = async () => { //################### MEMPOOL API ################### getAddressTxsDelayed: async function (addrData) { + const accounts = this.walletAccounts + const { + bitcoin: {addresses: addressesAPI} + } = mempoolJS({ + hostname: this.mempoolHostname + }) const fn = async () => { - const { - bitcoin: {addresses: addressesAPI} - } = mempoolJS({ - hostname: this.mempoolHostname - }) + if (!accounts.find(w => (w.id === addrData.wallet))) return [] return addressesAPI.getAddressTxs({ address: addrData.address }) @@ -339,13 +339,15 @@ const watchOnly = async () => { }, getAddressTxsUtxoDelayed: async function (address) { - const fn = async () => { - const { - bitcoin: {addresses: addressesAPI} - } = mempoolJS({ - hostname: this.mempoolHostname - }) + const endpoint = this.mempoolHostname + const { + bitcoin: {addresses: addressesAPI} + } = mempoolJS({ + hostname: endpoint + }) + const fn = async () => { + if (endpoint !== this.mempoolHostname) return [] return addressesAPI.getAddressTxsUtxo({ address }) diff --git a/lnbits/extensions/watchonly/static/js/map.js b/lnbits/extensions/watchonly/static/js/map.js index d1bc8038..82214a68 100644 --- a/lnbits/extensions/watchonly/static/js/map.js +++ b/lnbits/extensions/watchonly/static/js/map.js @@ -66,15 +66,14 @@ const mapAddressDataToUtxo = (wallet, addressData, utxo) => ({ selected: false }) -const mapWalletAccount = function (obj) { - obj._data = _.clone(obj) - obj.date = obj.time - ? Quasar.utils.date.formatDate( - new Date(obj.time * 1000), - 'YYYY-MM-DD HH:mm' - ) - : '' - obj.label = obj.title // for drop-downs - obj.expanded = false - return obj +const mapWalletAccount = function (o) { + return Object.assign({}, o, { + date: o.time + ? Quasar.utils.date.formatDate( + new Date(o.time * 1000), + 'YYYY-MM-DD HH:mm' + ) + : '', + expanded: false + }) }