Skip to content

Commit

Permalink
Resetting slider values when the user changes the asset type
Browse files Browse the repository at this point in the history
Refer to #1 thread
  • Loading branch information
KnightChaser committed Jun 8, 2024
1 parent 086e27f commit aebace1
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion frontend/src/routes/exchange/centerPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
// Calculate the size and total value based on the mode
const calculateValues = () => {
if (mode === 'buy') {
// If the user is buying, the size is calculated based on the total value
// If the user is buying, the size is calculated based on the total value
totalValue = Math.floor(sliderValue * krwBalance);
size = totalValue / currentPrice;
} else {
Expand All @@ -60,6 +60,14 @@
// Switch the mode between 'buy' and 'sell'
const switchMode = (newMode) => {
mode = newMode;
resetValues();
};
// Reset the values
const resetValues = () => {
sliderValue = 0;
size = 0;
totalValue = 0;
calculateValues();
};
Expand All @@ -69,6 +77,7 @@
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
return parts.join(".");
};
// Load the TradingView widget with the selected market
function loadTradingViewWidget(market) {
const script = document.createElement('script');
Expand Down Expand Up @@ -108,6 +117,7 @@
if (selectedMarket && selectedMarket.market !== previousMarket) {
loadTradingViewWidget(selectedMarket);
previousMarket = selectedMarket.market;
resetValues();
}
});
Expand Down

0 comments on commit aebace1

Please sign in to comment.