Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: sort confirmations upon saving configuration #594

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions internal/adapters/entrypoints/rest/assets/static/management.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ document.addEventListener('DOMContentLoaded', () => {
const entriesContainer = document.createElement('div');
entriesContainer.classList.add('entries-container');

Object.entries(confirmations).forEach(([amountWei, confirmation], index) => {
const sortedEntries = Object.entries(confirmations).sort(([amountWeiA], [amountWeiB]) => {
const amountA = new Decimal(weiToEther(amountWeiA));
const amountB = new Decimal(weiToEther(amountWeiB));
return amountA.minus(amountB).toNumber();
});
sortedEntries.forEach(([amountWei, confirmation], index) => {
createConfirmationEntry(entriesContainer, configKey, index, amountWei, confirmation);
});

Expand Down Expand Up @@ -367,7 +372,37 @@ document.addEventListener('DOMContentLoaded', () => {
}
}

if (saveSuccess) showSuccessToast();
if (saveSuccess) {
showSuccessToast();
sortConfirmationEntries();
}
};

const sortConfirmationEntries = () => {
const confirmationConfigs = document.querySelectorAll('.confirmation-config');
confirmationConfigs.forEach(container => {
const entriesContainer = container.querySelector('.entries-container');
const entries = Array.from(entriesContainer.children);

entries.sort((a, b) => {
const amountA = getAmountFromEntry(a);
const amountB = getAmountFromEntry(b);
return amountA.minus(amountB).toNumber();
});

entriesContainer.innerHTML = '';
entries.forEach(entry => entriesContainer.appendChild(entry));
});
};

const getAmountFromEntry = (entry) => {
const amountInput = entry.querySelector('input[data-field="amount"]');
const amountValue = amountInput.value;
try {
return new Decimal(amountValue);
} catch (error) {
return new Decimal(0);
}
};

const addCollateral = async (amountId, endpoint, elementId, loadingBarId, buttonId) => {
Expand Down
Loading