mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-11-27 03:06:24 -05:00
feat(gui): Switch to up-to-date asb, if current one is outdated (#189)
This commit is contained in:
parent
ba0b7ac893
commit
aa81f3c588
3 changed files with 40 additions and 34 deletions
|
|
@ -11,7 +11,7 @@ export function providerToConcatenatedMultiAddr(provider: Provider) {
|
|||
.toString();
|
||||
}
|
||||
|
||||
export function isProviderCompatible(
|
||||
export function isProviderOnCorrectNetwork(
|
||||
provider: ExtendedProviderStatus,
|
||||
): boolean {
|
||||
return provider.testnet === isTestnet();
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
import { ExtendedProviderStatus } from "models/apiModel";
|
||||
import { isProviderCompatible, isProviderOutdated } from "./multiAddrUtils";
|
||||
import { isProviderOnCorrectNetwork, isProviderOutdated } from "./multiAddrUtils";
|
||||
|
||||
export function sortProviderList(list: ExtendedProviderStatus[]) {
|
||||
return list
|
||||
.filter(isProviderCompatible)
|
||||
// Filter out providers that are on the wrong network (testnet / mainnet)
|
||||
.filter(isProviderOnCorrectNetwork)
|
||||
.concat()
|
||||
// Sort by criteria
|
||||
.sort((firstEl, secondEl) => {
|
||||
// If either provider is outdated, prioritize the one that isn't
|
||||
if (isProviderOutdated(firstEl) && !isProviderOutdated(secondEl)) return 1;
|
||||
|
|
@ -24,5 +26,9 @@ export function sortProviderList(list: ExtendedProviderStatus[]) {
|
|||
return -1;
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
})
|
||||
// Remove duplicate providers
|
||||
.filter((provider, index, self) =>
|
||||
index === self.findIndex((p) => p.peerId === provider.peerId)
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue