Refactor DCA client management: remove CRUD operations for clients and update UI to focus on deposit management. Introduce quick deposit form for existing clients.
This commit is contained in:
parent
7bafc67370
commit
b3332e585a
3 changed files with 103 additions and 174 deletions
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -8,17 +8,13 @@
|
|||
{% endblock %} {% block page %}
|
||||
<div class="row q-col-gutter-md" id="dcaAdmin">
|
||||
<div class="col-12 col-md-8 col-lg-7 q-gutter-y-md">
|
||||
<!-- Client Management Section -->
|
||||
<!-- Deposit Management Section -->
|
||||
<q-card>
|
||||
<q-card-section>
|
||||
<div class="row items-center no-wrap q-mb-md">
|
||||
<div class="col">
|
||||
<h5 class="text-subtitle1 q-my-none">DCA Client Management</h5>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<q-btn unelevated color="primary" @click="clientFormDialog.show = true">
|
||||
Add New Client
|
||||
</q-btn>
|
||||
<h5 class="text-subtitle1 q-my-none">DCA Deposit Management</h5>
|
||||
<p class="text-caption q-my-none">Manage fiat deposits for existing DCA clients</p>
|
||||
</div>
|
||||
</div>
|
||||
</q-card-section>
|
||||
|
|
@ -29,7 +25,8 @@
|
|||
<q-card-section>
|
||||
<div class="row items-center no-wrap q-mb-md">
|
||||
<div class="col">
|
||||
<h6 class="text-subtitle2 q-my-none">Active DCA Clients</h6>
|
||||
<h6 class="text-subtitle2 q-my-none">Registered DCA Clients</h6>
|
||||
<p class="text-caption q-my-none">Clients registered via the DCA client extension</p>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<q-btn flat color="grey" @click="exportClientsCSV">Export to CSV</q-btn>
|
||||
|
|
@ -53,7 +50,10 @@
|
|||
${ col.value }
|
||||
</q-badge>
|
||||
</div>
|
||||
<div v-else>${ col.value }</div>
|
||||
<div v-else-if="col.field == 'fixed_mode_daily_limit' && col.value">
|
||||
${ formatCurrency(col.value) }
|
||||
</div>
|
||||
<div v-else>${ col.value || '-' }</div>
|
||||
</q-td>
|
||||
<q-td auto-width>
|
||||
<q-btn
|
||||
|
|
@ -65,17 +65,10 @@
|
|||
</q-btn>
|
||||
<q-btn
|
||||
flat dense size="sm" icon="visibility"
|
||||
color="blue" class="q-mr-sm"
|
||||
color="blue"
|
||||
@click="viewClientDetails(props.row)"
|
||||
>
|
||||
<q-tooltip>View Details</q-tooltip>
|
||||
</q-btn>
|
||||
<q-btn
|
||||
flat dense size="sm" icon="edit"
|
||||
color="orange" class="q-mr-sm"
|
||||
@click="editClient(props.row)"
|
||||
>
|
||||
<q-tooltip>Edit Client</q-tooltip>
|
||||
<q-tooltip>View Balance & Details</q-tooltip>
|
||||
</q-btn>
|
||||
</q-td>
|
||||
</q-tr>
|
||||
|
|
@ -270,68 +263,64 @@
|
|||
</div>
|
||||
|
||||
<!--/////////////////////////////////////////////////-->
|
||||
<!--//////////////DCA CLIENT FORM DIALOG//////////////-->
|
||||
<!--//////////////QUICK ADD DEPOSIT SECTION//////////-->
|
||||
<!--/////////////////////////////////////////////////-->
|
||||
|
||||
<q-dialog v-model="clientFormDialog.show" position="top" @hide="closeClientFormDialog">
|
||||
<q-card class="q-pa-lg q-pt-xl" style="width: 500px">
|
||||
<q-form @submit="sendClientData" class="q-gutter-md">
|
||||
<q-input
|
||||
filled
|
||||
dense
|
||||
v-model.trim="clientFormDialog.data.user_id"
|
||||
label="User ID *"
|
||||
placeholder="LNBits User ID"
|
||||
></q-input>
|
||||
<q-select
|
||||
filled
|
||||
dense
|
||||
emit-value
|
||||
v-model="clientFormDialog.data.wallet_id"
|
||||
:options="g.user.walletOptions"
|
||||
label="DCA Wallet *"
|
||||
hint="Wallet to receive DCA payments"
|
||||
></q-select>
|
||||
<q-select
|
||||
filled
|
||||
dense
|
||||
emit-value
|
||||
v-model="clientFormDialog.data.dca_mode"
|
||||
:options="dcaModeOptions"
|
||||
label="DCA Mode *"
|
||||
></q-select>
|
||||
<q-input
|
||||
v-if="clientFormDialog.data.dca_mode === 'fixed'"
|
||||
filled
|
||||
dense
|
||||
type="number"
|
||||
v-model.number="clientFormDialog.data.fixed_mode_daily_limit"
|
||||
label="Daily Limit (GTQ)"
|
||||
placeholder="Maximum daily DCA amount"
|
||||
></q-input>
|
||||
<div class="row q-mt-lg">
|
||||
<q-btn
|
||||
v-if="clientFormDialog.data.id"
|
||||
unelevated
|
||||
color="primary"
|
||||
type="submit"
|
||||
>Update Client</q-btn
|
||||
>
|
||||
<q-btn
|
||||
v-else
|
||||
unelevated
|
||||
color="primary"
|
||||
:disable="!clientFormDialog.data.user_id || !clientFormDialog.data.wallet_id"
|
||||
type="submit"
|
||||
>Create Client</q-btn
|
||||
>
|
||||
<q-btn v-close-popup flat color="grey" class="q-ml-auto"
|
||||
>Cancel</q-btn
|
||||
>
|
||||
<q-card v-if="dcaClients.length > 0">
|
||||
<q-card-section>
|
||||
<h6 class="text-subtitle2 q-my-none">Quick Add Deposit</h6>
|
||||
<p class="text-caption q-my-none">Add a new deposit for an existing client</p>
|
||||
<q-form @submit="sendQuickDeposit" class="q-gutter-md q-mt-md">
|
||||
<div class="row q-gutter-md">
|
||||
<div class="col">
|
||||
<q-select
|
||||
filled
|
||||
dense
|
||||
emit-value
|
||||
v-model="quickDepositForm.client_id"
|
||||
:options="clientOptions"
|
||||
label="Select Client *"
|
||||
option-label="label"
|
||||
option-value="value"
|
||||
></q-select>
|
||||
</div>
|
||||
<div class="col">
|
||||
<q-input
|
||||
filled
|
||||
dense
|
||||
type="number"
|
||||
v-model.number="quickDepositForm.amount"
|
||||
label="Amount (GTQ) *"
|
||||
placeholder="Amount in centavos (GTQ * 100)"
|
||||
hint="Enter amount in centavos"
|
||||
></q-input>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<q-btn
|
||||
unelevated
|
||||
color="primary"
|
||||
type="submit"
|
||||
:disable="!quickDepositForm.client_id || !quickDepositForm.amount"
|
||||
>Add Deposit</q-btn
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<q-input
|
||||
filled
|
||||
dense
|
||||
type="textarea"
|
||||
v-model.trim="quickDepositForm.notes"
|
||||
label="Notes (Optional)"
|
||||
placeholder="Optional notes about this deposit"
|
||||
rows="2"
|
||||
></q-input>
|
||||
</div>
|
||||
</div>
|
||||
</q-form>
|
||||
</q-card>
|
||||
</q-dialog>
|
||||
</q-card-section>
|
||||
</q-card>
|
||||
|
||||
<!--/////////////////////////////////////////////////-->
|
||||
<!--//////////////DEPOSIT FORM DIALOG////////////////-->
|
||||
|
|
|
|||
46
views_api.py
46
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")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue