Volume / Market Cap Ratio: N/A (Market Cap is zero or invalid)
Bid-Ask Spread: ${formatNumber(bidAskSpreadPerc, 3)}%
Assessment: ${riskText}
Represents the cost to trade. Tighter spreads (lower percentage) are better.
Bid-Ask Spread: N/A (Ask Price is zero, or Bid Price is not less than Ask Price)
Buy-Side Depth (within 2%): $${formatNumber(depthBuy)}
Assessment: ${depthBuyAssessment.riskText}
The amount of buy orders near the current price. Higher indicates more support to absorb selling pressure.
Sell-Side Depth (within 2%): $${formatNumber(depthSell)}
Assessment: ${depthSellAssessment.riskText}
The amount of sell orders near the current price. Higher indicates more supply to absorb buying pressure.
Reputable Exchange Listings: ${exchangeListings}
Assessment: ${exchangeAssessment.riskText}
Number of listings on major exchanges. More reputable listings improve accessibility and perceived legitimacy.
Reputable Exchange Listings: N/A
${overallRiskText}
`; if(totalWeight > 0 && totalWeight < (weights.volumeToMarketCap + weights.bidAskSpread + weights.marketDepthBuy + weights.marketDepthSell + weights.exchangeListings) * 0.99) { // check if some data was missing overallAssessment.innerHTML += `(Note: Some data points were unavailable, which may affect the overall assessment accuracy.)
`; } // Enable report tab and next button, then switch to it reportTabButton.disabled = false; updateNavigationButtons(); // This will enable the 'Next' button if it was disabled return true; // Indicate successful processing } function validateAndProcess() { if (validateInputs()) { if(calculateLiquidityRisk()){ return true; } else { // This case might not be hit if calculateLiquidityRisk always returns true or errors out // but as a safeguard: reportTabButton.disabled = true; updateNavigationButtons(); return false; } } else { reportTabButton.disabled = true; // Keep report tab disabled if validation fails updateNavigationButtons(); // Ensure 'Next' button reflects this state return false; } } // Event listener for the "Assess Liquidity Risk" button if (assessButton) { assessButton.addEventListener('click', () => { if(validateAndProcess()){ // Automatically navigate to the report tab if validation and processing are successful showTab('reportTab', reportTabButton); // Use reportTabButton as the clicked button for styling } }); } // Event listener for PDF download if (downloadPdfButton) { downloadPdfButton.addEventListener('click', () => { // Corrected from ()_ const { jsPDF } = window.jspdf; const reportContent = document.getElementById('pdfReportContent'); if (!reportContent) { console.error("PDF report content area not found."); // Optionally, show a user-facing error message here // alert("Could not generate PDF: Report content missing."); // Avoid alert() const overallAssessmentEl = document.getElementById('overallAssessment'); if(overallAssessmentEl) { const p = document.createElement('p'); p.textContent = "Error: Could not generate PDF: Report content missing."; p.className = "error-message text-center"; overallAssessmentEl.appendChild(p); setTimeout(() => p.remove(), 5000); } return; } // Temporarily ensure all text is dark for PDF generation const originalColors = []; reportContent.querySelectorAll('*').forEach(el => { originalColors.push({el, color: el.style.color}); // el.style.color = '#000000'; // Force black for better PDF readability - Handled by CSS }); html2canvas(reportContent, { scale: 2, // Increase scale for better quality useCORS: true, // If you have any external images (though not in this example) onclone: (document) => { // This onclone function is crucial for applying PDF-specific styles // or ensuring all elements are rendered correctly. } }).then(canvas => { const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = pdf.internal.pageSize.getHeight(); const canvasWidth = canvas.width; const canvasHeight = canvas.height; const ratio = canvasWidth / canvasHeight; let imgWidth = pdfWidth - 20; // With 10mm margin on each side let imgHeight = imgWidth / ratio; if (imgHeight > pdfHeight - 20) { // Check if it exceeds page height with margin imgHeight = pdfHeight - 20; imgWidth = imgHeight * ratio; } const x = (pdfWidth - imgWidth) / 2; const y = 10; // 10mm margin from top pdf.addImage(imgData, 'PNG', x, y, imgWidth, imgHeight); const cryptoNameVal = document.getElementById('cryptoName')?.value.trim() || "crypto_assessment"; pdf.save(`${cryptoNameVal.replace(/\s+/g, '_')}_liquidity_report.pdf`); // Restore original colors - important for consistent UI after PDF generation originalColors.forEach(item => item.el.style.color = item.color); }).catch(error => { console.error("Error generating PDF: ", error); // alert("An error occurred while generating the PDF. Please try again."); // Avoid alert() const overallAssessmentEl = document.getElementById('overallAssessment'); if(overallAssessmentEl) { const p = document.createElement('p'); p.textContent = "Error: An error occurred while generating the PDF. Please try again."; p.className = "error-message text-center"; overallAssessmentEl.appendChild(p); setTimeout(() => p.remove(), 5000); } // Restore original colors even on error originalColors.forEach(item => item.el.style.color = item.color); }); }); } // Initialize navigation buttons state updateNavigationButtons(); });