From 42955af42ce86752f1bedee22bbb083a6dbeb4cb Mon Sep 17 00:00:00 2001 From: gerlofvanek Date: Fri, 29 Nov 2024 16:17:45 +0100 Subject: [PATCH] ui: Update logic of "New Address" --- basicswap/templates/offer.html | 18 ++---------- basicswap/templates/offer_new_1.html | 44 ++-------------------------- 2 files changed, 5 insertions(+), 57 deletions(-) diff --git a/basicswap/templates/offer.html b/basicswap/templates/offer.html index fdb7363..a5e29b6 100644 --- a/basicswap/templates/offer.html +++ b/basicswap/templates/offer.html @@ -432,19 +432,10 @@ function handleBidsPageAddress() { function loadInitialAddress() { const savedAddressJSON = localStorage.getItem(STORAGE_KEY); - if (savedAddressJSON) { try { const savedAddress = JSON.parse(savedAddressJSON); - const optionExists = Array.from(selectElement.options).some( - option => option.value === savedAddress.value - ); - - if (optionExists) { - selectElement.value = savedAddress.value; - } else { - selectFirstAddress(); - } + selectElement.value = savedAddress.value; } catch (e) { selectFirstAddress(); } @@ -472,12 +463,7 @@ function handleBidsPageAddress() { } selectElement.addEventListener('change', (event) => { - const selectedValue = event.target.value; - const selectedText = event.target.selectedOptions[0].text; - - if (selectedValue !== '-1') { - saveAddress(selectedValue, selectedText); - } + saveAddress(event.target.value, event.target.selectedOptions[0].text); }); loadInitialAddress(); diff --git a/basicswap/templates/offer_new_1.html b/basicswap/templates/offer_new_1.html index 4f9cee0..00a5464 100644 --- a/basicswap/templates/offer_new_1.html +++ b/basicswap/templates/offer_new_1.html @@ -127,19 +127,10 @@ function handleNewOfferAddress() { function loadInitialAddress() { const savedAddressJSON = localStorage.getItem(STORAGE_KEY); - if (savedAddressJSON) { try { const savedAddress = JSON.parse(savedAddressJSON); - const optionExists = Array.from(selectElement.options).some( - option => option.value === savedAddress.value - ); - - if (optionExists) { - selectElement.value = savedAddress.value; - } else { - selectFirstAddress(); - } + selectElement.value = savedAddress.value; } catch (e) { selectFirstAddress(); } @@ -167,40 +158,11 @@ function handleNewOfferAddress() { } form.addEventListener('submit', async (e) => { - if (selectElement.value === '-1') { - e.preventDefault(); - - try { - const formData = new FormData(form); - const response = await fetch(form.action, { - method: form.method, - body: formData - }); - - if (response.ok) { - setTimeout(() => { - const newAddress = selectElement.options[1]; - if (newAddress) { - selectElement.value = newAddress.value; - saveAddress(newAddress.value, newAddress.text); - } - form.submit(); - }, 100); - } - } catch (error) { - console.error('Error submitting form:', error); - form.submit(); - } - } + saveAddress(selectElement.value, selectElement.selectedOptions[0].text); }); selectElement.addEventListener('change', (event) => { - const selectedValue = event.target.value; - const selectedText = event.target.selectedOptions[0].text; - - if (selectedValue !== '-1') { - saveAddress(selectedValue, selectedText); - } + saveAddress(event.target.value, event.target.selectedOptions[0].text); }); loadInitialAddress();