PHASE 2: Fixes balance assertion creation and validation
Improves balance assertion creation by handling Decimal types correctly for database insertion. It also fixes a validation issue in the UI where the expected balance was not correctly validated as a required field and initializes the value to 0.
This commit is contained in:
parent
0257b7807c
commit
c0277dfc98
3 changed files with 36 additions and 42 deletions
26
crud.py
26
crud.py
|
|
@ -796,7 +796,31 @@ async def create_balance_assertion(
|
||||||
created_at=datetime.now(),
|
created_at=datetime.now(),
|
||||||
)
|
)
|
||||||
|
|
||||||
await db.insert("balance_assertions", assertion, convert_decimal=True)
|
# Manually insert with Decimal fields converted to strings
|
||||||
|
await db.execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO balance_assertions (
|
||||||
|
id, date, account_id, expected_balance_sats, expected_balance_fiat,
|
||||||
|
fiat_currency, tolerance_sats, tolerance_fiat, status, created_by, created_at
|
||||||
|
) VALUES (
|
||||||
|
:id, :date, :account_id, :expected_balance_sats, :expected_balance_fiat,
|
||||||
|
:fiat_currency, :tolerance_sats, :tolerance_fiat, :status, :created_by, :created_at
|
||||||
|
)
|
||||||
|
""",
|
||||||
|
{
|
||||||
|
"id": assertion.id,
|
||||||
|
"date": assertion.date,
|
||||||
|
"account_id": assertion.account_id,
|
||||||
|
"expected_balance_sats": assertion.expected_balance_sats,
|
||||||
|
"expected_balance_fiat": str(assertion.expected_balance_fiat) if assertion.expected_balance_fiat else None,
|
||||||
|
"fiat_currency": assertion.fiat_currency,
|
||||||
|
"tolerance_sats": assertion.tolerance_sats,
|
||||||
|
"tolerance_fiat": str(assertion.tolerance_fiat),
|
||||||
|
"status": assertion.status.value,
|
||||||
|
"created_by": assertion.created_by,
|
||||||
|
"created_at": assertion.created_at,
|
||||||
|
},
|
||||||
|
)
|
||||||
return assertion
|
return assertion
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ window.app = Vue.createApp({
|
||||||
assertionDialog: {
|
assertionDialog: {
|
||||||
show: false,
|
show: false,
|
||||||
account_id: '',
|
account_id: '',
|
||||||
expected_balance_sats: null,
|
expected_balance_sats: 0,
|
||||||
expected_balance_fiat: null,
|
expected_balance_fiat: null,
|
||||||
fiat_currency: null,
|
fiat_currency: null,
|
||||||
tolerance_sats: 0,
|
tolerance_sats: 0,
|
||||||
|
|
@ -646,7 +646,7 @@ window.app = Vue.createApp({
|
||||||
this.assertionDialog = {
|
this.assertionDialog = {
|
||||||
show: false,
|
show: false,
|
||||||
account_id: '',
|
account_id: '',
|
||||||
expected_balance_sats: null,
|
expected_balance_sats: 0,
|
||||||
expected_balance_fiat: null,
|
expected_balance_fiat: null,
|
||||||
fiat_currency: null,
|
fiat_currency: null,
|
||||||
tolerance_sats: 0,
|
tolerance_sats: 0,
|
||||||
|
|
@ -677,12 +677,6 @@ window.app = Vue.createApp({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async recheckAssertion(assertionId) {
|
async recheckAssertion(assertionId) {
|
||||||
// Set loading state
|
|
||||||
const assertion = this.balanceAssertions.find(a => a.id === assertionId)
|
|
||||||
if (assertion) {
|
|
||||||
this.$set(assertion, 'rechecking', true)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await LNbits.api.request(
|
await LNbits.api.request(
|
||||||
'POST',
|
'POST',
|
||||||
|
|
@ -699,19 +693,9 @@ window.app = Vue.createApp({
|
||||||
await this.loadBalanceAssertions()
|
await this.loadBalanceAssertions()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
LNbits.utils.notifyApiError(error)
|
LNbits.utils.notifyApiError(error)
|
||||||
} finally {
|
|
||||||
if (assertion) {
|
|
||||||
this.$set(assertion, 'rechecking', false)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async deleteAssertion(assertionId) {
|
async deleteAssertion(assertionId) {
|
||||||
// Set loading state
|
|
||||||
const assertion = this.balanceAssertions.find(a => a.id === assertionId)
|
|
||||||
if (assertion) {
|
|
||||||
this.$set(assertion, 'deleting', true)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await LNbits.api.request(
|
await LNbits.api.request(
|
||||||
'DELETE',
|
'DELETE',
|
||||||
|
|
@ -728,10 +712,6 @@ window.app = Vue.createApp({
|
||||||
await this.loadBalanceAssertions()
|
await this.loadBalanceAssertions()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
LNbits.utils.notifyApiError(error)
|
LNbits.utils.notifyApiError(error)
|
||||||
} finally {
|
|
||||||
if (assertion) {
|
|
||||||
this.$set(assertion, 'deleting', false)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getAccountName(accountId) {
|
getAccountName(accountId) {
|
||||||
|
|
|
||||||
|
|
@ -302,7 +302,6 @@
|
||||||
round
|
round
|
||||||
icon="refresh"
|
icon="refresh"
|
||||||
@click="recheckAssertion(assertion.id)"
|
@click="recheckAssertion(assertion.id)"
|
||||||
:loading="assertion.rechecking"
|
|
||||||
>
|
>
|
||||||
<q-tooltip>Re-check assertion</q-tooltip>
|
<q-tooltip>Re-check assertion</q-tooltip>
|
||||||
</q-btn>
|
</q-btn>
|
||||||
|
|
@ -312,7 +311,6 @@
|
||||||
round
|
round
|
||||||
icon="delete"
|
icon="delete"
|
||||||
@click="deleteAssertion(assertion.id)"
|
@click="deleteAssertion(assertion.id)"
|
||||||
:loading="assertion.deleting"
|
|
||||||
>
|
>
|
||||||
<q-tooltip>Delete assertion</q-tooltip>
|
<q-tooltip>Delete assertion</q-tooltip>
|
||||||
</q-btn>
|
</q-btn>
|
||||||
|
|
@ -353,7 +351,6 @@
|
||||||
round
|
round
|
||||||
icon="refresh"
|
icon="refresh"
|
||||||
@click="recheckAssertion(assertion.id)"
|
@click="recheckAssertion(assertion.id)"
|
||||||
:loading="assertion.rechecking"
|
|
||||||
>
|
>
|
||||||
<q-tooltip>Re-check assertion</q-tooltip>
|
<q-tooltip>Re-check assertion</q-tooltip>
|
||||||
</q-btn>
|
</q-btn>
|
||||||
|
|
@ -363,7 +360,6 @@
|
||||||
round
|
round
|
||||||
icon="delete"
|
icon="delete"
|
||||||
@click="deleteAssertion(assertion.id)"
|
@click="deleteAssertion(assertion.id)"
|
||||||
:loading="assertion.deleting"
|
|
||||||
>
|
>
|
||||||
<q-tooltip>Delete assertion</q-tooltip>
|
<q-tooltip>Delete assertion</q-tooltip>
|
||||||
</q-btn>
|
</q-btn>
|
||||||
|
|
@ -929,12 +925,9 @@
|
||||||
v-model.number="assertionDialog.expected_balance_sats"
|
v-model.number="assertionDialog.expected_balance_sats"
|
||||||
type="number"
|
type="number"
|
||||||
label="Expected Balance (sats) *"
|
label="Expected Balance (sats) *"
|
||||||
:rules="[val => val !== null && val !== undefined || 'Expected balance is required']"
|
hint="The balance you expect this account to have in satoshis"
|
||||||
>
|
:rules="[val => val !== null && val !== undefined && val !== '' || 'Expected balance is required']"
|
||||||
<template v-slot:hint>
|
></q-input>
|
||||||
The balance you expect this account to have in satoshis
|
|
||||||
</template>
|
|
||||||
</q-input>
|
|
||||||
|
|
||||||
<q-input
|
<q-input
|
||||||
filled
|
filled
|
||||||
|
|
@ -943,15 +936,12 @@
|
||||||
type="number"
|
type="number"
|
||||||
label="Tolerance (sats)"
|
label="Tolerance (sats)"
|
||||||
min="0"
|
min="0"
|
||||||
>
|
hint="Allow the actual balance to differ by ± this amount (default: 0)"
|
||||||
<template v-slot:hint>
|
></q-input>
|
||||||
Allow the actual balance to differ by ± this amount (default: 0)
|
|
||||||
</template>
|
|
||||||
</q-input>
|
|
||||||
|
|
||||||
<q-separator />
|
<q-separator class="q-my-md"></q-separator>
|
||||||
|
|
||||||
<div class="text-subtitle2">Optional: Fiat Balance Check</div>
|
<div class="text-subtitle2 q-mb-sm">Optional: Fiat Balance Check</div>
|
||||||
|
|
||||||
<q-select
|
<q-select
|
||||||
filled
|
filled
|
||||||
|
|
@ -987,11 +977,11 @@
|
||||||
min="0"
|
min="0"
|
||||||
></q-input>
|
></q-input>
|
||||||
|
|
||||||
<div class="row q-mt-lg">
|
<div class="row q-mt-md q-gutter-sm">
|
||||||
<q-btn unelevated color="primary" type="submit" :loading="assertionDialog.loading">
|
<q-btn unelevated color="primary" type="submit" :loading="assertionDialog.loading">
|
||||||
Create & Check
|
Create & Check
|
||||||
</q-btn>
|
</q-btn>
|
||||||
<q-btn v-close-popup flat color="grey" class="q-ml-auto">Cancel</q-btn>
|
<q-btn v-close-popup flat color="grey">Cancel</q-btn>
|
||||||
</div>
|
</div>
|
||||||
</q-form>
|
</q-form>
|
||||||
</q-card>
|
</q-card>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue