formatted
This commit is contained in:
parent
f506b010f6
commit
75e6252d23
|
@ -2,7 +2,6 @@ from typing import List
|
|||
|
||||
from . import db
|
||||
from .models import Target
|
||||
from loguru import logger
|
||||
|
||||
|
||||
async def get_targets(source_wallet: str) -> List[Target]:
|
||||
|
@ -13,7 +12,6 @@ async def get_targets(source_wallet: str) -> List[Target]:
|
|||
|
||||
|
||||
async def set_targets(source_wallet: str, targets: List[Target]):
|
||||
logger.debug(targets)
|
||||
async with db.connect() as conn:
|
||||
await conn.execute(
|
||||
"DELETE FROM splitpayments.targets WHERE source = ?", (source_wallet,)
|
||||
|
@ -25,5 +23,11 @@ async def set_targets(source_wallet: str, targets: List[Target]):
|
|||
(source, wallet, percent, tag, alias)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
""",
|
||||
(source_wallet, target.wallet, target.percent, target.tag, target.alias),
|
||||
(
|
||||
source_wallet,
|
||||
target.wallet,
|
||||
target.percent,
|
||||
target.tag,
|
||||
target.alias,
|
||||
),
|
||||
)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from lnbits.helpers import urlsafe_short_hash
|
||||
|
||||
|
||||
async def m001_initial(db):
|
||||
"""
|
||||
Initial split payment table.
|
||||
|
@ -92,7 +93,7 @@ async def m003_add_id_and_tag(db):
|
|||
)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
(urlsafe_short_hash(), row[0], row[1], row[2], '', row[3]),
|
||||
(urlsafe_short_hash(), row[0], row[1], row[2], "", row[3]),
|
||||
)
|
||||
|
||||
await db.execute("DROP TABLE splitpayments.splitpayments_old")
|
|
@ -10,7 +10,11 @@ function hashTargets(targets) {
|
|||
}
|
||||
|
||||
function isTargetComplete(target) {
|
||||
return target.wallet && target.wallet.trim() !== '' && (target.percent > 0 || target.tag != '')
|
||||
return (
|
||||
target.wallet &&
|
||||
target.wallet.trim() !== '' &&
|
||||
(target.percent > 0 || target.tag != '')
|
||||
)
|
||||
}
|
||||
|
||||
new Vue({
|
||||
|
@ -20,9 +24,11 @@ new Vue({
|
|||
return {
|
||||
selectedWallet: null,
|
||||
currentHash: '', // a string that must match if the edit data is unchanged
|
||||
targets: [{
|
||||
method: "split"
|
||||
}]
|
||||
targets: [
|
||||
{
|
||||
method: 'split'
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
|
@ -43,8 +49,7 @@ new Vue({
|
|||
this.targets.splice(index, 1)
|
||||
console.log(this.targets)
|
||||
this.$q.notify({
|
||||
message:
|
||||
'Removed item. You must click to save manually.',
|
||||
message: 'Removed item. You must click to save manually.',
|
||||
timeout: 500
|
||||
})
|
||||
},
|
||||
|
@ -62,16 +67,13 @@ new Vue({
|
|||
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"
|
||||
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 = ''
|
||||
}
|
||||
else if (this.targets[i].percent.length > 0){
|
||||
this.targets[i].method = "split"
|
||||
}
|
||||
else{
|
||||
this.targets[i].method = ""
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
},
|
||||
|
@ -80,11 +82,10 @@ new Vue({
|
|||
this.getTargets()
|
||||
},
|
||||
clearChanged(index) {
|
||||
if(this.targets[index].method == 'split'){
|
||||
if (this.targets[index].method == 'split') {
|
||||
this.targets[index].tag = null
|
||||
this.targets[index].method = 'split'
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
this.targets[index].percent = null
|
||||
this.targets[index].method = 'tag'
|
||||
}
|
||||
|
@ -94,7 +95,7 @@ new Vue({
|
|||
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 = ""
|
||||
this.targets[index].tag = ''
|
||||
}
|
||||
|
||||
// not percentage
|
||||
|
@ -153,10 +154,9 @@ new Vue({
|
|||
},
|
||||
saveTargets() {
|
||||
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{
|
||||
} else {
|
||||
this.targets[i].tag = ''
|
||||
}
|
||||
}
|
||||
|
@ -168,7 +168,12 @@ new Vue({
|
|||
{
|
||||
targets: this.targets
|
||||
.filter(isTargetComplete)
|
||||
.map(({wallet, percent, tag, alias}) => ({wallet, percent, tag, alias}))
|
||||
.map(({wallet, percent, tag, alias}) => ({
|
||||
wallet,
|
||||
percent,
|
||||
tag,
|
||||
alias
|
||||
}))
|
||||
}
|
||||
)
|
||||
.then(response => {
|
||||
|
|
|
@ -77,5 +77,3 @@ async def on_invoice_paid(payment: Payment) -> None:
|
|||
extra={"tag": "splitpayments"},
|
||||
)
|
||||
logger.debug(f"paid split invoice: {checking_id}")
|
||||
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
style="flex-wrap: nowrap"
|
||||
v-for="(target, t) in targets"
|
||||
>
|
||||
<q-input
|
||||
<q-input
|
||||
dense
|
||||
outlined
|
||||
v-model="target.alias"
|
||||
|
@ -53,17 +53,16 @@
|
|||
emit-value
|
||||
></q-input>
|
||||
|
||||
|
||||
<q-toggle
|
||||
:false-value="'split'"
|
||||
:true-value="'tag'"
|
||||
color="primary"
|
||||
label=""
|
||||
value="True"
|
||||
style="width: 180px"
|
||||
v-model="target.method"
|
||||
:label="`${target.method}` === 'tag' ? 'Send funds by tag' : `${target.method}` === 'split' ? 'Split funds by %' : 'Split/tag?'"
|
||||
@input="clearChanged(t)"
|
||||
:false-value="'split'"
|
||||
:true-value="'tag'"
|
||||
color="primary"
|
||||
label=""
|
||||
value="True"
|
||||
style="width: 180px"
|
||||
v-model="target.method"
|
||||
:label="`${target.method}` === 'tag' ? 'Send funds by tag' : `${target.method}` === 'split' ? 'Split funds by %' : 'Split/tag?'"
|
||||
@input="clearChanged(t)"
|
||||
></q-toggle>
|
||||
|
||||
<q-input
|
||||
|
@ -97,7 +96,14 @@
|
|||
>
|
||||
<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>
|
||||
<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>
|
||||
|
|
|
@ -11,8 +11,6 @@ from . import splitpayments_ext
|
|||
from .crud import get_targets, set_targets
|
||||
from .models import Target, TargetPut
|
||||
|
||||
from loguru import logger
|
||||
|
||||
|
||||
@splitpayments_ext.get("/api/v1/targets")
|
||||
async def api_targets_get(wallet: WalletTypeInfo = Depends(require_admin_key)):
|
||||
|
@ -27,7 +25,6 @@ async def api_targets_set(
|
|||
body = await req.json()
|
||||
targets = []
|
||||
data = TargetPut.parse_obj(body["targets"])
|
||||
logger.debug(data)
|
||||
for entry in data.__root__:
|
||||
wallet = await get_wallet(entry.wallet)
|
||||
if not wallet:
|
||||
|
|
Loading…
Reference in New Issue
Block a user