Commit 29d64814 authored by Your Name's avatar Your Name

Add logging and visual feedback for consolidation settings

- Added detailed logging to track consolidation updates
- Logs received config, rows affected, and commit status
- Returns success:false on errors for proper frontend handling
- Frontend now shows toast notifications on save success/failure
- Added console logging for debugging
- Checks rowcount to detect if records exist in database
parent eb05beac
......@@ -6529,6 +6529,8 @@ async def update_payment_consolidation_config(request: Request):
body = await request.json()
db = DatabaseRegistry.get_config_database()
logger.info(f"Received consolidation config update: {body}")
with db._get_connection() as conn:
cursor = conn.cursor()
placeholder = '?' if db.db_type == 'sqlite' else '%s'
......@@ -6549,6 +6551,7 @@ async def update_payment_consolidation_config(request: Request):
setting.get('enabled', True),
setting['crypto_type']
))
logger.info(f"Updated {setting['crypto_type']} threshold to {setting['threshold']}")
else:
# New format - simple key-value pairs
crypto_map = {
......@@ -6558,6 +6561,7 @@ async def update_payment_consolidation_config(request: Request):
'usdc': 'USDC'
}
updated_count = 0
for key, crypto_type in crypto_map.items():
if key in body:
threshold = float(body[key])
......@@ -6566,13 +6570,20 @@ async def update_payment_consolidation_config(request: Request):
SET threshold_amount = {placeholder}
WHERE crypto_type = {placeholder}
""", (threshold, crypto_type))
rows_affected = cursor.rowcount
logger.info(f"Updated {crypto_type} threshold to {threshold}, rows affected: {rows_affected}")
updated_count += rows_affected
if updated_count == 0:
logger.warning("No rows were updated - records may not exist in database")
conn.commit()
logger.info("Consolidation settings committed to database")
return JSONResponse({'success': True, 'message': 'Consolidation settings updated'})
except Exception as e:
logger.error(f"Error updating consolidation settings: {e}")
return JSONResponse({'error': str(e)}, status_code=500)
logger.error(f"Error updating consolidation settings: {e}", exc_info=True)
return JSONResponse({'success': False, 'error': str(e)}, status_code=500)
@app.post("/api/admin/config/consolidation")
async def update_consolidation_config(request: Request):
......
......@@ -801,6 +801,8 @@ async function saveConsolidationConfig() {
usdc: parseFloat(document.getElementById('consolidationUSDC').value)
};
console.log('Saving consolidation config:', config);
try {
const response = await fetch('{{ url_for(request, "/api/admin/payment-system/config/consolidation") }}', {
method: 'PUT',
......@@ -808,12 +810,16 @@ async function saveConsolidationConfig() {
body: JSON.stringify(config)
});
if (response.ok) {
showToast('Consolidation settings saved', 'success');
const result = await response.json();
console.log('Save response:', result);
if (response.ok && result.success) {
showToast('Consolidation settings saved successfully', 'success');
} else {
showToast('Failed to save consolidation settings', 'danger');
showToast(result.error || 'Failed to save consolidation settings', 'danger');
}
} catch (error) {
console.error('Error saving consolidation settings:', error);
showToast('Error saving consolidation settings: ' + error.message, 'danger');
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment