FIX: issues and improvements to frontend, add lnurlp/lnurladdress, remove split by tag feature (#4)
* deinitialize task * rework of frontend * add lnurl and lightningaddresses * substract fee_reserve from external split, for potential routing fee, add a warning to ui
This commit is contained in:
parent
a96897d4a2
commit
5bb234b797
12 changed files with 269 additions and 344 deletions
|
|
@ -24,11 +24,7 @@ new Vue({
|
|||
return {
|
||||
selectedWallet: null,
|
||||
currentHash: '', // a string that must match if the edit data is unchanged
|
||||
targets: [
|
||||
{
|
||||
method: 'split'
|
||||
}
|
||||
]
|
||||
targets: []
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
|
|
@ -37,14 +33,6 @@ new Vue({
|
|||
}
|
||||
},
|
||||
methods: {
|
||||
clearTargets() {
|
||||
this.targets = [{}]
|
||||
this.$q.notify({
|
||||
message:
|
||||
'Cleared the form, but not saved. You must click to save manually.',
|
||||
timeout: 500
|
||||
})
|
||||
},
|
||||
clearTarget(index) {
|
||||
this.targets.splice(index, 1)
|
||||
console.log(this.targets)
|
||||
|
|
@ -60,106 +48,21 @@ new Vue({
|
|||
'/splitpayments/api/v1/targets',
|
||||
this.selectedWallet.adminkey
|
||||
)
|
||||
.then(response => {
|
||||
this.targets = response.data
|
||||
})
|
||||
.catch(err => {
|
||||
LNbits.utils.notifyApiError(err)
|
||||
})
|
||||
.then(response => {
|
||||
this.currentHash = hashTargets(response.data)
|
||||
this.targets = response.data.concat({})
|
||||
for (let i = 0; i < this.targets.length; i++) {
|
||||
if (this.targets[i].tag.length > 0) {
|
||||
this.targets[i].method = 'tag'
|
||||
} else if (this.targets[i].percent.length > 0) {
|
||||
this.targets[i].method = 'split'
|
||||
} else {
|
||||
this.targets[i].method = ''
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
changedWallet(wallet) {
|
||||
this.selectedWallet = wallet
|
||||
this.getTargets()
|
||||
},
|
||||
clearChanged(index) {
|
||||
if (this.targets[index].method == 'split') {
|
||||
this.targets[index].tag = null
|
||||
this.targets[index].method = 'split'
|
||||
} else {
|
||||
this.targets[index].percent = null
|
||||
this.targets[index].method = 'tag'
|
||||
}
|
||||
},
|
||||
targetChanged(index) {
|
||||
// fix percent min and max range
|
||||
if (this.targets[index].percent) {
|
||||
if (this.targets[index].percent > 100) this.targets[index].percent = 100
|
||||
if (this.targets[index].percent < 0) this.targets[index].percent = 0
|
||||
this.targets[index].tag = ''
|
||||
}
|
||||
|
||||
// not percentage
|
||||
if (!this.targets[index].percent) {
|
||||
this.targets[index].percent = 0
|
||||
}
|
||||
|
||||
// remove empty lines (except last)
|
||||
if (this.targets.length >= 2) {
|
||||
for (let i = this.targets.length - 2; i >= 0; i--) {
|
||||
let target = this.targets[i]
|
||||
if (
|
||||
(!target.wallet || target.wallet.trim() === '') &&
|
||||
(!target.alias || target.alias.trim() === '') &&
|
||||
(!target.tag || target.tag.trim() === '') &&
|
||||
!target.percent
|
||||
) {
|
||||
this.targets.splice(i, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add a line at the end if the last one is filled
|
||||
let last = this.targets[this.targets.length - 1]
|
||||
if (last.wallet && last.wallet.trim() !== '') {
|
||||
this.targets.push({})
|
||||
}
|
||||
|
||||
// sum of all percents
|
||||
let currentTotal = this.targets.reduce(
|
||||
(acc, target) => acc + (target.percent || 0),
|
||||
0
|
||||
)
|
||||
|
||||
// remove last (unfilled) line if the percent is already 100
|
||||
if (currentTotal >= 100) {
|
||||
let last = this.targets[this.targets.length - 1]
|
||||
if (
|
||||
(!last.wallet || last.wallet.trim() === '') &&
|
||||
(!last.alias || last.alias.trim() === '') &&
|
||||
!last.percent
|
||||
) {
|
||||
this.targets = this.targets.slice(0, -1)
|
||||
}
|
||||
}
|
||||
|
||||
// adjust percents of other lines (not this one)
|
||||
if (currentTotal > 100 && isPercent) {
|
||||
let diff = (currentTotal - 100) / (100 - this.targets[index].percent)
|
||||
this.targets.forEach((target, t) => {
|
||||
if (t !== index) target.percent -= +(diff * target.percent).toFixed(2)
|
||||
})
|
||||
}
|
||||
// overwrite so changes appear
|
||||
this.targets = this.targets
|
||||
addTarget() {
|
||||
this.targets.push({source: this.selectedWallet})
|
||||
},
|
||||
saveTargets() {
|
||||
for (let i = 0; i < this.targets.length; i++) {
|
||||
if (this.targets[i].tag != '') {
|
||||
this.targets[i].percent = 0
|
||||
} else {
|
||||
this.targets[i].tag = ''
|
||||
}
|
||||
}
|
||||
LNbits.api
|
||||
.request(
|
||||
'PUT',
|
||||
|
|
@ -167,13 +70,6 @@ new Vue({
|
|||
this.selectedWallet.adminkey,
|
||||
{
|
||||
targets: this.targets
|
||||
.filter(isTargetComplete)
|
||||
.map(({wallet, percent, tag, alias}) => ({
|
||||
wallet,
|
||||
percent,
|
||||
tag,
|
||||
alias
|
||||
}))
|
||||
}
|
||||
)
|
||||
.then(response => {
|
||||
|
|
@ -181,11 +77,32 @@ new Vue({
|
|||
message: 'Split payments targets set.',
|
||||
timeout: 700
|
||||
})
|
||||
this.getTargets()
|
||||
})
|
||||
.catch(err => {
|
||||
LNbits.utils.notifyApiError(err)
|
||||
})
|
||||
},
|
||||
deleteTargets() {
|
||||
LNbits.utils
|
||||
.confirmDialog('Are you sure you want to delete the targets?')
|
||||
.onOk(() => {
|
||||
this.targets = []
|
||||
LNbits.api
|
||||
.request(
|
||||
'DELETE',
|
||||
'/splitpayments/api/v1/targets',
|
||||
this.selectedWallet.adminkey
|
||||
)
|
||||
.then(response => {
|
||||
this.$q.notify({
|
||||
message: 'Split payments targets deleted.',
|
||||
timeout: 700
|
||||
})
|
||||
})
|
||||
.catch(err => {
|
||||
LNbits.utils.notifyApiError(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
},
|
||||
created() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue