Skip to content

Commit

Permalink
feat: to support phase-1 delegation unbonding, query delegation excep…
Browse files Browse the repository at this point in the history
…t terminal state
  • Loading branch information
jrwbabylonlab committed Dec 9, 2024
1 parent aedf75a commit a56af1f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 127 deletions.
8 changes: 3 additions & 5 deletions src/app/api/getDelegations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ interface DelegationAPI {
staking_tx: StakingTxAPI;
unbonding_tx?: UnbondingTxAPI;
is_overflow: boolean;
transitioned: boolean;
is_eligible_for_transition: boolean;
}

Expand All @@ -49,13 +48,12 @@ export const getDelegations = async (
throw new Error("No public key provided");
}

// const limit = 100;
// const reverse = false;

const params = {
pagination_key: encode(key),
staker_btc_pk: encode(publicKeyNoCoord),
state: ["active", "unbonded"],
// We only fetch for states that can have pending actions.
// We don't care terminal states such as "withdrawn" or "transitioned".
state: ["active", "unbonded", "unbonding", "unbonding_requested"],
};

const response = await apiWrapper(
Expand Down
105 changes: 0 additions & 105 deletions src/app/components/Summary/Summary.tsx

This file was deleted.

17 changes: 0 additions & 17 deletions src/app/state/DelegationState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ import { useLocalStorage } from "usehooks-ts";
import { useBTCWallet } from "@/app/context/wallet/BTCWalletProvider";
import { useDelegations } from "@/app/hooks/client/api/useDelegations";
import type { Delegation } from "@/app/types/delegations";
import { DelegationState as DelegationEnum } from "@/app/types/delegations";
import { createStateUtils } from "@/utils/createStateUtils";
import { calculateDelegationsDiff } from "@/utils/local_storage/calculateDelegationsDiff";
import { getDelegationsLocalStorageKey as getDelegationsKey } from "@/utils/local_storage/getDelegationsLocalStorageKey";

interface DelegationState {
isLoading: boolean;
hasMoreDelegations: boolean;
totalStaked: number;
delegations: Delegation[];
addDelegation: (delegation: Delegation) => void;
fetchMoreDelegations: () => void;
Expand All @@ -21,7 +19,6 @@ interface DelegationState {
const { StateProvider, useState } = createStateUtils<DelegationState>({
isLoading: false,
delegations: [],
totalStaked: 0,
hasMoreDelegations: false,
addDelegation: () => null,
fetchMoreDelegations: () => null,
Expand Down Expand Up @@ -57,18 +54,6 @@ export function DelegationState({ children }: PropsWithChildren) {
[data?.delegations, setDelegations, delegations],
);

// Computed
const totalStaked = useMemo(
() =>
(data?.delegations ?? [])
.filter((delegation) => delegation?.state === DelegationEnum.ACTIVE)
.reduce(
(accumulator: number, item) => accumulator + item?.stakingValueSat,
0,
),
[data?.delegations],
);

// Methods
const addDelegation = useCallback(
(newDelegation: Delegation) => {
Expand All @@ -92,15 +77,13 @@ export function DelegationState({ children }: PropsWithChildren) {
const state = useMemo(
() => ({
delegations,
totalStaked,
isLoading: isFetchingNextPage,
hasMoreDelegations: hasNextPage,
addDelegation,
fetchMoreDelegations: fetchNextPage,
}),
[
delegations,
totalStaked,
isFetchingNextPage,
hasNextPage,
addDelegation,
Expand Down

0 comments on commit a56af1f

Please sign in to comment.