Add test transaction endpoint and UI integration: implement API for simulating transactions with mock data, including commission and discount calculations. Enhance frontend to trigger test transactions and display results in a dialog, improving user experience and testing capabilities.
This commit is contained in:
parent
df8b36fc0f
commit
5f21a27f0e
3 changed files with 122 additions and 0 deletions
|
|
@ -60,6 +60,7 @@ window.app = Vue.createApp({
|
||||||
lastPollTime: null,
|
lastPollTime: null,
|
||||||
testingConnection: false,
|
testingConnection: false,
|
||||||
runningManualPoll: false,
|
runningManualPoll: false,
|
||||||
|
runningTestTransaction: false,
|
||||||
lamassuConfig: null,
|
lamassuConfig: null,
|
||||||
|
|
||||||
// Config dialog
|
// Config dialog
|
||||||
|
|
@ -515,6 +516,57 @@ window.app = Vue.createApp({
|
||||||
this.runningManualPoll = false
|
this.runningManualPoll = false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async testTransaction() {
|
||||||
|
this.runningTestTransaction = true
|
||||||
|
try {
|
||||||
|
const {data} = await LNbits.api.request(
|
||||||
|
'POST',
|
||||||
|
'/myextension/api/v1/dca/test-transaction',
|
||||||
|
this.g.user.wallets[0].adminkey
|
||||||
|
)
|
||||||
|
|
||||||
|
// Show detailed results in a dialog
|
||||||
|
const details = data.transaction_details
|
||||||
|
|
||||||
|
let dialogContent = `<strong>Test Transaction Results</strong><br/><br/>`
|
||||||
|
dialogContent += `<strong>Transaction ID:</strong> ${details.transaction_id}<br/>`
|
||||||
|
dialogContent += `<strong>Total Amount:</strong> ${details.total_amount_sats} sats<br/>`
|
||||||
|
dialogContent += `<strong>Base Amount:</strong> ${details.base_amount_sats} sats<br/>`
|
||||||
|
dialogContent += `<strong>Commission:</strong> ${details.commission_amount_sats} sats (${details.commission_percentage}%)<br/>`
|
||||||
|
if (details.discount > 0) {
|
||||||
|
dialogContent += `<strong>Discount:</strong> ${details.discount}%<br/>`
|
||||||
|
dialogContent += `<strong>Effective Commission:</strong> ${details.effective_commission}%<br/>`
|
||||||
|
}
|
||||||
|
dialogContent += `<br/><strong>Check your wallets to see the distributions!</strong>`
|
||||||
|
|
||||||
|
this.$q.dialog({
|
||||||
|
title: 'Test Transaction Completed',
|
||||||
|
message: dialogContent,
|
||||||
|
html: true,
|
||||||
|
ok: {
|
||||||
|
color: 'positive',
|
||||||
|
label: 'Great!'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Also show a brief notification
|
||||||
|
this.$q.notify({
|
||||||
|
type: 'positive',
|
||||||
|
message: `Test transaction processed: ${details.total_amount_sats} sats distributed`,
|
||||||
|
timeout: 5000
|
||||||
|
})
|
||||||
|
|
||||||
|
// Refresh data
|
||||||
|
await this.getDeposits()
|
||||||
|
await this.getLamassuConfig()
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
LNbits.utils.notifyApiError(error)
|
||||||
|
} finally {
|
||||||
|
this.runningTestTransaction = false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
// Legacy Methods (keep for backward compatibility)
|
// Legacy Methods (keep for backward compatibility)
|
||||||
async closeFormDialog() {
|
async closeFormDialog() {
|
||||||
|
|
|
||||||
|
|
@ -383,6 +383,16 @@
|
||||||
>
|
>
|
||||||
Manual Poll
|
Manual Poll
|
||||||
</q-btn>
|
</q-btn>
|
||||||
|
<q-btn
|
||||||
|
v-if="lamassuConfig && lamassuConfig.source_wallet_id"
|
||||||
|
size="sm"
|
||||||
|
color="warning"
|
||||||
|
@click="testTransaction"
|
||||||
|
:loading="runningTestTransaction"
|
||||||
|
class="q-ml-sm"
|
||||||
|
>
|
||||||
|
Test Transaction
|
||||||
|
</q-btn>
|
||||||
</div>
|
</div>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-expansion-item>
|
</q-expansion-item>
|
||||||
|
|
|
||||||
60
views_api.py
60
views_api.py
|
|
@ -390,6 +390,66 @@ async def api_manual_poll(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@myextension_api_router.post("/api/v1/dca/test-transaction")
|
||||||
|
async def api_test_transaction(
|
||||||
|
wallet: WalletTypeInfo = Depends(require_admin_key),
|
||||||
|
crypto_atoms: int = 103,
|
||||||
|
commission_percentage: float = 0.03,
|
||||||
|
discount: float = 0.0,
|
||||||
|
) -> dict:
|
||||||
|
"""Test transaction processing with simulated Lamassu transaction data"""
|
||||||
|
try:
|
||||||
|
from .transaction_processor import transaction_processor
|
||||||
|
import uuid
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
|
# Create a mock transaction that mimics Lamassu database structure
|
||||||
|
mock_transaction = {
|
||||||
|
"transaction_id": str(uuid.uuid4())[:8], # Short ID for testing
|
||||||
|
"crypto_amount": crypto_atoms, # Total sats including commission
|
||||||
|
"fiat_amount": 100, # Mock fiat amount (100 centavos = 1 GTQ)
|
||||||
|
"commission_percentage": commission_percentage, # Already as decimal
|
||||||
|
"discount": discount,
|
||||||
|
"transaction_time": datetime.now(timezone.utc),
|
||||||
|
"crypto_code": "BTC",
|
||||||
|
"fiat_code": "GTQ",
|
||||||
|
"device_id": "test_device",
|
||||||
|
"status": "confirmed"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Process the mock transaction through the complete DCA flow
|
||||||
|
await transaction_processor.process_transaction(mock_transaction)
|
||||||
|
|
||||||
|
# Calculate commission for response
|
||||||
|
if commission_percentage > 0:
|
||||||
|
effective_commission = commission_percentage * (100 - discount) / 100
|
||||||
|
base_crypto_atoms = int(crypto_atoms / (1 + effective_commission))
|
||||||
|
commission_amount_sats = crypto_atoms - base_crypto_atoms
|
||||||
|
else:
|
||||||
|
base_crypto_atoms = crypto_atoms
|
||||||
|
commission_amount_sats = 0
|
||||||
|
|
||||||
|
return {
|
||||||
|
"success": True,
|
||||||
|
"message": "Test transaction processed successfully",
|
||||||
|
"transaction_details": {
|
||||||
|
"transaction_id": mock_transaction["transaction_id"],
|
||||||
|
"total_amount_sats": crypto_atoms,
|
||||||
|
"base_amount_sats": base_crypto_atoms,
|
||||||
|
"commission_amount_sats": commission_amount_sats,
|
||||||
|
"commission_percentage": commission_percentage * 100, # Show as percentage
|
||||||
|
"effective_commission": effective_commission * 100 if commission_percentage > 0 else 0,
|
||||||
|
"discount": discount
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
|
||||||
|
detail=f"Error processing test transaction: {str(e)}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# Lamassu Configuration Endpoints
|
# Lamassu Configuration Endpoints
|
||||||
|
|
||||||
@myextension_api_router.get("/api/v1/dca/config")
|
@myextension_api_router.get("/api/v1/dca/config")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue