mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-12-21 11:25:50 -05:00
feat: cargo project at root
This commit is contained in:
parent
aa0c0623ca
commit
709a2820c4
313 changed files with 1 additions and 740 deletions
56
src-gui/src/store/hooks.ts
Normal file
56
src-gui/src/store/hooks.ts
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import { TypedUseSelectorHook, useDispatch, useSelector } from 'react-redux';
|
||||
import type { AppDispatch, RootState } from 'renderer/store/storeRenderer';
|
||||
import { sortBy } from 'lodash';
|
||||
import { parseDateString } from 'utils/parseUtils';
|
||||
|
||||
// Use throughout your app instead of plain `useDispatch` and `useSelector`
|
||||
export const useAppDispatch = () => useDispatch<AppDispatch>();
|
||||
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;
|
||||
|
||||
export function useResumeableSwapsCount() {
|
||||
return useAppSelector(
|
||||
(state) =>
|
||||
Object.values(state.rpc.state.swapInfos).filter(
|
||||
(swapInfo) => !swapInfo.completed,
|
||||
).length,
|
||||
);
|
||||
}
|
||||
|
||||
export function useIsSwapRunning() {
|
||||
return useAppSelector((state) => state.swap.state !== null);
|
||||
}
|
||||
|
||||
export function useSwapInfo(swapId: string | null) {
|
||||
return useAppSelector((state) =>
|
||||
swapId ? state.rpc.state.swapInfos[swapId] ?? null : null,
|
||||
);
|
||||
}
|
||||
|
||||
export function useActiveSwapId() {
|
||||
return useAppSelector((s) => s.swap.swapId);
|
||||
}
|
||||
|
||||
export function useActiveSwapInfo() {
|
||||
const swapId = useActiveSwapId();
|
||||
return useSwapInfo(swapId);
|
||||
}
|
||||
|
||||
export function useIsRpcEndpointBusy(method: string) {
|
||||
return useAppSelector((state) => state.rpc.busyEndpoints.includes(method));
|
||||
}
|
||||
|
||||
export function useAllProviders() {
|
||||
return useAppSelector((state) => {
|
||||
const registryProviders = state.providers.registry.providers || [];
|
||||
const listSellersProviders = state.providers.rendezvous.providers || [];
|
||||
return [...registryProviders, ...listSellersProviders];
|
||||
});
|
||||
}
|
||||
|
||||
export function useSwapInfosSortedByDate() {
|
||||
const swapInfos = useAppSelector((state) => state.rpc.state.swapInfos);
|
||||
return sortBy(
|
||||
Object.values(swapInfos),
|
||||
(swap) => -parseDateString(swap.startDate),
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue