Commit eb05beac authored by Your Name's avatar Your Name

Fix consolidation settings not saving

- Updated API endpoint to handle simple key-value format from frontend
- Endpoint now accepts both old format (consolidation_settings array) and new format (btc/eth/usdt/usdc keys)
- Maps lowercase keys to uppercase crypto_type in database (btc -> BTC, etc)
- Only updates threshold_amount, preserves admin_address and is_enabled
- Fixes issue where changing page would reset values to defaults
parent f0f3d96f
...@@ -6533,7 +6533,10 @@ async def update_payment_consolidation_config(request: Request): ...@@ -6533,7 +6533,10 @@ async def update_payment_consolidation_config(request: Request):
cursor = conn.cursor() cursor = conn.cursor()
placeholder = '?' if db.db_type == 'sqlite' else '%s' placeholder = '?' if db.db_type == 'sqlite' else '%s'
for setting in body.get('consolidation_settings', []): # Handle both old format (consolidation_settings array) and new format (btc/eth/usdt/usdc keys)
if 'consolidation_settings' in body:
# Old format
for setting in body['consolidation_settings']:
cursor.execute(f""" cursor.execute(f"""
UPDATE crypto_consolidation_settings UPDATE crypto_consolidation_settings
SET threshold_amount = {placeholder}, SET threshold_amount = {placeholder},
...@@ -6542,10 +6545,27 @@ async def update_payment_consolidation_config(request: Request): ...@@ -6542,10 +6545,27 @@ async def update_payment_consolidation_config(request: Request):
WHERE crypto_type = {placeholder} WHERE crypto_type = {placeholder}
""", ( """, (
setting['threshold'], setting['threshold'],
setting['admin_address'], setting.get('admin_address', ''),
setting['enabled'], setting.get('enabled', True),
setting['crypto_type'] setting['crypto_type']
)) ))
else:
# New format - simple key-value pairs
crypto_map = {
'btc': 'BTC',
'eth': 'ETH',
'usdt': 'USDT',
'usdc': 'USDC'
}
for key, crypto_type in crypto_map.items():
if key in body:
threshold = float(body[key])
cursor.execute(f"""
UPDATE crypto_consolidation_settings
SET threshold_amount = {placeholder}
WHERE crypto_type = {placeholder}
""", (threshold, crypto_type))
conn.commit() conn.commit()
......
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