Skip to content

Commit

Permalink
fix: refetch v1 delegations after register to phase-2
Browse files Browse the repository at this point in the history
  • Loading branch information
jrwbabylonlab committed Jan 8, 2025
1 parent 77fa49c commit 5cb6360
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
2 changes: 0 additions & 2 deletions src/app/components/Delegations/Delegation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { RegistrationStartModal } from "@/app/components/Modals/RegistrationModa
import { SignModal } from "@/app/components/Modals/SignModal/SignModal";
import { ONE_MINUTE } from "@/app/constants";
import { useRegistrationService } from "@/app/hooks/services/useRegistrationService";
import { useHealthCheck } from "@/app/hooks/useHealthCheck";
import { useDelegationState } from "@/app/state/DelegationState";
import { useFinalityProviderState } from "@/app/state/FinalityProviderState";
import {
Expand Down Expand Up @@ -68,7 +67,6 @@ export const Delegation: React.FC<DelegationProps> = ({

const { startTimestamp } = stakingTx;
const [currentTime, setCurrentTime] = useState(Date.now());
const { isApiNormal, isGeoBlocked } = useHealthCheck();
const {
processing,
registrationStep: step,
Expand Down
9 changes: 8 additions & 1 deletion src/app/hooks/services/useRegistrationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ export function useRegistrationService() {
setProcessing,
selectedDelegation,
resetRegistration: reset,
refetch: refetchV1Delegations,
} = useDelegationState();
const { transitionPhase1Delegation } = useTransactionService();
const { addDelegation } = useDelegationV2State();
const { addDelegation, refetch: refetchV2Delegations } =
useDelegationV2State();
const { showError } = useError();

const registerPhase1Delegation = useCallback(async () => {
Expand Down Expand Up @@ -85,6 +87,9 @@ export function useRegistrationService() {
);
if (delegation) {
setStep("registration-verified");
// Refetch both v1 and v2 delegations to reflect the latest state
refetchV1Delegations();
refetchV2Delegations();
}
setProcessing(false);
} catch (error: any) {
Expand All @@ -104,6 +109,8 @@ export function useRegistrationService() {
showError,
selectedDelegation,
addDelegation,
refetchV1Delegations,
refetchV2Delegations,
]);

return { registerPhase1Delegation };
Expand Down
6 changes: 5 additions & 1 deletion src/app/state/DelegationState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ interface DelegationState {
setProcessing: (value: boolean) => void;
setSelectedDelegation: (delegation?: Delegation) => void;
resetRegistration: () => void;
refetch: () => void;
}

const { StateProvider, useState: useDelegationState } =
Expand All @@ -56,11 +57,12 @@ const { StateProvider, useState: useDelegationState } =
setProcessing: () => null,
setSelectedDelegation: () => null,
resetRegistration: () => null,
refetch: () => null,
});

export function DelegationState({ children }: PropsWithChildren) {
const { publicKeyNoCoord } = useBTCWallet();
const { data, fetchNextPage, isFetchingNextPage, hasNextPage } =
const { data, fetchNextPage, isFetchingNextPage, hasNextPage, refetch } =
useDelegations();

// States
Expand Down Expand Up @@ -130,6 +132,7 @@ export function DelegationState({ children }: PropsWithChildren) {
setProcessing,
setSelectedDelegation,
resetRegistration,
refetch,
}),
[
delegations,
Expand All @@ -144,6 +147,7 @@ export function DelegationState({ children }: PropsWithChildren) {
setProcessing,
setSelectedDelegation,
resetRegistration,
refetch,
],
);

Expand Down
6 changes: 5 additions & 1 deletion src/app/state/DelegationV2State.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface DelegationV2State {
fetchMoreDelegations: () => void;
findDelegationByTxHash: (txHash: string) => DelegationV2 | undefined;
getStakedBalance: () => number;
refetch: () => void;
}

const STAKED_BALANCE_STATUSES = [
Expand All @@ -45,11 +46,12 @@ const { StateProvider, useState } = createStateUtils<DelegationV2State>({
fetchMoreDelegations: () => {},
findDelegationByTxHash: () => undefined,
getStakedBalance: () => 0,
refetch: () => {},
});

export function DelegationV2State({ children }: PropsWithChildren) {
const { publicKeyNoCoord } = useBTCWallet();
const { data, fetchNextPage, isFetchingNextPage, hasNextPage } =
const { data, fetchNextPage, isFetchingNextPage, hasNextPage, refetch } =
useDelegationsV2();

// States
Expand Down Expand Up @@ -101,6 +103,7 @@ export function DelegationV2State({ children }: PropsWithChildren) {
findDelegationByTxHash,
fetchMoreDelegations: fetchNextPage,
getStakedBalance,
refetch,
}),
[
delegations,
Expand All @@ -111,6 +114,7 @@ export function DelegationV2State({ children }: PropsWithChildren) {
findDelegationByTxHash,
fetchNextPage,
getStakedBalance,
refetch,
],
);

Expand Down

0 comments on commit 5cb6360

Please sign in to comment.