From b3332e585aa1762e1bbd9aa05da8025e90ce4853 Mon Sep 17 00:00:00 2001 From: padreug Date: Tue, 17 Jun 2025 19:28:53 +0200 Subject: [PATCH] Refactor DCA client management: remove CRUD operations for clients and update UI to focus on deposit management. Introduce quick deposit form for existing clients. --- static/js/index.js | 90 ++++++++------------ templates/myextension/index.html | 141 ++++++++++++++----------------- views_api.py | 46 +--------- 3 files changed, 103 insertions(+), 174 deletions(-) diff --git a/static/js/index.js b/static/js/index.js index 947aecb..0cfefb1 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -36,14 +36,7 @@ window.app = Vue.createApp({ } }, - // Dialog states - clientFormDialog: { - show: false, - data: { - dca_mode: 'flow', - currency: 'GTQ' - } - }, + // Dialog states depositFormDialog: { show: false, data: { @@ -56,11 +49,14 @@ window.app = Vue.createApp({ balance: null }, + // Quick deposit form + quickDepositForm: { + client_id: '', + amount: null, + notes: '' + }, + // Options - dcaModeOptions: [ - {label: 'Flow Mode', value: 'flow'}, - {label: 'Fixed Mode', value: 'fixed'} - ], currencyOptions: [ {label: 'GTQ', value: 'GTQ'}, {label: 'USD', value: 'USD'} @@ -123,43 +119,35 @@ window.app = Vue.createApp({ } }, - async sendClientData() { + // Quick Deposit Methods + async sendQuickDeposit() { try { const data = { - user_id: this.clientFormDialog.data.user_id, - wallet_id: this.clientFormDialog.data.wallet_id, - dca_mode: this.clientFormDialog.data.dca_mode, - fixed_mode_daily_limit: this.clientFormDialog.data.fixed_mode_daily_limit + client_id: this.quickDepositForm.client_id, + amount: this.quickDepositForm.amount, + currency: 'GTQ', + notes: this.quickDepositForm.notes } - if (this.clientFormDialog.data.id) { - // Update existing client - const {data: updatedClient} = await LNbits.api.request( - 'PUT', - `/myextension/api/v1/dca/clients/${this.clientFormDialog.data.id}`, - this.g.user.wallets[0].adminkey, - data - ) - // Update client in array - const index = this.dcaClients.findIndex(c => c.id === updatedClient.id) - if (index !== -1) { - this.dcaClients.splice(index, 1, updatedClient) - } - } else { - // Create new client - const {data: newClient} = await LNbits.api.request( - 'POST', - '/myextension/api/v1/dca/clients', - this.g.user.wallets[0].adminkey, - data - ) - this.dcaClients.push(newClient) + const {data: newDeposit} = await LNbits.api.request( + 'POST', + '/myextension/api/v1/dca/deposits', + this.g.user.wallets[0].adminkey, + data + ) + + this.deposits.unshift(newDeposit) + + // Reset form + this.quickDepositForm = { + client_id: '', + amount: null, + notes: '' } - this.closeClientFormDialog() this.$q.notify({ type: 'positive', - message: this.clientFormDialog.data.id ? 'Client updated successfully' : 'Client created successfully', + message: 'Deposit created successfully', timeout: 5000 }) } catch (error) { @@ -167,19 +155,6 @@ window.app = Vue.createApp({ } }, - closeClientFormDialog() { - this.clientFormDialog.show = false - this.clientFormDialog.data = { - dca_mode: 'flow', - currency: 'GTQ' - } - }, - - editClient(client) { - this.clientFormDialog.data = {...client} - this.clientFormDialog.show = true - }, - async viewClientDetails(client) { try { const {data: balance} = await LNbits.api.request( @@ -521,6 +496,13 @@ window.app = Vue.createApp({ }, computed: { + clientOptions() { + return this.dcaClients.map(client => ({ + label: `${client.user_id.substring(0, 8)}... (${client.dca_mode})`, + value: client.id + })) + }, + calculateTotalDcaBalance() { this.totalDcaBalance = this.deposits .filter(d => d.status === 'confirmed') diff --git a/templates/myextension/index.html b/templates/myextension/index.html index 6c87b22..1c89b97 100644 --- a/templates/myextension/index.html +++ b/templates/myextension/index.html @@ -8,17 +8,13 @@ {% endblock %} {% block page %}
- +
-
DCA Client Management
-
-
- - Add New Client - +
DCA Deposit Management
+

Manage fiat deposits for existing DCA clients

@@ -29,7 +25,8 @@
-
Active DCA Clients
+
Registered DCA Clients
+

Clients registered via the DCA client extension

Export to CSV @@ -53,7 +50,10 @@ ${ col.value }
-
${ col.value }
+
+ ${ formatCurrency(col.value) } +
+
${ col.value || '-' }
- View Details - - - Edit Client + View Balance & Details @@ -270,68 +263,64 @@
- + - - - - - - - -
- Update Client - Create Client - Cancel + + +
Quick Add Deposit
+

Add a new deposit for an existing client

+ +
+
+ +
+
+ +
+
+ Add Deposit +
+
+
+
+ +
-
- + + diff --git a/views_api.py b/views_api.py index 0f9ba7c..444489b 100644 --- a/views_api.py +++ b/views_api.py @@ -220,50 +220,8 @@ async def api_get_dca_client( return client -@myextension_api_router.post("/api/v1/dca/clients", status_code=HTTPStatus.CREATED) -async def api_create_dca_client( - data: CreateDcaClientData, - wallet: WalletTypeInfo = Depends(require_admin_key), -) -> DcaClient: - """Create a new DCA client""" - return await create_dca_client(data) - - -@myextension_api_router.put("/api/v1/dca/clients/{client_id}") -async def api_update_dca_client( - client_id: str, - data: UpdateDcaClientData, - wallet: WalletTypeInfo = Depends(require_admin_key), -) -> DcaClient: - """Update a DCA client""" - client = await get_dca_client(client_id) - if not client: - raise HTTPException( - status_code=HTTPStatus.NOT_FOUND, detail="DCA client not found." - ) - - updated_client = await update_dca_client(client_id, data) - if not updated_client: - raise HTTPException( - status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail="Failed to update client." - ) - return updated_client - - -@myextension_api_router.delete("/api/v1/dca/clients/{client_id}") -async def api_delete_dca_client( - client_id: str, - wallet: WalletTypeInfo = Depends(require_admin_key), -): - """Delete a DCA client""" - client = await get_dca_client(client_id) - if not client: - raise HTTPException( - status_code=HTTPStatus.NOT_FOUND, detail="DCA client not found." - ) - - await delete_dca_client(client_id) - return {"message": "Client deleted successfully"} +# Note: Client creation/update/delete will be handled by the DCA client extension +# Admin extension only reads existing clients and manages their deposits @myextension_api_router.get("/api/v1/dca/clients/{client_id}/balance")