mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-02-23 14:40:47 +01:00
tagged working
This commit is contained in:
parent
c91b5031bf
commit
5f53eb8e4e
4 changed files with 67 additions and 31 deletions
|
@ -16,7 +16,7 @@ class TargetPutList(BaseModel):
|
|||
wallet: str = Query(...)
|
||||
alias: str = Query("")
|
||||
percent: float = Query(..., ge=0, lt=100)
|
||||
tag: str = Query("")
|
||||
tag: str
|
||||
|
||||
|
||||
class TargetPut(BaseModel):
|
||||
|
|
|
@ -39,6 +39,15 @@ new Vue({
|
|||
timeout: 500
|
||||
})
|
||||
},
|
||||
clearTarget(index) {
|
||||
this.targets.splice(index, 1)
|
||||
console.log(this.targets)
|
||||
this.$q.notify({
|
||||
message:
|
||||
'Removed item. You must click to save manually.',
|
||||
timeout: 500
|
||||
})
|
||||
},
|
||||
getTargets() {
|
||||
LNbits.api
|
||||
.request(
|
||||
|
@ -52,8 +61,17 @@ new Vue({
|
|||
.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 !=
|
||||
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 = ""
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
},
|
||||
|
@ -64,17 +82,19 @@ new Vue({
|
|||
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
|
||||
console.log(this.targets)
|
||||
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
|
||||
|
@ -128,15 +148,12 @@ new Vue({
|
|||
if (t !== index) target.percent -= +(diff * target.percent).toFixed(2)
|
||||
})
|
||||
}
|
||||
|
||||
// overwrite so changes appear
|
||||
this.targets = this.targets
|
||||
console.log(this.targets)
|
||||
},
|
||||
saveTargets() {
|
||||
console.log(this.targets)
|
||||
for (let i = 0; i < this.targets.length; i++) {
|
||||
if (this.targets[i].tag){
|
||||
if (this.targets[i].tag != ''){
|
||||
this.targets[i].percent = 0
|
||||
}
|
||||
else{
|
||||
|
|
|
@ -25,7 +25,7 @@ async def on_invoice_paid(payment: Payment) -> None:
|
|||
return
|
||||
|
||||
targets = await get_targets(payment.wallet_id)
|
||||
|
||||
logger.debug(targets)
|
||||
if not targets:
|
||||
return
|
||||
|
||||
|
@ -35,28 +35,46 @@ async def on_invoice_paid(payment: Payment) -> None:
|
|||
logger.error("splitpayment failure: total percent adds up to more than 100%")
|
||||
return
|
||||
|
||||
logger.debug(f"performing split payments to {len(targets)} targets")
|
||||
logger.debug(f"checking if tagged for {len(targets)} targets")
|
||||
tagged = False
|
||||
for target in targets:
|
||||
|
||||
if target.tag and payment.extra.get("tag") == target.tag:
|
||||
amount = int(payment.amount)
|
||||
elif target.percent:
|
||||
if payment.extra.get("tag") == target.tag:
|
||||
tagged = True
|
||||
payment_hash, payment_request = await create_invoice(
|
||||
wallet_id=target.wallet,
|
||||
amount=int(payment.amount / 1000), # sats
|
||||
internal=True,
|
||||
memo=f"Pushed tagged payment to {target.alias}",
|
||||
extra={"tag": "splitpayments"},
|
||||
)
|
||||
logger.debug(f"created split invoice: {payment_hash}")
|
||||
|
||||
checking_id = await pay_invoice(
|
||||
payment_request=payment_request,
|
||||
wallet_id=payment.wallet_id,
|
||||
extra={"tag": "splitpayments"},
|
||||
)
|
||||
logger.debug(f"paid split invoice: {checking_id}")
|
||||
|
||||
logger.debug(f"performing split to {len(targets)} targets")
|
||||
logger.debug("pitbull")
|
||||
if tagged == False:
|
||||
for target in targets:
|
||||
amount = int(payment.amount * target.percent / 100) # msats
|
||||
else:
|
||||
return
|
||||
payment_hash, payment_request = await create_invoice(
|
||||
wallet_id=target.wallet,
|
||||
amount=int(amount / 1000), # sats
|
||||
internal=True,
|
||||
memo=f"split payment: {target.percent}% for {target.alias or target.wallet}",
|
||||
extra={"tag": "splitpayments"},
|
||||
)
|
||||
logger.debug(f"created split invoice: {payment_hash}")
|
||||
|
||||
checking_id = await pay_invoice(
|
||||
payment_request=payment_request,
|
||||
wallet_id=payment.wallet_id,
|
||||
extra={"tag": "splitpayments"},
|
||||
)
|
||||
logger.debug(f"paid split invoice: {checking_id}")
|
||||
|
||||
payment_hash, payment_request = await create_invoice(
|
||||
wallet_id=target.wallet,
|
||||
amount=int(amount / 1000), # sats
|
||||
internal=True,
|
||||
memo=f"split payment: {target.percent}% for {target.alias or target.wallet}",
|
||||
extra={"tag": "splitpayments"},
|
||||
)
|
||||
logger.debug(f"created split invoice: {payment_hash}")
|
||||
|
||||
checking_id = await pay_invoice(
|
||||
payment_request=payment_request,
|
||||
wallet_id=payment.wallet_id,
|
||||
extra={"tag": "splitpayments"},
|
||||
)
|
||||
logger.debug(f"paid split invoice: {checking_id}")
|
||||
|
|
|
@ -67,7 +67,7 @@
|
|||
></q-toggle>
|
||||
|
||||
<q-input
|
||||
v-if="target.method == 'tag' || target.tag != ''"
|
||||
v-if="target.method == 'tag'"
|
||||
style="width: 150px"
|
||||
dense
|
||||
outlined
|
||||
|
@ -97,6 +97,7 @@
|
|||
>
|
||||
<q-tooltip>Add more</q-tooltip>
|
||||
</q-btn>
|
||||
<q-btn v-if="t < targets.length - 1" @click="clearTarget(t)" round color="red" size="5px" icon="close"></q-btn>
|
||||
</div>
|
||||
<div class="row justify-evenly q-pa-lg">
|
||||
<div>
|
||||
|
|
Loading…
Add table
Reference in a new issue