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 . import db
from .models import Target from .models import Target
from loguru import logger
async def get_targets(source_wallet: str) -> List[Target]: 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]): async def set_targets(source_wallet: str, targets: List[Target]):
logger.debug(targets)
async with db.connect() as conn: async with db.connect() as conn:
await conn.execute( await conn.execute(
"DELETE FROM splitpayments.targets WHERE source = ?", (source_wallet,) "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) (source, wallet, percent, tag, alias)
VALUES (?, ?, ?, ?, ?) 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 from lnbits.helpers import urlsafe_short_hash
async def m001_initial(db): async def m001_initial(db):
""" """
Initial split payment table. Initial split payment table.
@@ -92,7 +93,7 @@ async def m003_add_id_and_tag(db):
) )
VALUES (?, ?, ?, ?, ?, ?) 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) { 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({ new Vue({
@@ -20,9 +24,11 @@ new Vue({
return { return {
selectedWallet: null, selectedWallet: null,
currentHash: '', // a string that must match if the edit data is unchanged currentHash: '', // a string that must match if the edit data is unchanged
targets: [{ targets: [
method: "split" {
}] method: 'split'
}
]
} }
}, },
computed: { computed: {
@@ -43,8 +49,7 @@ new Vue({
this.targets.splice(index, 1) this.targets.splice(index, 1)
console.log(this.targets) console.log(this.targets)
this.$q.notify({ this.$q.notify({
message: message: 'Removed item. You must click to save manually.',
'Removed item. You must click to save manually.',
timeout: 500 timeout: 500
}) })
}, },
@@ -61,17 +66,14 @@ new Vue({
.then(response => { .then(response => {
this.currentHash = hashTargets(response.data) this.currentHash = hashTargets(response.data)
this.targets = response.data.concat({}) this.targets = response.data.concat({})
for (let i = 0; i < this.targets.length; i++) { for (let i = 0; i < this.targets.length; i++) {
if(this.targets[i].tag.length > 0){ if (this.targets[i].tag.length > 0) {
this.targets[i].method = "tag" 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() this.getTargets()
}, },
clearChanged(index) { clearChanged(index) {
if(this.targets[index].method == 'split'){ if (this.targets[index].method == 'split') {
this.targets[index].tag = null this.targets[index].tag = null
this.targets[index].method = 'split' this.targets[index].method = 'split'
} } else {
else{
this.targets[index].percent = null this.targets[index].percent = null
this.targets[index].method = 'tag' this.targets[index].method = 'tag'
} }
@@ -94,14 +95,14 @@ new Vue({
if (this.targets[index].percent) { if (this.targets[index].percent) {
if (this.targets[index].percent > 100) this.targets[index].percent = 100 if (this.targets[index].percent > 100) this.targets[index].percent = 100
if (this.targets[index].percent < 0) this.targets[index].percent = 0 if (this.targets[index].percent < 0) this.targets[index].percent = 0
this.targets[index].tag = "" this.targets[index].tag = ''
} }
// not percentage // not percentage
if (!this.targets[index].percent) { if (!this.targets[index].percent) {
this.targets[index].percent = 0 this.targets[index].percent = 0
} }
// remove empty lines (except last) // remove empty lines (except last)
if (this.targets.length >= 2) { if (this.targets.length >= 2) {
for (let i = this.targets.length - 2; i >= 0; i--) { for (let i = this.targets.length - 2; i >= 0; i--) {
@@ -153,10 +154,9 @@ new Vue({
}, },
saveTargets() { saveTargets() {
for (let i = 0; i < this.targets.length; i++) { for (let i = 0; i < this.targets.length; i++) {
if (this.targets[i].tag != ''){ if (this.targets[i].tag != '') {
this.targets[i].percent = 0 this.targets[i].percent = 0
} } else {
else{
this.targets[i].tag = '' this.targets[i].tag = ''
} }
} }
@@ -168,7 +168,12 @@ new Vue({
{ {
targets: this.targets targets: this.targets
.filter(isTargetComplete) .filter(isTargetComplete)
.map(({wallet, percent, tag, alias}) => ({wallet, percent, tag, alias})) .map(({wallet, percent, tag, alias}) => ({
wallet,
percent,
tag,
alias
}))
} }
) )
.then(response => { .then(response => {

View File

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

View File

@@ -31,7 +31,7 @@
style="flex-wrap: nowrap" style="flex-wrap: nowrap"
v-for="(target, t) in targets" v-for="(target, t) in targets"
> >
<q-input <q-input
dense dense
outlined outlined
v-model="target.alias" v-model="target.alias"
@@ -39,7 +39,7 @@
:hint="t === targets.length - 1 ? 'A name to identify this target wallet locally.' : undefined" :hint="t === targets.length - 1 ? 'A name to identify this target wallet locally.' : undefined"
style="width: 150px" style="width: 150px"
></q-input> ></q-input>
<q-input <q-input
dense dense
v-model="target.wallet" v-model="target.wallet"
@@ -52,18 +52,17 @@
input-debounce="0" input-debounce="0"
emit-value emit-value
></q-input> ></q-input>
<q-toggle <q-toggle
:false-value="'split'" :false-value="'split'"
:true-value="'tag'" :true-value="'tag'"
color="primary" color="primary"
label="" label=""
value="True" value="True"
style="width: 180px" style="width: 180px"
v-model="target.method" v-model="target.method"
:label="`${target.method}` === 'tag' ? 'Send funds by tag' : `${target.method}` === 'split' ? 'Split funds by %' : 'Split/tag?'" :label="`${target.method}` === 'tag' ? 'Send funds by tag' : `${target.method}` === 'split' ? 'Split funds by %' : 'Split/tag?'"
@input="clearChanged(t)" @input="clearChanged(t)"
></q-toggle> ></q-toggle>
<q-input <q-input
@@ -97,7 +96,14 @@
> >
<q-tooltip>Add more</q-tooltip> <q-tooltip>Add more</q-tooltip>
</q-btn> </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>
<div class="row justify-evenly q-pa-lg"> <div class="row justify-evenly q-pa-lg">
<div> <div>

View File

@@ -11,8 +11,6 @@ from . import splitpayments_ext
from .crud import get_targets, set_targets from .crud import get_targets, set_targets
from .models import Target, TargetPut from .models import Target, TargetPut
from loguru import logger
@splitpayments_ext.get("/api/v1/targets") @splitpayments_ext.get("/api/v1/targets")
async def api_targets_get(wallet: WalletTypeInfo = Depends(require_admin_key)): async def api_targets_get(wallet: WalletTypeInfo = Depends(require_admin_key)):
@@ -27,7 +25,6 @@ async def api_targets_set(
body = await req.json() body = await req.json()
targets = [] targets = []
data = TargetPut.parse_obj(body["targets"]) data = TargetPut.parse_obj(body["targets"])
logger.debug(data)
for entry in data.__root__: for entry in data.__root__:
wallet = await get_wallet(entry.wallet) wallet = await get_wallet(entry.wallet)
if not wallet: if not wallet: