Merge pull request #180 from gerlofvanek/offer-2
Some checks failed
ci / ci (3.12) (push) Has been cancelled

ui: Update logic of "New Address"
This commit is contained in:
tecnovert 2024-11-29 21:05:06 +00:00 committed by GitHub
commit 6f61c7d26d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 57 deletions

View file

@ -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();

View file

@ -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();