DeFi Risk & Reward Analyzer (Self-Assessment)
A framework to guide your research and subjective assessment of a DeFi opportunity.
Important: DeFi is high-risk. This tool is for educational and self-assessment purposes ONLY. Data is user-inputted, and APY/APRs change rapidly. This tool does NOT provide investment advice or endorse any platform. Scores are based on YOUR ratings. Always Do Your Own Research (DYOR) and consult a financial advisor.
High Concern: ${riskSummary.HighConcern} | Medium Concern: ${riskSummary.MediumConcern} | Low Concern: ${riskSummary.LowConcern} | Not Assessed: ${riskSummary.NotAssessed}
`; pdfHtml += `Overall Considerations (Based on Your Assessment)
${qualitativeFeedbackEl.innerHTML.replace(/
`;
}
pdfExportContainer.innerHTML = pdfHtml;
document.body.appendChild(pdfExportContainer);
try {
const canvas = await html2canvas(pdfExportContainer, { scale: 1.2, useCORS: true, logging: false, windowWidth: pdfExportContainer.scrollWidth, windowHeight: pdfExportContainer.scrollHeight });
document.body.removeChild(pdfExportContainer);
const imgData = canvas.toDataURL('image/png');
const { jsPDF } = window.jspdf;
const pdf = new jsPDF({ orientation: 'p', unit: 'pt', format: 'a4' });
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = pdf.internal.pageSize.getHeight();
const imgProps = pdf.getImageProperties(imgData);
let imgFinalWidth = pdfWidth - 40;
let imgFinalHeight = (imgProps.height * imgFinalWidth) / imgProps.width;
if (imgFinalHeight > pdfHeight - 40) { // Check if it exceeds one page height
// Simple approach for now: scale to fit one page width, height will be proportional
// For true multi-page from a single large canvas, more complex slicing of imgData is needed
// Or, ensure content is short enough, or accept scrolling in image if PDF viewer supports.
// Forcing it onto one page by potentially reducing scale further if too tall:
if (imgFinalHeight > pdfHeight - 40) {
imgFinalHeight = pdfHeight - 40; // Max height
imgFinalWidth = (imgProps.width * imgFinalHeight) / imgProps.height; // Adjust width to maintain aspect ratio
}
}
let position = 20;
// This simple addImage might not handle multi-page perfectly for very long content.
// For a robust multi-page for very long content, one would typically segment the HTML
// or use more advanced jsPDF features with `addHTML` (which has its own complexities)
// or split the canvas. For now, it will attempt to fit on one or more pages by scaling.
// The loop for multiple pages from previous thought block is good if image can be sliced.
// Here's a simplified version that just adds the (potentially long) image.
let currentY = position;
const pageMargin = 20;
const pageHeightAvailable = pdfHeight - 2 * pageMargin;
let heightProcessed = 0;
while(heightProcessed < imgHeight) {
let pageSegmentHeight = Math.min(imgHeight - heightProcessed, pageHeightAvailable);
// Create a temporary canvas for the segment
const segmentCanvas = document.createElement('canvas');
segmentCanvas.width = canvas.width; // Use original canvas width for source slicing
segmentCanvas.height = (pageSegmentHeight / imgHeight) * canvas.height; // Proportional height from original canvas
const sctx = segmentCanvas.getContext('2d');
// Source y, source height
sctx.drawImage(canvas, 0, (heightProcessed / imgHeight) * canvas.height, canvas.width, segmentCanvas.height, 0, 0, segmentCanvas.width, segmentCanvas.height);
const segmentImgData = segmentCanvas.toDataURL('image/png');
const segmentImgProps = pdf.getImageProperties(segmentImgData);
let segmentFinalWidth = pdfWidth - 2 * pageMargin;
let segmentFinalHeight = (segmentImgProps.height * segmentFinalWidth) / segmentImgProps.width;
// Ensure segment fits on current page (it should, as pageSegmentHeight was capped)
if(segmentFinalHeight > pageHeightAvailable) { // Should not happen if logic above is correct
segmentFinalHeight = pageHeightAvailable;
segmentFinalWidth = (segmentImgProps.width * segmentFinalHeight) / segmentImgProps.height;
}
if(heightProcessed > 0) pdf.addPage();
pdf.addImage(segmentImgData, 'PNG', pageMargin, pageMargin, segmentFinalWidth, segmentFinalHeight);
heightProcessed += pageSegmentHeight * (imgHeight / canvas.height) * (canvas.height / segmentCanvas.height); // track original image height processed
}
pdf.save('DeFi_Risk_Reward_Analysis.pdf');
} catch (error) {
console.error("Error generating PDF:", error);
alert("An error occurred while generating PDF.");
if (document.body.contains(pdfExportContainer)) document.body.removeChild(pdfExportContainer);
}
}
};
document.addEventListener('DOMContentLoaded', function() {
defiRRAApp.init();
});
