mirror of
https://github.com/basicswap/basicswap.git
synced 2024-12-22 11:39:34 +00:00
Merge pull request #180 from gerlofvanek/offer-2
Some checks failed
ci / ci (3.12) (push) Has been cancelled
Some checks failed
ci / ci (3.12) (push) Has been cancelled
ui: Update logic of "New Address"
This commit is contained in:
commit
6f61c7d26d
2 changed files with 5 additions and 57 deletions
|
@ -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();
|
||||
}
|
||||
} 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();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
} 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();
|
||||
|
|
Loading…
Reference in a new issue