Files
kidsai/html/rechner/test.html
2025-06-24 15:43:32 +02:00

205 lines
7.7 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Asset Conversion Test</title>
<style>
body {
font-family: sans-serif;
background: #222;
color: #eee;
padding: 20px;
}
.form-row {
margin: 10px 0;
display: flex;
align-items: center;
}
label {
width: 150px;
padding-right: 10px;
}
button {
margin-top: 15px;
padding: 8px 15px;
background: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
select, input {
padding: 5px;
background: #333;
color: white;
border: 1px solid #555;
}
.result-box {
margin-top: 20px;
padding: 15px;
background: #333;
border: 1px solid #555;
border-radius: 5px;
white-space: pre-wrap;
}
</style>
</head>
<body>
<h1>Asset Conversion Test</h1>
<div class="form">
<div class="form-row">
<label for="fromAsset">From Asset:</label>
<select id="fromAsset">
<option value="coinTracker1">Fartcoin/sol</option>
<option value="coinTracker2">SUI</option>
</select>
</div>
<div class="form-row">
<label for="conversionAmount">Dollar Amount ($):</label>
<input type="number" id="conversionAmount" value="3" step="0.01">
</div>
<div class="form-row">
<label for="conversionType">Type:</label>
<select id="conversionType">
<option value="principal">Reduce Principal</option>
<option value="income" selected>Transfer Income Only</option>
</select>
</div>
<div class="form-row">
<label for="toAsset">To Asset:</label>
<select id="toAsset">
<option value="coinTracker1">Fartcoin/sol</option>
<option value="coinTracker2" selected>SUI</option>
</select>
</div>
<button id="executeConversion">Transfer Dollar Value</button>
</div>
<div class="result-box" id="results">Results will appear here</div>
<script>
// Create mock coin tracker elements for testing
function createMockTracker(id, name) {
const div = document.createElement('div');
div.id = id;
div.className = "coin-tracker";
div.style.display = "none";
// Create header
const header = document.createElement('div');
header.className = "coin-tracker-header";
// Create name input
const nameInput = document.createElement('input');
nameInput.className = "coin-name-input";
nameInput.value = name;
header.appendChild(nameInput);
div.appendChild(header);
// Create table structure
const table = document.createElement('table');
table.className = "coin-table";
const tbody = document.createElement('tbody');
table.appendChild(tbody);
div.appendChild(table);
return div;
}
// Add them to the document
document.body.appendChild(createMockTracker("coinTracker1", "Fartcoin/sol"));
document.body.appendChild(createMockTracker("coinTracker2", "SUI"));
// Simple helper for testing
function $(id) {
return document.getElementById(id);
}
// Add a function to simulate the converter with detailed logging
function recordAssetTransfer(fromId, toId, dollarAmount, transferType) {
const fromTracker = $(fromId);
const toTracker = $(toId);
log(`Starting asset transfer: ${fromId} -> ${toId}, amount: $${dollarAmount}, type: ${transferType}`);
if (!fromTracker || !toTracker) {
log(`ERROR: Could not find one or both trackers:\n - fromTracker: ${fromTracker ? 'Found' : 'Not found'}\n - toTracker: ${toTracker ? 'Found' : 'Not found'}`);
return;
}
// Get coin names for logging
const fromName = fromTracker.querySelector(".coin-tracker-header input.coin-name-input").value;
const toName = toTracker.querySelector(".coin-tracker-header input.coin-name-input").value;
log(`Found trackers:\n - From: ${fromName} (${fromId})\n - To: ${toName} (${toId})`);
// Get table elements
const sourceTable = fromTracker.querySelector("table.coin-table");
const destTable = toTracker.querySelector("table.coin-table");
if (!sourceTable || !destTable) {
log(`ERROR: Could not find tables:\n - Source table: ${sourceTable ? 'Found' : 'Not found'}\n - Destination table: ${destTable ? 'Found' : 'Not found'}`);
return;
}
log(`Found tables:\n - Source: ${sourceTable.tagName}\n - Destination: ${destTable.tagName}`);
// Get tbody elements
const sourceTbody = sourceTable.querySelector("tbody");
const destTbody = destTable.querySelector("tbody");
if (!sourceTbody || !destTbody) {
log(`ERROR: Could not find tbody elements:\n - Source tbody: ${sourceTbody ? 'Found' : 'Not found'}\n - Destination tbody: ${destTbody ? 'Found' : 'Not found'}`);
return;
}
log(`Found tbody elements:\n - Source: ${sourceTbody.tagName}\n - Destination: ${destTbody.tagName}`);
// In a real implementation, you'd add rows to the tables here
log(`SUCCESS: Transfer of $${dollarAmount} from ${fromName} to ${toName} completed!`);
return true;
}
// Function to log results
function log(message) {
$('results').textContent += "\n" + message;
}
// Set up convert button
$('executeConversion').addEventListener('click', () => {
// Clear previous results
$('results').textContent = "Executing transfer...";
// Get form values
const fromAsset = $('fromAsset').value;
const toAsset = $('toAsset').value;
const dollarAmount = parseFloat($('conversionAmount').value) || 0;
const transferType = $('conversionType').value;
log(`Form values:\n - fromAsset: ${fromAsset}\n - toAsset: ${toAsset}\n - dollarAmount: ${dollarAmount}\n - transferType: ${transferType}`);
if (fromAsset && toAsset && dollarAmount > 0) {
log("All validation passed, calling recordAssetTransfer");
try {
const result = recordAssetTransfer(fromAsset, toAsset, dollarAmount, transferType);
log(`Transfer result: ${result ? "SUCCESS" : "FAILED"}`);
} catch (error) {
log(`ERROR during asset transfer: ${error.message}`);
console.error("Error during asset transfer:", error);
}
} else {
log("VALIDATION FAILED: Please fill in all fields with valid values.");
}
});
</script>
</body>
</html>