diff --git a/scripts/amm.js b/scripts/amm.js index 13c9be8..83cfbbc 100644 --- a/scripts/amm.js +++ b/scripts/amm.js @@ -47,6 +47,13 @@ const button = document.getElementById("swapButton"); const text = document.getElementById("swapText"); const loader = document.getElementById("swapLoader"); const toAmountCurrency = document.getElementById("to-currency"); +const arrowImg = document.querySelector(".card-arrow img"); +const maxButton = document.getElementById("max-button"); +const fromAmountBox = document.getElementById("from-amount"); +let handleSwitch, handleMax; +arrowImg.removeEventListener("click", handleSwitch); +maxButton.removeEventListener("click", handleMax); +fromAmountBox.removeEventListener("input", calculateConversion); const walletsConfig = [ { @@ -112,8 +119,8 @@ async function setPublicBalances() { } catch (e) { window.alert( "could not get balance for " + - wallet + - ", please check your .env file configuration" + wallet + + ", please check your .env file configuration" ); $(`#${label}Row`).text(wallet); $(`#${label}Base`).text("n/a"); @@ -125,7 +132,10 @@ async function setPublicBalances() { } function loadAndDisplay() { - setPublicBalances(); + setPublicBalances().then(() => { + maxButton.addEventListener("click", handleMax); + }); + prepareSwitchButtonClick(); } @@ -292,16 +302,13 @@ async function swapToken( } enableSwapButton(); } catch (err) { - window.alert( - "Transaction failed, check console for details." - ); + window.alert("Transaction failed, check console for details."); console.log(err); enableSwapButton(); } } -const maxButton = document.getElementById("max-button"); -maxButton.addEventListener("click", async () => { +handleMax = () => { const fromAmountBox = document.getElementById("from-amount"); const fromCurrencyDropdown = document.getElementById("from-currency"); const fromCurrency = fromCurrencyDropdown.value; @@ -327,7 +334,7 @@ maxButton.addEventListener("click", async () => { } } calculateConversion(); -}); +}; $("#swapButton").on("click", () => { if (fromAmountBox.value == 0 || isNaN(fromAmountBox.value)) { @@ -352,7 +359,6 @@ function enableSwapButton() { button.disabled = false; } -const fromAmountBox = document.getElementById("from-amount"); fromAmountBox.addEventListener("input", calculateConversion); async function calculateConversionDetails( @@ -363,32 +369,32 @@ async function calculateConversionDetails( ) { const spotPrice = isSynthIn ? await charon.calcSpotPrice( - await charon.recordBalance(), - await charon.recordBalanceSynth(), - 0 - ) + await charon.recordBalance(), + await charon.recordBalanceSynth(), + 0 + ) : await charon.calcSpotPrice( - await charon.recordBalanceSynth(), - await charon.recordBalance(), - 0 - ); + await charon.recordBalanceSynth(), + await charon.recordBalance(), + 0 + ); const expectedOut = spotPrice * inputValue; const exitFee = inputValue * ethers.utils.formatEther(await charon.fee()); const adjustedIn = inputValue - exitFee; const minAmountOut = isSynthIn ? await charon.calcSingleOutGivenIn( - await charon.recordBalance(), - await charon.recordBalanceSynth(), - ethers.utils.parseEther(adjustedIn.toFixed(18).toString()), - 0, - false - ) + await charon.recordBalance(), + await charon.recordBalanceSynth(), + ethers.utils.parseEther(adjustedIn.toFixed(18).toString()), + 0, + false + ) : await charon.calcOutGivenIn( - await charon.recordBalance(), - await charon.recordBalanceSynth(), - ethers.utils.parseEther(adjustedIn.toFixed(18).toString()), - 0 - ); + await charon.recordBalance(), + await charon.recordBalanceSynth(), + ethers.utils.parseEther(adjustedIn.toFixed(18).toString()), + 0 + ); const slippage = (minAmountOut - expectedOut) / expectedOut; try { const feeData = await provider.getFeeData(); @@ -513,13 +519,12 @@ async function calculateConversion() { function prepareSwitchButtonClick() { const fromAmountInput = document.getElementById("from-amount"); const toAmountInput = document.getElementById("to-amount"); - const arrowImg = document.querySelector(".card-arrow img"); const fromCurrencyDropdown = document.getElementById("from-currency"); const toCurrencyDropdown = document.getElementById("to-currency"); const fromCurrencyStyle = fromCurrencyDropdown.style; const toCurrencyStyle = toCurrencyDropdown.style; let temp, selectedIndex, toCurrencyOptions; - arrowImg.addEventListener("click", () => { + handleSwitch = () => { if (toAmountInput.value === "...") return; if (fromCurrencyDropdown.value == "chd") { temp = fromAmountInput.value; @@ -554,7 +559,8 @@ function prepareSwitchButtonClick() { fromCurrencyDropdown.disabled = true; } calculateConversion(); - }); + }; + arrowImg.addEventListener("click", handleSwitch); } async function fetchCryptoPrice(fromCurrency) { diff --git a/scripts/bridgeModal.js b/scripts/bridgeModal.js index 90da00c..07dc731 100644 --- a/scripts/bridgeModal.js +++ b/scripts/bridgeModal.js @@ -409,7 +409,7 @@ function getCharon(chain) { function getChainID(chain) { switch (chain) { case "sepolia": - return 5; + return 11155111; case "chiado": return 10200; case "mumbai": diff --git a/scripts/chd.js b/scripts/chd.js index 0eee87d..ff13f28 100644 --- a/scripts/chd.js +++ b/scripts/chd.js @@ -315,7 +315,7 @@ async function setData() { function getChainID(chain) { switch (chain) { case "sepolia": - return 5; + return 11155111; case "chiado": return 10200; case "mumbai": diff --git a/scripts/sendModal.js b/scripts/sendModal.js index 5609afb..6a08e4e 100644 --- a/scripts/sendModal.js +++ b/scripts/sendModal.js @@ -124,7 +124,7 @@ function readUTXOs() { function getChainID(chain) { switch (chain) { case "sepolia": - return 5; + return 11155111; case "mumbai": return 80001; case "chiado": @@ -488,7 +488,7 @@ function showLoadingAnimation() { } function getChain(_id) { switch (_id) { - case 5: + case 11155111: return "sepolia"; case 80001: return "mumbai"; @@ -505,7 +505,7 @@ function getChain(_id) { function getPrivateBalance(_id) { switch (_id) { - case 5: + case 11155111: return psVal; case 80001: return pmVal; @@ -522,7 +522,7 @@ function getPrivateBalance(_id) { function getPublicBalance(_id) { switch (_id) { - case 5: + case 11155111: return sVal; case 80001: return mVal;