Spaces:
Running
Running
Update index.html
Browse files- index.html +126 -0
index.html
CHANGED
@@ -805,6 +805,132 @@
|
|
805 |
calculateTrancheOffer(tranche);
|
806 |
});
|
807 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
808 |
|
809 |
// Function to update tranche pool information
|
810 |
function updateTranchePoolInfo() {
|
|
|
805 |
calculateTrancheOffer(tranche);
|
806 |
});
|
807 |
});
|
808 |
+
// Submit offer buttons
|
809 |
+
const submitOfferBtns = document.querySelectorAll('.submit-offer');
|
810 |
+
|
811 |
+
submitOfferBtns.forEach(btn => {
|
812 |
+
btn.addEventListener('click', function() {
|
813 |
+
const tranche = this.dataset.tranche;
|
814 |
+
const trancheName = {
|
815 |
+
'a': 'Tranche A (Senior)',
|
816 |
+
'b': 'Tranche B (Mezzanine)',
|
817 |
+
'c': 'Tranche C (B-Piece)'
|
818 |
+
}[tranche];
|
819 |
+
|
820 |
+
const liabilities = parseFloat(document.getElementById(`liabilities-${tranche}`).value) || 0;
|
821 |
+
const contribution = parseFloat(document.getElementById(`contribution-${tranche}`).value) || 0;
|
822 |
+
|
823 |
+
if (liabilities <= 0 || contribution <= 0) {
|
824 |
+
alert('Please enter valid values for liabilities and contribution');
|
825 |
+
return;
|
826 |
+
}
|
827 |
+
|
828 |
+
// Update tranche data with new investment
|
829 |
+
trancheData[tranche].assets += contribution;
|
830 |
+
trancheData[tranche].liquidity += contribution * 0.9; // Assuming 90% goes to liquidity
|
831 |
+
|
832 |
+
// Update the pool information display
|
833 |
+
updateTranchePoolInfo();
|
834 |
+
|
835 |
+
// Show success message
|
836 |
+
successMessage.classList.remove('hidden');
|
837 |
+
setTimeout(() => {
|
838 |
+
successMessage.classList.add('hidden');
|
839 |
+
}, 3000);
|
840 |
+
|
841 |
+
// Reset form
|
842 |
+
document.getElementById(`liabilities-${tranche}`).value = '';
|
843 |
+
document.getElementById(`contribution-${tranche}`).value = '';
|
844 |
+
|
845 |
+
// Recalculate
|
846 |
+
calculateTrancheOffer(tranche);
|
847 |
+
});
|
848 |
+
});
|
849 |
+
// Submit offer buttons
|
850 |
+
const submitOfferBtns = document.querySelectorAll('.submit-offer');
|
851 |
+
|
852 |
+
submitOfferBtns.forEach(btn => {
|
853 |
+
// CHANGE THIS LINE: Make the function async
|
854 |
+
btn.addEventListener('click', async function() {
|
855 |
+
const tranche = this.dataset.tranche;
|
856 |
+
const trancheName = {
|
857 |
+
'a': 'Tranche A (Senior)',
|
858 |
+
'b': 'Tranche B (Mezzanine)',
|
859 |
+
'c': 'Tranche C (B-Piece)'
|
860 |
+
}[tranche];
|
861 |
+
|
862 |
+
const liabilities = parseFloat(document.getElementById(`liabilities-${tranche}`).value) || 0;
|
863 |
+
const contribution = parseFloat(document.getElementById(`contribution-${tranche}`).value) || 0;
|
864 |
+
|
865 |
+
if (liabilities <= 0 || contribution <= 0) {
|
866 |
+
alert('Please enter valid values for liabilities and contribution');
|
867 |
+
return;
|
868 |
+
}
|
869 |
+
|
870 |
+
// *** ADD THESE LINES FOR THE WORKER URL AND DATA PREPARATION ***
|
871 |
+
// Replace 'YOUR_CLOUDFLARE_WORKER_URL' with the actual URL of your deployed Cloudflare Worker
|
872 |
+
// e.g., 'https://century-city-remic-api.your-subdomain.workers.dev/submit-offer'
|
873 |
+
const workerUrl = 'YOUR_CLOUDFLARE_WORKER_URL/submit-offer';
|
874 |
+
|
875 |
+
const offerData = {
|
876 |
+
tranche: tranche,
|
877 |
+
trancheName: trancheName,
|
878 |
+
liabilities: liabilities,
|
879 |
+
contribution: contribution,
|
880 |
+
// Include other calculated values if needed, for example:
|
881 |
+
tokenPrice: parseFloat(document.getElementById(`token-price-${tranche}`).textContent.replace('$', '')),
|
882 |
+
tokenAllocation: parseInt(document.getElementById(`token-allocation-${tranche}`).textContent.replace(/,/g, '')),
|
883 |
+
poolPercentage: parseFloat(document.getElementById(`pool-percentage-${tranche}`).textContent.replace('%', '')),
|
884 |
+
remicPercentage: parseFloat(document.getElementById(`remic-percentage-${tranche}`).textContent.replace('%', '')),
|
885 |
+
};
|
886 |
+
|
887 |
+
try {
|
888 |
+
const response = await fetch(workerUrl, {
|
889 |
+
method: 'POST',
|
890 |
+
headers: {
|
891 |
+
'Content-Type': 'application/json',
|
892 |
+
},
|
893 |
+
body: JSON.stringify(offerData),
|
894 |
+
});
|
895 |
+
|
896 |
+
if (response.ok) {
|
897 |
+
const result = await response.json();
|
898 |
+
console.log('Backend response:', result);
|
899 |
+
|
900 |
+
// The client-side updates (like updating trancheData and UI)
|
901 |
+
// should ideally only happen AFTER a successful backend submission.
|
902 |
+
// So, move them here:
|
903 |
+
// Update tranche data with new investment (if successful)
|
904 |
+
trancheData[tranche].assets += contribution;
|
905 |
+
trancheData[tranche].liquidity += contribution * 0.9;
|
906 |
+
updateTranchePoolInfo(); // Update frontend display
|
907 |
+
|
908 |
+
// Show success message
|
909 |
+
successMessage.classList.remove('hidden');
|
910 |
+
setTimeout(() => {
|
911 |
+
successMessage.classList.add('hidden');
|
912 |
+
}, 3000);
|
913 |
+
|
914 |
+
// Reset form
|
915 |
+
document.getElementById(`liabilities-${tranche}`).value = '';
|
916 |
+
document.getElementById(`contribution-${tranche}`).value = '';
|
917 |
+
|
918 |
+
// Recalculate (this will use the updated trancheData for display)
|
919 |
+
calculateTrancheOffer(tranche);
|
920 |
+
|
921 |
+
} else {
|
922 |
+
const errorData = await response.json();
|
923 |
+
console.error('Backend submission failed:', errorData);
|
924 |
+
alert(`Submission failed: ${errorData.message || 'Unknown error'}`);
|
925 |
+
}
|
926 |
+
} catch (error) {
|
927 |
+
console.error('Network or unexpected error:', error);
|
928 |
+
alert('An error occurred while submitting your offer. Please try again.');
|
929 |
+
}
|
930 |
+
// *** END OF ADDED LINES ***
|
931 |
+
|
932 |
+
});
|
933 |
+
});
|
934 |
|
935 |
// Function to update tranche pool information
|
936 |
function updateTranchePoolInfo() {
|