-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.js
More file actions
137 lines (115 loc) · 4.65 KB
/
Copy pathui.js
File metadata and controls
137 lines (115 loc) · 4.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// UI update functions
window.updateSummary = function(migrationStakers, quickStakers, monthlyStakers, currentSupply) {
const monthlyTotal = monthlyStakers.reduce((sum, staker) => sum + staker.amount, 0);
const monthlyRewards = monthlyStakers.reduce((sum, staker) => sum + staker.totalRewards, 0);
// Update total supply information
const initialSupply = window.getInputValues().initialSupply;
const supplyGrowth = ((currentSupply - initialSupply) / initialSupply * 100).toFixed(2);
updateSupplyInfo(currentSupply, supplyGrowth);
updateInflationInfo();
updateCohortInfo(migrationStakers, quickStakers, monthlyTotal, monthlyRewards, currentSupply);
updateTotalInfo(migrationStakers, quickStakers, monthlyTotal, monthlyRewards, currentSupply);
};
function updateSupplyInfo(currentSupply, supplyGrowth) {
document.getElementById('totalSupplyValue').textContent =
`${formatNumber(currentSupply)} EFX`;
document.getElementById('totalSupplyGrowth').textContent =
`+${supplyGrowth}% from initial supply`;
}
function updateInflationInfo() {
const currentMonth = window.simulationData.length - 1;
const currentData = window.simulationData[currentMonth];
if (currentMonth >= 12) {
const annualInflation = currentData.annualInflation;
const previousMonth = window.simulationData[currentMonth - 1];
const monthlyInflation = calculateInflation(
currentData.currentSupply,
previousMonth.currentSupply
);
document.getElementById('annualInflationValue').textContent =
`${formatPercentage(annualInflation)}`;
document.getElementById('monthlyInflationValue').textContent =
`${formatPercentage(monthlyInflation)} monthly rate`;
} else {
document.getElementById('annualInflationValue').textContent = 'Calculating...';
document.getElementById('monthlyInflationValue').textContent =
'Need 12 months of data';
}
}
function updateCohortInfo(migrationStakers, quickStakers, monthlyTotal, monthlyRewards, currentSupply) {
// Migration cohort
updateSummaryElement('migrationTotal',
migrationStakers.amount,
currentSupply
);
updateSummaryElement('migrationRewards',
migrationStakers.totalRewards
);
// Quick stakers
updateSummaryElement('quickTotal',
quickStakers.amount,
currentSupply
);
updateSummaryElement('quickRewards',
quickStakers.totalRewards
);
// Monthly stakers
updateSummaryElement('monthlyTotal',
monthlyTotal,
currentSupply
);
updateSummaryElement('monthlyRewards',
monthlyRewards
);
}
function updateTotalInfo(migrationStakers, quickStakers, monthlyTotal, monthlyRewards, currentSupply) {
const totalStaked = migrationStakers.amount + quickStakers.amount + monthlyTotal;
const totalRewards = migrationStakers.totalRewards + quickStakers.totalRewards + monthlyRewards;
updateSummaryElement('totalStaked',
totalStaked,
currentSupply
);
updateSummaryElement('totalRewards',
totalRewards
);
}
window.updateSummaryElement = function(elementId, amount, supply = null) {
const element = document.getElementById(elementId);
if (!element) return;
if (supply) {
const percentage = (amount / supply) * 100;
element.textContent = `${formatNumber(amount)} EFX (${formatPercentage(percentage)})`;
} else {
element.textContent = `+${formatNumber(amount)} EFX Rewards`;
}
};
// Error handling
window.handleError = function(error) {
console.error('Simulation error:', error);
alert('An error occurred during simulation. Please check the console for details.');
};
// Input validation
window.validateInputs = function() {
const inputs = getInputValues();
if (inputs.baseApy < 0 || inputs.bonusApy < 0) {
throw new Error('APY values cannot be negative');
}
if (inputs.initialSupply <= 0) {
throw new Error('Initial supply must be greater than 0');
}
const totalInitialStake = inputs.migrationStake + inputs.quickStake;
if (totalInitialStake > 100) {
throw new Error('Total initial stake cannot exceed 100%');
}
if (inputs.monthlyNewStake < 0) {
throw new Error('Monthly new stake cannot be negative');
}
return inputs;
};
// Initialize the UI
window.initializeUI = function() {
document.getElementById('exportBtn').disabled = true;
document.getElementById('summaryContainer').style.display = 'none';
};
// Add event listener for page load
window.addEventListener('load', initializeUI);