mirror of
https://github.com/basicswap/basicswap.git
synced 2024-12-22 19:49:20 +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() {
|
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(
|
|
||||||
option => option.value === savedAddress.value
|
|
||||||
);
|
|
||||||
|
|
||||||
if (optionExists) {
|
|
||||||
selectElement.value = savedAddress.value;
|
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(
|
|
||||||
option => option.value === savedAddress.value
|
|
||||||
);
|
|
||||||
|
|
||||||
if (optionExists) {
|
|
||||||
selectElement.value = savedAddress.value;
|
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