mirror of
https://github.com/basicswap/basicswap.git
synced 2025-01-18 08:34:32 +00:00
ui: Update logic of "New Address"
This commit is contained in:
parent
cf92c5635d
commit
42955af42c
2 changed files with 5 additions and 57 deletions
|
@ -432,19 +432,10 @@ function handleBidsPageAddress() {
|
||||||
|
|
||||||
function loadInitialAddress() {
|
function loadInitialAddress() {
|
||||||
const savedAddressJSON = localStorage.getItem(STORAGE_KEY);
|
const savedAddressJSON = localStorage.getItem(STORAGE_KEY);
|
||||||
|
|
||||||
if (savedAddressJSON) {
|
if (savedAddressJSON) {
|
||||||
try {
|
try {
|
||||||
const savedAddress = JSON.parse(savedAddressJSON);
|
const savedAddress = JSON.parse(savedAddressJSON);
|
||||||
const optionExists = Array.from(selectElement.options).some(
|
selectElement.value = savedAddress.value;
|
||||||
option => option.value === savedAddress.value
|
|
||||||
);
|
|
||||||
|
|
||||||
if (optionExists) {
|
|
||||||
selectElement.value = savedAddress.value;
|
|
||||||
} else {
|
|
||||||
selectFirstAddress();
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
selectFirstAddress();
|
selectFirstAddress();
|
||||||
}
|
}
|
||||||
|
@ -472,12 +463,7 @@ function handleBidsPageAddress() {
|
||||||
}
|
}
|
||||||
|
|
||||||
selectElement.addEventListener('change', (event) => {
|
selectElement.addEventListener('change', (event) => {
|
||||||
const selectedValue = event.target.value;
|
saveAddress(event.target.value, event.target.selectedOptions[0].text);
|
||||||
const selectedText = event.target.selectedOptions[0].text;
|
|
||||||
|
|
||||||
if (selectedValue !== '-1') {
|
|
||||||
saveAddress(selectedValue, selectedText);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
loadInitialAddress();
|
loadInitialAddress();
|
||||||
|
|
|
@ -127,19 +127,10 @@ function handleNewOfferAddress() {
|
||||||
|
|
||||||
function loadInitialAddress() {
|
function loadInitialAddress() {
|
||||||
const savedAddressJSON = localStorage.getItem(STORAGE_KEY);
|
const savedAddressJSON = localStorage.getItem(STORAGE_KEY);
|
||||||
|
|
||||||
if (savedAddressJSON) {
|
if (savedAddressJSON) {
|
||||||
try {
|
try {
|
||||||
const savedAddress = JSON.parse(savedAddressJSON);
|
const savedAddress = JSON.parse(savedAddressJSON);
|
||||||
const optionExists = Array.from(selectElement.options).some(
|
selectElement.value = savedAddress.value;
|
||||||
option => option.value === savedAddress.value
|
|
||||||
);
|
|
||||||
|
|
||||||
if (optionExists) {
|
|
||||||
selectElement.value = savedAddress.value;
|
|
||||||
} else {
|
|
||||||
selectFirstAddress();
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
selectFirstAddress();
|
selectFirstAddress();
|
||||||
}
|
}
|
||||||
|
@ -167,40 +158,11 @@ function handleNewOfferAddress() {
|
||||||
}
|
}
|
||||||
|
|
||||||
form.addEventListener('submit', async (e) => {
|
form.addEventListener('submit', async (e) => {
|
||||||
if (selectElement.value === '-1') {
|
saveAddress(selectElement.value, selectElement.selectedOptions[0].text);
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
selectElement.addEventListener('change', (event) => {
|
selectElement.addEventListener('change', (event) => {
|
||||||
const selectedValue = event.target.value;
|
saveAddress(event.target.value, event.target.selectedOptions[0].text);
|
||||||
const selectedText = event.target.selectedOptions[0].text;
|
|
||||||
|
|
||||||
if (selectedValue !== '-1') {
|
|
||||||
saveAddress(selectedValue, selectedText);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
loadInitialAddress();
|
loadInitialAddress();
|
||||||
|
|
Loading…
Reference in a new issue