privateuserh commited on
Commit
2c78937
·
verified ·
1 Parent(s): 43663e0

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +244 -146
index.html CHANGED
@@ -623,106 +623,7 @@
623
  </div>
624
  </div>
625
 
626
- <script>
627
- document.addEventListener('DOMContentLoaded', function() {
628
- // Initialize tranche data
629
- const trancheData = {
630
- a: {
631
- assets: 1200000,
632
- tokens: 0.3,
633
- liquidity: 1.2,
634
- distribution: 0.3
635
- },
636
- b: {
637
- assets: 8500000,
638
- tokens: 20000000,
639
- liquidity: 8.5,
640
- distribution: 20
641
- },
642
- c: {
643
- assets: 3800000,
644
- tokens: 10000000,
645
- liquidity: 3.8,
646
- distribution: 10
647
- }
648
- };
649
-
650
- // Calculator toggle functionality
651
- const calculatorBtn = document.getElementById('token-calculator-btn');
652
- const calculator = document.getElementById('token-calculator');
653
- const closeCalculator = document.getElementById('close-calculator');
654
- const successMessage = document.getElementById('success-message');
655
-
656
- calculatorBtn.addEventListener('click', function() {
657
- calculator.classList.toggle('hidden');
658
- });
659
-
660
- closeCalculator.addEventListener('click', function() {
661
- calculator.classList.add('hidden');
662
- });
663
-
664
- // Tab switching functionality
665
- const tabs = document.querySelectorAll('.tranche-tab');
666
- const contents = document.querySelectorAll('.tranche-content');
667
-
668
- tabs.forEach(tab => {
669
- tab.addEventListener('click', function() {
670
- const tranche = this.dataset.tranche;
671
-
672
- // Update active tab
673
- tabs.forEach(t => t.classList.remove('active'));
674
- this.classList.add('active');
675
-
676
- // Update active content
677
- contents.forEach(c => c.classList.remove('active'));
678
- document.getElementById(`tranche-${tranche}-calc`).classList.add('active');
679
- });
680
- });
681
-
682
- // Calculator buttons from tranche cards
683
- const trancheCalculatorBtns = document.querySelectorAll('.tranche-calculator-btn');
684
-
685
- trancheCalculatorBtns.forEach(btn => {
686
- btn.addEventListener('click', function() {
687
- const tranche = this.dataset.tranche;
688
-
689
- // Show calculator if hidden
690
- if (calculator.classList.contains('hidden')) {
691
- calculator.classList.remove('hidden');
692
- }
693
-
694
- // Switch to the correct tab
695
- tabs.forEach(t => t.classList.remove('active'));
696
- document.querySelector(`.tranche-tab[data-tranche="${tranche}"]`).classList.add('active');
697
-
698
- contents.forEach(c => c.classList.remove('active'));
699
- document.getElementById(`tranche-${tranche}-calc`).classList.add('active');
700
- });
701
- });
702
-
703
- // Calculate functions for each tranche
704
- function calculateTrancheOffer(tranche) {
705
- const assets = parseFloat(document.getElementById(`assets-${tranche}`).value) || 0;
706
- const liabilities = parseFloat(document.getElementById(`liabilities-${tranche}`).value) || 0;
707
- const tokens = parseFloat(document.getElementById(`tokens-${tranche}`).value) || 1;
708
- const contribution = parseFloat(document.getElementById(`contribution-${tranche}`).value) || 0;
709
-
710
- // Different calculation formulas based on tranche
711
- let tokenPrice, tokenAllocation, poolPercentage, remicPercentage;
712
-
713
- switch(tranche) {
714
- case 'a':
715
- // Senior tranche - lower risk, higher price
716
- tokenPrice = (assets * 0.9 - liabilities * 0.5) / tokens;
717
- tokenAllocation = contribution / tokenPrice;
718
- poolPercentage = (tokenAllocation / tokens) * 100;
719
- remicPercentage = (contribution / (assets * 1.5)) * 100;
720
- break;
721
- case 'b':
722
- // Mezzanine tranche - balanced approach
723
- tokenPrice = (assets * 0.8 - liabilities * 0.7) / tokens;
724
- tokenAllocation = contribution / tokenPrice;
725
- poolPercentage = (tokenAllocation / tokens) * 100;
726
  remicPercentage = (contribution / (assets * 1.2)) * 100;
727
  break;
728
  case 'c':
@@ -910,60 +811,257 @@
910
  successMessage.classList.remove('hidden');
911
  setTimeout(() => {
912
  successMessage.classList.add('hidden');
913
- }, 3000);
914
-
915
- // Reset form
916
- document.getElementById(`liabilities-${tranche}`).value = '';
917
- document.getElementById(`contribution-${tranche}`).value = '';
918
-
919
- // Recalculate (this will use the updated trancheData for display)
920
- calculateTrancheOffer(tranche);
921
-
922
- } else {
923
- const errorData = await response.json();
924
- console.error('Backend submission failed:', errorData);
925
- alert(`Submission failed: ${errorData.message || 'Unknown error'}`);
926
- }
927
- } catch (error) {
928
- console.error('Network or unexpected error:', error);
929
- alert('An error occurred while submitting your offer. Please try again.');
930
- }
931
- // *** END OF ADDED LINES ***
 
 
 
 
932
 
933
- });
934
- });
935
-
936
- // Function to update tranche pool information
937
- function updateTranchePoolInfo() {
938
- // Update supply and liquidity displays
939
- document.getElementById('tranche-a-supply').textContent = `${trancheData.a.tokens.toLocaleString()} Tokens`;
940
- document.getElementById('tranche-a-liquidity').textContent = `$${(trancheData.a.liquidity / 1000000).toFixed(1)}M`;
 
 
 
 
 
 
 
 
 
 
 
 
 
941
 
942
- document.getElementById('tranche-b-supply').textContent = `${(trancheData.b.tokens / 1000000).toFixed(1)}M Tokens`;
943
- document.getElementById('tranche-b-liquidity').textContent = `$${(trancheData.b.liquidity / 1000000).toFixed(1)}M`;
 
944
 
945
- document.getElementById('tranche-c-supply').textContent = `${(trancheData.c.tokens / 1000000).toFixed(1)}M Tokens`;
946
- document.getElementById('tranche-c-liquidity').textContent = `$${(trancheData.c.liquidity / 1000000).toFixed(1)}M`;
 
 
 
 
 
 
 
 
 
 
947
 
948
- // Update token distribution
949
- const total = trancheData.a.distribution + trancheData.b.distribution + trancheData.c.distribution;
950
- const aPercent = (trancheData.a.distribution / total * 100).toFixed(2);
951
- const bPercent = (trancheData.b.distribution / total * 100).toFixed(2);
952
- const cPercent = (trancheData.c.distribution / total * 100).toFixed(2);
953
 
954
- document.getElementById('dist-a').textContent = `${trancheData.a.distribution}M (${aPercent}%)`;
955
- document.getElementById('dist-b').textContent = `${trancheData.b.distribution}M (${bPercent}%)`;
956
- document.getElementById('dist-c').textContent = `${trancheData.c.distribution}M (${cPercent}%)`;
957
 
958
- // Update distribution bars
959
- document.querySelector('#tranche-a-calc .bg-blue-600').style.width = `${aPercent}%`;
960
- document.querySelector('#tranche-b-calc .bg-green-500').style.width = `${bPercent}%`;
961
- document.querySelector('#tranche-c-calc .bg-red-500').style.width = `${cPercent}%`;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
962
  }
