Skip to content

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-babylonlabs committed Nov 29, 2024
1 parent 7dbff67 commit c115f28
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 274 deletions.
34 changes: 24 additions & 10 deletions src/app/api/getFinalityProviders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { encode } from "url-safe-base64";
import { isValidUrl } from "@/utils/url";

import { Pagination } from "../types/api";
import { FinalityProvider } from "../types/finalityProviders";
import {
FinalityProvider,
FinalityProviderState,
} from "../types/finalityProviders";

import { apiWrapper } from "./apiWrapper";

Expand All @@ -19,6 +22,7 @@ interface FinalityProvidersAPIResponse {

interface FinalityProviderAPI {
description: DescriptionAPI;
state: FinalityProviderState;
commission: string;
btc_pk: string;
active_tvl: number;
Expand All @@ -35,21 +39,30 @@ interface DescriptionAPI {
details: string;
}

export const getFinalityProviders = async (
key: string,
): Promise<PaginatedFinalityProviders> => {
// const limit = 100;
// const reverse = false;

export const getFinalityProviders = async ({
key,
pk,
sortBy,
order,
name,
}: {
key: string;
name?: string;
sortBy?: string;
order?: "asc" | "desc";
pk?: string;
}): Promise<PaginatedFinalityProviders> => {
const params = {
pagination_key: encode(key),
// "pagination_reverse": reverse,
// "pagination_limit": limit,
finality_provider_pk: pk,
sort_by: sortBy,
order,
name,
};

const response = await apiWrapper(
"GET",
"/v1/finality-providers",
"/v2/finality-providers",
"Error getting finality providers",
params,
);
Expand All @@ -70,6 +83,7 @@ export const getFinalityProviders = async (
securityContact: fp.description.security_contact,
details: fp.description.details,
},
state: fp.state,
commission: fp.commission,
btcPk: fp.btc_pk,
activeTVLSat: fp.active_tvl,
Expand Down
106 changes: 0 additions & 106 deletions src/app/api/getFinalityProvidersV2.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/app/components/Delegations/Delegation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FaBitcoin } from "react-icons/fa";
import { IoIosWarning } from "react-icons/io";
import { Tooltip } from "react-tooltip";

import { useFinalityProviderV2Service } from "@/app/hooks/services/useFinalityProviderV2Service";
import { useFinalityProviderService } from "@/app/hooks/services/useFinalityProviderService";
import {
type SigningStep,
useTransactionService,
Expand Down Expand Up @@ -48,7 +48,7 @@ export const Delegation: React.FC<DelegationProps> = ({
const [currentTime, setCurrentTime] = useState(Date.now());
const { isApiNormal, isGeoBlocked } = useHealthCheck();
const { transitionPhase1Delegation } = useTransactionService();
const { getFinalityProviderMoniker } = useFinalityProviderV2Service(); // get the moniker of the finality provider
const { getFinalityProviderMoniker } = useFinalityProviderService(); // get the moniker of the finality provider
useEffect(() => {
const timerId = setInterval(() => {
setCurrentTime(Date.now());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
LoadingTableList,
LoadingView,
} from "@/app/components/Loading/Loading";
import { useFinalityProviderV2Service } from "@/app/hooks/services/useFinalityProviderV2Service";
import type { FinalityProviderV2 as FinalityProviderInterface } from "@/app/types/finalityProviders";
import { useFinalityProviderService } from "@/app/hooks/services/useFinalityProviderService";
import type { FinalityProvider as FinalityProviderInterface } from "@/app/types/finalityProviders";

import { FinalityProvider } from "./FinalityProvider";
import { FinalityProviderSearch } from "./FinalityProviderSearch";
Expand All @@ -30,7 +30,7 @@ export const FinalityProviders: React.FC<FinalityProvidersProps> = ({
fetchNextPage,
handleSearch,
handleSort,
} = useFinalityProviderV2Service();
} = useFinalityProviderService();

useEffect(() => {
if (finalityProviders) {
Expand Down
6 changes: 3 additions & 3 deletions src/app/components/Staking/Staking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import { useHealthCheck } from "@/app/hooks/useHealthCheck";
import { useAppState } from "@/app/state";
import { ErrorHandlerParam, ErrorState } from "@/app/types/errors";
import {
FinalityProviderV2 as FinalityProviderInterface,
FinalityProviderV2,
FinalityProvider,
FinalityProvider as FinalityProviderInterface,
} from "@/app/types/finalityProviders";
import { getFeeRateFromMempool } from "@/utils/getFeeRateFromMempool";
import { isStakingSignReady } from "@/utils/isStakingSignReady";
Expand Down Expand Up @@ -58,7 +58,7 @@ export const Staking = () => {
const [finalityProvider, setFinalityProvider] =
useState<FinalityProviderInterface>();
const [finalityProviders, setFinalityProviders] =
useState<FinalityProviderV2[]>();
useState<FinalityProvider[]>();
// Selected fee rate, comes from the user input
const [selectedFeeRate, setSelectedFeeRate] = useState(0);
const [awaitingWalletResponse, setAwaitingWalletResponse] = useState(false);
Expand Down
53 changes: 0 additions & 53 deletions src/app/hooks/api/useFinalityProviders.ts

This file was deleted.

19 changes: 7 additions & 12 deletions src/app/hooks/api/useFinalityProvidersV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { useInfiniteQuery } from "@tanstack/react-query";
import { useEffect } from "react";

import {
type PaginatedFinalityProvidersV2,
getFinalityProvidersV2,
} from "@/app/api/getFinalityProvidersV2";
type PaginatedFinalityProviders,
getFinalityProviders,
} from "@/app/api/getFinalityProviders";
import { ONE_MINUTE } from "@/app/constants";
import { useError } from "@/app/context/Error/ErrorContext";
import { ErrorState } from "@/app/types/errors";
Expand All @@ -18,18 +18,13 @@ interface Params {
order?: "asc" | "desc";
}

export function useFinalityProvidersV2({
pk,
sortBy,
order,
name,
}: Params = {}) {
export function useFinalityProviders({ pk, sortBy, order, name }: Params = {}) {
const { isErrorOpen, handleError } = useError();

const query = useInfiniteQuery({
queryKey: [FINALITY_PROVIDERS_KEY, pk, name, sortBy, order],
queryKey: [FINALITY_PROVIDERS_KEY],
queryFn: ({ pageParam = "" }) =>
getFinalityProvidersV2({ key: pageParam, pk, sortBy, order, name }),
getFinalityProviders({ key: pageParam, pk, sortBy, order, name }),
getNextPageParam: (lastPage) =>
lastPage?.pagination?.next_key !== ""
? lastPage?.pagination?.next_key
Expand All @@ -38,7 +33,7 @@ export function useFinalityProvidersV2({
refetchInterval: ONE_MINUTE,
placeholderData: (prev) => prev,
select: (data) => {
const flattenedData = data.pages.reduce<PaginatedFinalityProvidersV2>(
const flattenedData = data.pages.reduce<PaginatedFinalityProviders>(
(acc, page) => {
acc.finalityProviders.push(...page.finalityProviders);
acc.pagination = page.pagination;
Expand Down
Loading

0 comments on commit c115f28

Please sign in to comment.