mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-07-30 10:09:04 -04:00
feat(gui): Connect to preset rendezvous nodes at startup (#162)
This commit is contained in:
parent
7ebe59bc8d
commit
163f6fa94d
5 changed files with 37 additions and 19 deletions
|
@ -11,7 +11,7 @@ export default function DaemonStatusAlert() {
|
|||
const navigate = useNavigate();
|
||||
|
||||
if (contextStatus === null) {
|
||||
return <Alert severity="info">The daemon is not running</Alert>;
|
||||
return <LoadingSpinnerAlert severity="warning">Checking for available remote nodes</LoadingSpinnerAlert>;
|
||||
}
|
||||
|
||||
switch (contextStatus.type) {
|
||||
|
|
|
@ -16,16 +16,11 @@ import { useSnackbar } from "notistack";
|
|||
import { ChangeEvent, useState } from "react";
|
||||
import TruncatedText from "renderer/components/other/TruncatedText";
|
||||
import PromiseInvokeButton from "renderer/components/PromiseInvokeButton";
|
||||
import { listSellersAtRendezvousPoint } from "renderer/rpc";
|
||||
import { listSellersAtRendezvousPoint, PRESET_RENDEZVOUS_POINTS } from "renderer/rpc";
|
||||
import { discoveredProvidersByRendezvous } from "store/features/providersSlice";
|
||||
import { useAppDispatch } from "store/hooks";
|
||||
import { isValidMultiAddressWithPeerId } from "utils/parseUtils";
|
||||
|
||||
const PRESET_RENDEZVOUS_POINTS = [
|
||||
"/dns4/discover.unstoppableswap.net/tcp/8888/p2p/12D3KooWA6cnqJpVnreBVnoro8midDL9Lpzmg8oJPoAGi7YYaamE",
|
||||
"/dns4/eratosthen.es/tcp/7798/p2p/12D3KooWAh7EXXa2ZyegzLGdjvj1W4G3EXrTGrf6trraoT1MEobs",
|
||||
];
|
||||
|
||||
const useStyles = makeStyles((theme: Theme) => ({
|
||||
chipOuter: {
|
||||
display: "flex",
|
||||
|
|
|
@ -48,6 +48,21 @@ import logger from "utils/logger";
|
|||
import { getNetwork, getNetworkName, isTestnet } from "store/config";
|
||||
import { Blockchain } from "store/features/settingsSlice";
|
||||
import { setStatus } from "store/features/nodesSlice";
|
||||
import { discoveredProvidersByRendezvous } from "store/features/providersSlice";
|
||||
|
||||
export const PRESET_RENDEZVOUS_POINTS = [
|
||||
"/dns4/discover.unstoppableswap.net/tcp/8888/p2p/12D3KooWA6cnqJpVnreBVnoro8midDL9Lpzmg8oJPoAGi7YYaamE",
|
||||
];
|
||||
|
||||
export async function fetchSellersAtPresetRendezvousPoints() {
|
||||
await Promise.all(PRESET_RENDEZVOUS_POINTS.map(async (rendezvousPoint) => {
|
||||
const response = await listSellersAtRendezvousPoint(rendezvousPoint);
|
||||
store.dispatch(discoveredProvidersByRendezvous(response.sellers));
|
||||
|
||||
console.log(`Discovered ${response.sellers.length} sellers at rendezvous point ${rendezvousPoint} during startup fetch`);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export async function initEventListeners() {
|
||||
// This operation is in-expensive
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { createListenerMiddleware } from "@reduxjs/toolkit";
|
||||
import { getAllSwapInfos, checkBitcoinBalance, updateAllNodeStatuses } from "renderer/rpc";
|
||||
import { getAllSwapInfos, checkBitcoinBalance, updateAllNodeStatuses, fetchSellersAtPresetRendezvousPoints } from "renderer/rpc";
|
||||
import logger from "utils/logger";
|
||||
import { contextStatusEventReceived } from "store/features/rpcSlice";
|
||||
import { addNode, setFetchFiatPrices, setFiatCurrency } from "store/features/settingsSlice";
|
||||
|
@ -10,7 +10,7 @@ export function createMainListeners() {
|
|||
const listener = createListenerMiddleware();
|
||||
|
||||
// Listener for when the Context becomes available
|
||||
// When the context becomes available, we check the bitcoin balance and fetch all swap infos
|
||||
// When the context becomes available, we check the bitcoin balance, fetch all swap infos and connect to the rendezvous point
|
||||
listener.startListening({
|
||||
actionCreator: contextStatusEventReceived,
|
||||
effect: async (action) => {
|
||||
|
@ -21,8 +21,11 @@ export function createMainListeners() {
|
|||
logger.debug(
|
||||
"Context is available, checking bitcoin balance and history",
|
||||
);
|
||||
await checkBitcoinBalance();
|
||||
await getAllSwapInfos();
|
||||
await Promise.allSettled([
|
||||
checkBitcoinBalance(),
|
||||
getAllSwapInfos(),
|
||||
fetchSellersAtPresetRendezvousPoints(),
|
||||
]);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue