formatted

This commit is contained in:
ben 2022-12-14 00:06:36 +00:00
parent f506b010f6
commit 75e6252d23
6 changed files with 62 additions and 51 deletions

View File

@ -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,
),
)

View File

@ -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")
await db.execute("DROP TABLE splitpayments.splitpayments_old")

View File

@ -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
})
},
@ -61,17 +66,14 @@ 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.length > 0){
this.targets[i].method = "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 = ''
}
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,14 +95,14 @@ 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
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--) {
@ -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 => {

View File

@ -55,9 +55,9 @@ async def on_invoice_paid(payment: Payment) -> None:
extra={"tag": "splitpayments"},
)
logger.debug(f"paid split invoice: {checking_id}")
logger.debug(f"performing split to {len(targets)} targets")
if tagged == False:
for target in targets:
if target.percent > 0:
@ -77,5 +77,3 @@ async def on_invoice_paid(payment: Payment) -> None:
extra={"tag": "splitpayments"},
)
logger.debug(f"paid split invoice: {checking_id}")

View File

@ -31,7 +31,7 @@
style="flex-wrap: nowrap"
v-for="(target, t) in targets"
>
<q-input
<q-input
dense
outlined
v-model="target.alias"
@ -39,7 +39,7 @@
:hint="t === targets.length - 1 ? 'A name to identify this target wallet locally.' : undefined"
style="width: 150px"
></q-input>
<q-input
dense
v-model="target.wallet"
@ -52,18 +52,17 @@
input-debounce="0"
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>

View File

@ -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: