fix: refresh change address when wallet is created/deleted

This commit is contained in:
Vlad Stan
2022-07-05 15:18:00 +03:00
parent 23954b501f
commit cf75df366a
2 changed files with 24 additions and 16 deletions

View File

@ -96,12 +96,19 @@ new Vue({
) )
this.walletAccounts.push(mapWalletAccount(response.data)) this.walletAccounts.push(mapWalletAccount(response.data))
this.formDialog.show = false this.formDialog.show = false
await this.refreshWalletAccounts() await this.refreshWalletAccounts()
await this.refreshAddresses()
if (!this.payment.changeWallett) {
this.payment.changeWallet = this.walletAccounts[0]
this.selectChangeAddress(this.payment.changeWallet)
}
} catch (error) { } catch (error) {
LNbits.utils.notifyApiError(error) LNbits.utils.notifyApiError(error)
} }
}, },
deleteWalletAccount: function (linkId) { deleteWalletAccount: function (walletAccountId) {
LNbits.utils LNbits.utils
.confirmDialog( .confirmDialog(
'Are you sure you want to delete this watch only wallet?' 'Are you sure you want to delete this watch only wallet?'
@ -110,15 +117,21 @@ new Vue({
try { try {
await LNbits.api.request( await LNbits.api.request(
'DELETE', 'DELETE',
'/watchonly/api/v1/wallet/' + linkId, '/watchonly/api/v1/wallet/' + walletAccountId,
this.g.user.wallets[0].adminkey this.g.user.wallets[0].adminkey
) )
this.walletAccounts = _.reject(this.walletAccounts, function (obj) { this.walletAccounts = _.reject(this.walletAccounts, function (obj) {
return obj.id === linkId return obj.id === walletAccountId
}) })
await this.refreshWalletAccounts() await this.refreshWalletAccounts()
await this.refreshAddresses() await this.refreshAddresses()
console.log('### 111') if (
this.payment.changeWallet &&
this.payment.changeWallet.id === walletAccountId
) {
this.payment.changeWallet = this.walletAccounts[0]
this.selectChangeAddress(this.payment.changeWallet)
}
await this.scanAddressWithAmount() await this.scanAddressWithAmount()
} catch (error) { } catch (error) {
this.$q.notify({ this.$q.notify({
@ -189,9 +202,7 @@ new Vue({
) )
const lastAcctiveAddress = const lastAcctiveAddress =
uniqueAddresses uniqueAddresses.filter(a => !a.isChange && a.hasActivity).pop() || {}
.filter(a => a.addressIndex === 0 && a.hasActivity)
.pop() || {}
uniqueAddresses.forEach(a => { uniqueAddresses.forEach(a => {
a.expanded = false a.expanded = false
@ -288,14 +299,11 @@ new Vue({
const lastAcctiveAddress = const lastAcctiveAddress =
this.addresses.data this.addresses.data
.filter( .filter(
a => a => a.wallet === addressData.wallet && !a.isChange && a.hasActivity
a.wallet === addressData.wallet &&
a.addressIndex === 0 &&
a.hasActivity
) )
.pop() || {} .pop() || {}
addressData.gapLimitExceeded = addressData.gapLimitExceeded =
addressData.addressIndex === 0 && !addressData.isChange &&
addressData.addressIndex > addressData.addressIndex >
lastAcctiveAddress.addressIndex + lastAcctiveAddress.addressIndex +
this.config.DEFAULT_RECEIVE_GAP_LIMIT this.config.DEFAULT_RECEIVE_GAP_LIMIT
@ -452,7 +460,7 @@ new Vue({
this.payment.showAdvanced = false this.payment.showAdvanced = false
this.payment.changeWallet = this.walletAccounts[0] this.payment.changeWallet = this.walletAccounts[0]
this.selectChangeAccount(this.payment.changeWallet) this.selectChangeAddress(this.payment.changeWallet)
await this.refreshRecommendedFees() await this.refreshRecommendedFees()
this.payment.feeRate = this.payment.recommededFees.halfHourFee this.payment.feeRate = this.payment.recommededFees.halfHourFee
@ -471,10 +479,10 @@ new Vue({
getTotalPaymentAmount: function () { getTotalPaymentAmount: function () {
return this.payment.data.reduce((t, a) => t + (a.amount || 0), 0) return this.payment.data.reduce((t, a) => t + (a.amount || 0), 0)
}, },
selectChangeAccount: function (wallet) { selectChangeAddress: function (wallet = {}) {
this.payment.changeAddress = this.payment.changeAddress =
this.addresses.data.find( this.addresses.data.find(
a => a.wallet === wallet.id && a.addressIndex === 1 && !a.hasActivity a => a.wallet === wallet.id && a.isChange && !a.hasActivity
) || {} ) || {}
}, },
goToPaymentView: async function () { goToPaymentView: async function () {

View File

@ -862,7 +862,7 @@
emit-value emit-value
v-model="payment.changeWallet" v-model="payment.changeWallet"
:options="walletAccounts" :options="walletAccounts"
@input="selectChangeAccount" @input="selectChangeAddress"
:rules="[val => !!val || 'Field is required']" :rules="[val => !!val || 'Field is required']"
label="Wallet Account" label="Wallet Account"
></q-select> ></q-select>