963
 
964
- // Initial calculations
965
- ['a', 'b', 'c'].forEach(tranche => calculateTrancheOffer(tranche));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
966
  });
967
- </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
968
  <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=privateuserh/ccremic-vbeta1-06" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
969
  </html>
 
623
  </div>
624
  </div>
625
 
626
+ poolPercentage = (tokenAllocation / tokens) * 100;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
627
  remicPercentage = (contribution / (assets * 1.2)) * 100;
628
  break;
629
  case 'c':
 
811
  successMessage.classList.remove('hidden');
812
  setTimeout(() => {
813
  successMessage.classList.add('hidden');
814
+ <script>
815
+ document.addEventListener('DOMContentLoaded', function() {
816
+ // Initialize tranche data
817
+ const trancheData = {
818
+ a: {
819
+ assets: 1200000,
820
+ tokens: 0.3,
821
+ liquidity: 1.2,
822
+ distribution: 0.3
823
+ },
824
+ b: {
825
+ assets: 8500000,
826
+ tokens: 20000000,
827
+ liquidity: 8.5,
828
+ distribution: 20
829
+ },
830
+ c: {
831
+ assets: 3800000,
832
+ tokens: 10000000,
833
+ liquidity: 3.8,
834
+ distribution: 10
835
+ }
836
+ };
837
 
838
+ // Calculator toggle functionality
839
+ const calculatorBtn = document.getElementById('token-calculator-btn');
840
+ const calculator = document.getElementById('token-calculator');
841
+ const closeCalculator = document.getElementById('close-calculator');
842
+ const successMessage = document.getElementById('success-message');
843
+
844
+ calculatorBtn.addEventListener('click', function() {
845
+ calculator.classList.toggle('hidden');
846
+ });
847
+
848
+ closeCalculator.addEventListener('click', function() {
849
+ calculator.classList.add('hidden');
850
+ });
851
+
852
+ // Tab switching functionality
853
+ const tabs = document.querySelectorAll('.tranche-tab');
854
+ const contents = document.querySelectorAll('.tranche-content');
855
+
856
+ tabs.forEach(tab => {
857
+ tab.addEventListener('click', function() {
858
+ const tranche = this.dataset.tranche;
859
 
860
+ // Update active tab
861
+ tabs.forEach(t => t.classList.remove('active'));
862
+ this.classList.add('active');
863
 
864
+ // Update active content
865
+ contents.forEach(c => c.classList.remove('active'));
866
+ document.getElementById(`tranche-${tranche}-calc`).classList.add('active');
867
+ });
868
+ });
869
+
870
+ // Calculator buttons from tranche cards
871
+ const trancheCalculatorBtns = document.querySelectorAll('.tranche-calculator-btn');
872
+
873
+ trancheCalculatorBtns.forEach(btn => {
874
+ btn.addEventListener('click', function() {
875
+ const tranche = this.dataset.tranche;
876
 
877
+ // Show calculator if hidden
878
+ if (calculator.classList.contains('hidden')) {
879
+ calculator.classList.remove('hidden');
880
+ }
 
881
 
882
+ // Switch to the correct tab
883
+ tabs.forEach(t => t.classList.remove('active'));
884
+ document.querySelector(`.tranche-tab[data-tranche="${tranche}"]`).classList.add('active');
885
 
886
+ contents.forEach(c => c.classList.remove('active'));
887
+ document.getElementById(`tranche-${tranche}-calc`).classList.add('active');
888
+ });
889
+ });
890
+
891
+ // Calculate functions for each tranche
892
+ function calculateTrancheOffer(tranche) {
893
+ const assets = parseFloat(document.getElementById(`assets-${tranche}`).value) || 0;
894
+ const liabilities = parseFloat(document.getElementById(`liabilities-${tranche}`).value) || 0;
895
+ const tokens = parseFloat(document.getElementById(`tokens-${tranche}`).value) || 1;
896
+ const contribution = parseFloat(document.getElementById(`contribution-${tranche}`).value) || 0;
897
+
898
+ // Different calculation formulas based on tranche
899
+ let tokenPrice, tokenAllocation, poolPercentage, remicPercentage;
900
+
901
+ switch(tranche) {
902
+ case 'a':
903
+ // Senior tranche - lower risk, higher price
904
+ tokenPrice = (assets * 0.9 - liabilities * 0.5) / tokens;
905
+ tokenAllocation = contribution / tokenPrice;
906
+ poolPercentage = (tokenAllocation / tokens) * 100;
907
+ remicPercentage = (contribution / (assets * 1.5)) * 100;
908
+ break;
909
+ case 'b':
910
+ // Mezzanine tranche - balanced approach
911
+ tokenPrice = (assets * 0.8 - liabilities * 0.7) / tokens;
912
+ tokenAllocation = contribution / tokenPrice;
913
+ poolPercentage = (tokenAllocation / tokens) * 100;
914
+ remicPercentage = (contribution / (assets * 1.2)) * 100;
915
+ break;
916
+ case 'c':
917
+ // B-Piece tranche - higher risk, lower price
918
+ tokenPrice = (assets * 0.7 - liabilities * 0.9) / tokens;
919
+ tokenAllocation = contribution / tokenPrice;
920
+ poolPercentage = (tokenAllocation / tokens) * 100;
921
+ remicPercentage = (contribution / assets) * 100;
922
+ break;
923
  }
924
 
925
+ // Update display
926
+ document.getElementById(`token-price-${tranche}`).textContent = `$${tokenPrice.toFixed(2)}`;
927
+ document.getElementById(`token-allocation-${tranche}`).textContent = Math.round(tokenAllocation).toLocaleString();
928
+ document.getElementById(`pool-percentage-${tranche}`).textContent = `${poolPercentage.toFixed(2)}%`;
929
+ document.getElementById(`remic-percentage-${tranche}`).textContent = `${remicPercentage.toFixed(2)}%`;
930
+ }
931
+
932
+ // Set up calculate buttons
933
+ const calculateBtns = document.querySelectorAll('.calculate-btn');
934
+
935
+ calculateBtns.forEach(btn => {
936
+ btn.addEventListener('click', function() {
937
+ const tranche = this.dataset.tranche;
938
+ calculateTrancheOffer(tranche);
939
+ });
940
+ });
941
+
942
+ // Also calculate when seller inputs change
943
+ const sellerInputs = ['a', 'b', 'c'].map(t => [
944
+ `liabilities-${t}`,
945
+ `contribution-${t}`
946
+ ]).flat();
947
+
948
+ sellerInputs.forEach(id => {
949
+ document.getElementById(id).addEventListener('input', function() {
950
+ const tranche = id.split('-')[1];
951
+ calculateTrancheOffer(tranche);
952
+ });
953
+ });
954
+
955
+ // Submit offer buttons (this is the ONLY one you should have)
956
+ const submitOfferBtns = document.querySelectorAll('.submit-offer');
957
+
958
+ submitOfferBtns.forEach(btn => {
959
+ btn.addEventListener('click', async function() { // Made async for fetch
960
+ const tranche = this.dataset.tranche;
961
+ const trancheName = {
962
+ 'a': 'Tranche A (Senior)',
963
+ 'b': 'Tranche B (Mezzanine)',
964
+ 'c': 'Tranche C (B-Piece)'
965
+ }[tranche];
966
+
967
+ const liabilities = parseFloat(document.getElementById(`liabilities-${tranche}`).value) || 0;
968
+ const contribution = parseFloat(document.getElementById(`contribution-${tranche}`).value) || 0;
969
+
970
+ if (liabilities <= 0 || contribution <= 0) {
971
+ alert('Please enter valid values for liabilities and contribution');
972
+ return;
973
+ }
974
+
975
+ // IMPORTANT: Replace this with YOUR ACTUAL Cloudflare Worker URL
976
+ // Example: 'https://your-worker-name.your-username.workers.dev/submit-offer'
977
+ const workerUrl = 'https://century-city-remic-api.aiagents.workers.dev/submit-offer'; // Ensure this is your final, correct URL
978
+
979
+ const offerData = {
980
+ tranche: tranche,
981
+ trancheName: trancheName,
982
+ liabilities: liabilities,
983
+ contribution: contribution,
984
+ // Include other calculated values if needed, for example:
985
+ tokenPrice: parseFloat(document.getElementById(`token-price-${tranche}`).textContent.replace('$', '')),
986
+ tokenAllocation: parseInt(document.getElementById(`token-allocation-${tranche}`).textContent.replace(/,/g, '')),
987
+ poolPercentage: parseFloat(document.getElementById(`pool-percentage-${tranche}`).textContent.replace('%', '')),
988
+ remicPercentage: parseFloat(document.getElementById(`remic-percentage-${tranche}`).textContent.replace('%', '')),
989
+ };
990
+
991
+ try {
992
+ const response = await fetch(workerUrl, {
993
+ method: 'POST',
994
+ headers: {
995
+ 'Content-Type': 'application/json',
996
+ },
997
+ body: JSON.stringify(offerData),
998
+ });
999
+
1000
+ if (response.ok) {
1001
+ const result = await response.json();
1002
+ console.log('Backend response:', result);
1003
+
1004
+ // Update tranche data with new investment (if successful)
1005
+ trancheData[tranche].assets += contribution;
1006
+ trancheData[tranche].liquidity += contribution * 0.9;
1007
+ updateTranchePoolInfo(); // Update frontend display
1008
+
1009
+ // Show success message
1010
+ successMessage.classList.remove('hidden');
1011
+ setTimeout(() => {
1012
+ successMessage.classList.add('hidden');
1013
+ }, 3000);
1014
+
1015
+ // Reset form
1016
+ document.getElementById(`liabilities-${tranche}`).value = '';
1017
+ document.getElementById(`contribution-${tranche}`).value = '';
1018
+
1019
+ // Recalculate (this will use the updated trancheData for display)
1020
+ calculateTrancheOffer(tranche);
1021
+
1022
+ } else {
1023
+ const errorData = await response.json();
1024
+ console.error('Backend submission failed:', errorData);
1025
+ alert(`Submission failed: ${errorData.message || 'Unknown error'}`);
1026
+ }
1027
+ } catch (error) {
1028
+ console.error('Network or unexpected error:', error);
1029
+ alert('An error occurred while submitting your offer. Please try again.');
1030
+ }
1031
+ });
1032
  });
1033
+
1034
+ // Function to update tranche pool information
1035
+ function updateTranchePoolInfo() {
1036
+ // Update supply and liquidity displays
1037
+ document.getElementById('tranche-a-supply').textContent = `${trancheData.a.tokens.toLocaleString()} Tokens`;
1038
+ document.getElementById('tranche-a-liquidity').textContent = `$${(trancheData.a.liquidity / 1000000).toFixed(1)}M`;
1039
+
1040
+ document.getElementById('tranche-b-supply').textContent = `${(trancheData.b.tokens / 1000000).toFixed(1)}M Tokens`;
1041
+ document.getElementById('tranche-b-liquidity').textContent = `$${(trancheData.b.liquidity / 1000000).toFixed(1)}M`;
1042
+
1043
+ document.getElementById('tranche-c-supply').textContent = `${(trancheData.c.tokens / 1000000).toFixed(1)}M Tokens`;
1044
+ document.getElementById('tranche-c-liquidity').textContent = `$${(trancheData.c.liquidity / 1000000).toFixed(1)}M`;
1045
+
1046
+ // Update token distribution
1047
+ const total = trancheData.a.distribution + trancheData.b.distribution + trancheData.c.distribution;
1048
+ const aPercent = (trancheData.a.distribution / total * 100).toFixed(2);
1049
+ const bPercent = (trancheData.b.distribution / total * 100).toFixed(2);
1050
+ const cPercent = (trancheData.c.distribution / total * 100).toFixed(2);
1051
+
1052
+ document.getElementById('dist-a').textContent = `${trancheData.a.distribution}M (${aPercent}%)`;
1053
+ document.getElementById('dist-b').textContent = `${trancheData.b.distribution}M (${bPercent}%)`;
1054
+ document.getElementById('dist-c').textContent = `${trancheData.c.distribution}M (${cPercent}%)`;
1055
+
1056
+ // Update distribution bars
1057
+ document.querySelector('#tranche-a-calc .bg-blue-600').style.width = `${aPercent}%`;
1058
+ document.querySelector('#tranche-b-calc .bg-green-500').style.width = `${bPercent}%`;
1059
+ document.querySelector('#tranche-c-calc .bg-red-500').style.width = `${cPercent}%`;
1060
+ }
1061
+
1062
+ // Initial calculations
1063
+ ['a', 'b', 'c'].forEach(tranche => calculateTrancheOffer(tranche));
1064
+ });
1065
+ </script>
1066
  <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=privateuserh/ccremic-vbeta1-06" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
1067
  </html>