fix(gui): Strictly enforce UI types with Typescript (#678)

* fix(gui): we were not checking for null everywhere

* add more null checks, enable tsconfig strict

* remove dead code

* more nullish checks

* remove unused JSONViewTree.tsx

* fix a bunch of small typescript lints

* add explanations as to why LabeledMoneroAddress.address is non-nullish but we pass in null due to typeshare limitation

* remove @mui/lab from yarn.lock

* re-add SortableQuoteWithAddress

* add guard function for ExportBitcoinWalletResponseExt ("wallet_descriptor")

* fix remaining linter errors

* remove duplicate XMR

* fix hasUnusualAmountOfTimePassed in SwapStatusAlert.tsx
This commit is contained in:
Mohan 2025-11-05 18:38:00 +01:00 committed by GitHub
parent 3ce8e360c5
commit 5948a40c8d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
45 changed files with 312 additions and 648 deletions

View file

@ -10,48 +10,47 @@ export function sortApprovalsAndKnownQuotes(
pendingSelectMakerApprovals: PendingSelectMakerApprovalRequest[],
known_quotes: QuoteWithAddress[],
) {
const sortableQuotes = pendingSelectMakerApprovals.map((approval) => {
return {
...approval.request.content.maker,
expiration_ts:
approval.request_status.state === "Pending"
? approval.request_status.content.expiration_ts
: undefined,
request_id: approval.request_id,
} as SortableQuoteWithAddress;
});
const sortableQuotes: SortableQuoteWithAddress[] =
pendingSelectMakerApprovals.map((approval) => {
return {
quote_with_address: approval.request.content.maker,
approval:
approval.request_status.state === "Pending"
? {
request_id: approval.request_id,
expiration_ts: approval.request_status.content.expiration_ts,
}
: null,
};
});
sortableQuotes.push(
...known_quotes.map((quote) => ({
...quote,
request_id: null,
quote_with_address: quote,
approval: null,
})),
);
return sortMakerApprovals(sortableQuotes);
}
export function sortMakerApprovals(list: SortableQuoteWithAddress[]) {
return (
_(list)
_(sortableQuotes)
.orderBy(
[
// Prefer makers that have a 'version' attribute
// If we don't have a version, we cannot clarify if it's outdated or not
(m) => (m.version ? 0 : 1),
(m) => (m.quote_with_address.version ? 0 : 1),
// Prefer makers with a minimum quantity > 0
(m) => ((m.quote.min_quantity ?? 0) > 0 ? 0 : 1),
(m) => ((m.quote_with_address.quote.min_quantity ?? 0) > 0 ? 0 : 1),
// Prefer makers that are not outdated
(m) => (isMakerVersionOutdated(m.version) ? 1 : 0),
(m) => (isMakerVersionOutdated(m.quote_with_address.version) ? 1 : 0),
// Prefer approvals over actual quotes
(m) => (m.request_id ? 0 : 1),
(m) => (m.approval ? 0 : 1),
// Prefer makers with a lower price
(m) => m.quote.price,
(m) => m.quote_with_address.quote.price,
],
["asc", "asc", "asc", "asc", "asc"],
)
// Remove duplicate makers
.uniqBy((m) => m.peer_id)
.uniqBy((m) => m.quote_with_address.peer_id)
.value()
);
}