01 Refactor currency handling to store amounts in GTQ: Removed currency conversion utilities, updated models and API endpoints to directly handle GTQ amounts, and modified transaction processing logic for consistency. Enhanced frontend to reflect these changes, ensuring accurate display and submission of GTQ values across the application.

Refactor GTQ storage migration: Moved the conversion logic for centavo amounts to GTQ into a new migration function, m004_convert_to_gtq_storage, ensuring proper data type changes and updates across relevant tables. This enhances clarity and maintains the integrity of the migration process.
This commit is contained in:
padreug 2025-07-06 00:00:30 +02:00
parent aa71321c84
commit c83ebf43ab
8 changed files with 157 additions and 162 deletions

View file

@ -38,23 +38,14 @@ from .models import (
DcaClient,
UpdateDcaClientData,
CreateDepositData,
CreateDepositAPI,
DepositAPI,
DcaDeposit,
UpdateDepositStatusData,
ClientBalanceSummary,
ClientBalanceSummaryAPI,
CreateLamassuConfigData,
LamassuConfig,
UpdateLamassuConfigData,
StoredLamassuTransaction,
)
from .currency_utils import (
gtq_to_centavos,
centavos_to_gtq,
deposit_db_to_api,
balance_summary_db_to_api,
)
satmachineadmin_api_router = APIRouter()
@ -96,7 +87,7 @@ async def api_get_dca_client(
async def api_get_client_balance(
client_id: str,
wallet: WalletTypeInfo = Depends(check_super_user),
) -> ClientBalanceSummaryAPI:
) -> ClientBalanceSummary:
"""Get client balance summary"""
client = await get_dca_client(client_id)
if not client:
@ -104,8 +95,7 @@ async def api_get_client_balance(
status_code=HTTPStatus.NOT_FOUND, detail="DCA client not found."
)
balance_db = await get_client_balance_summary(client_id)
return ClientBalanceSummaryAPI(**balance_summary_db_to_api(balance_db))
return await get_client_balance_summary(client_id)
# DCA Deposit Endpoints
@ -114,31 +104,30 @@ async def api_get_client_balance(
@satmachineadmin_api_router.get("/api/v1/dca/deposits")
async def api_get_deposits(
wallet: WalletTypeInfo = Depends(check_super_user),
) -> list[DepositAPI]:
) -> list[DcaDeposit]:
"""Get all deposits"""
deposits_db = await get_all_deposits()
return [DepositAPI(**deposit_db_to_api(deposit)) for deposit in deposits_db]
return await get_all_deposits()
@satmachineadmin_api_router.get("/api/v1/dca/deposits/{deposit_id}")
async def api_get_deposit(
deposit_id: str,
wallet: WalletTypeInfo = Depends(check_super_user),
) -> DepositAPI:
) -> DcaDeposit:
"""Get a specific deposit"""
deposit_db = await get_deposit(deposit_id)
if not deposit_db:
deposit = await get_deposit(deposit_id)
if not deposit:
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="Deposit not found."
)
return DepositAPI(**deposit_db_to_api(deposit_db))
return deposit
@satmachineadmin_api_router.post("/api/v1/dca/deposits", status_code=HTTPStatus.CREATED)
async def api_create_deposit(
data: CreateDepositAPI,
data: CreateDepositData,
user: User = Depends(check_super_user),
) -> DepositAPI:
) -> DcaDeposit:
"""Create a new deposit"""
# Verify client exists
client = await get_dca_client(data.client_id)
@ -147,16 +136,7 @@ async def api_create_deposit(
status_code=HTTPStatus.NOT_FOUND, detail="DCA client not found."
)
# Convert GTQ to centavos at API boundary
deposit_data = CreateDepositData(
client_id=data.client_id,
amount=gtq_to_centavos(data.amount_gtq),
currency=data.currency,
notes=data.notes
)
deposit_db = await create_deposit(deposit_data)
return DepositAPI(**deposit_db_to_api(deposit_db))
return await create_deposit(data)
@satmachineadmin_api_router.put("/api/v1/dca/deposits/{deposit_id}/status")
@ -164,7 +144,7 @@ async def api_update_deposit_status(
deposit_id: str,
data: UpdateDepositStatusData,
user: User = Depends(check_super_user),
) -> DepositAPI:
) -> DcaDeposit:
"""Update deposit status (e.g., confirm deposit)"""
deposit = await get_deposit(deposit_id)
if not deposit:
@ -172,13 +152,13 @@ async def api_update_deposit_status(
status_code=HTTPStatus.NOT_FOUND, detail="Deposit not found."
)
updated_deposit_db = await update_deposit_status(deposit_id, data)
if not updated_deposit_db:
updated_deposit = await update_deposit_status(deposit_id, data)
if not updated_deposit:
raise HTTPException(
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
detail="Failed to update deposit.",
)
return DepositAPI(**deposit_db_to_api(updated_deposit_db))
return updated_deposit
# Transaction Polling Endpoints