feat(gui): Connect to preset rendezvous nodes at startup (#162)

This commit is contained in:
binarybaron 2024-11-14 17:04:27 +01:00 committed by GitHub
parent 7ebe59bc8d
commit 163f6fa94d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 37 additions and 19 deletions

View file

@ -1,20 +1,25 @@
import { ExtendedProviderStatus } from "models/apiModel";
import { isProviderCompatible } from "./multiAddrUtils";
import { isProviderCompatible, isProviderOutdated } from "./multiAddrUtils";
export function sortProviderList(list: ExtendedProviderStatus[]) {
return list
.filter(isProviderCompatible)
.concat()
.sort((firstEl, secondEl) => {
// If neither of them have a relevancy score, sort by max swap amount
if (firstEl.relevancy === undefined && secondEl.relevancy === undefined) {
if (firstEl.maxSwapAmount > secondEl.maxSwapAmount) {
return -1;
}
// If either provider is outdated, prioritize the one that isn't
if (isProviderOutdated(firstEl) && !isProviderOutdated(secondEl)) return 1;
if (!isProviderOutdated(firstEl) && isProviderOutdated(secondEl)) return -1;
// If neither of them have a relevancy score, sort by price
if (firstEl.relevancy == null && secondEl.relevancy == null) {
return firstEl.price - secondEl.price;
}
// If only on of the two don't have a relevancy score, prioritize the one that does
if (firstEl.relevancy === undefined) return 1;
if (secondEl.relevancy === undefined) return -1;
if (firstEl.relevancy == null) return 1;
if (secondEl.relevancy == null) return -1;
// Otherwise, sort by relevancy score
if (firstEl.relevancy > secondEl.relevancy) {
return -1;
}