Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 16 additions & 54 deletions components/StakeTransactions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ import { Box, Card, Flex, Heading, Text } from "@livepeer/design-system";
import { formatLPT } from "@utils/numberFormatters";
import { formatAddress } from "@utils/web3";
import { UnbondingLock } from "apollo";
import {
useCurrentRoundData,
useSubgraphDegraded,
useUnbondingLocksData,
} from "hooks";
import { useMemo } from "react";
import { parseEther } from "viem";

Expand All @@ -18,54 +13,20 @@ import WithdrawStake from "../WithdrawStake";
const Index = ({ delegator, transcoders, currentRound, isMyAccount }) => {
const isBonded = !!delegator.delegate;

// TEMPORARY, with the subgraph outage: locks created after indexing stopped
// are missing here, so an unbond looks like it never happened. Append the
// ones above the subgraph's highest known id, read from the chain. The round
// comes from the chain too, or a stale one leaves a matured lock stuck in
// "Pending" with no withdraw button. Remove once indexing has recovered.
const degraded = useSubgraphDegraded();

const nextLockId = useMemo(
() =>
delegator.unbondingLocks.reduce(
(next: number, lock: UnbondingLock) =>
Math.max(next, lock.unbondingLockId + 1),
0
),
[delegator.unbondingLocks]
);
const missing = useUnbondingLocksData(
degraded && isMyAccount ? delegator.id : null,
nextLockId
);

const locks = useMemo(
() =>
missing?.locks.length
? [...delegator.unbondingLocks, ...missing.locks]
: delegator.unbondingLocks,
[delegator.unbondingLocks, missing]
);

const onchainRound = useCurrentRoundData();
const roundId = Number(onchainRound?.id ?? currentRound.id);

const pendingStakeTransactions = useMemo(
() =>
locks.filter(
(item: UnbondingLock) =>
item.withdrawRound && +item.withdrawRound > roundId
),
[locks, roundId]
);
const completedStakeTransactions = useMemo(
() =>
locks.filter(
(item: UnbondingLock) =>
item.withdrawRound && +item.withdrawRound <= roundId
),
[locks, roundId]
);
const pendingStakeTransactions = useMemo(() => {
const roundId = parseInt(currentRound.id, 10);
return delegator.unbondingLocks.filter(
(item: UnbondingLock) =>
item.withdrawRound && +item.withdrawRound > roundId
);
}, [delegator.unbondingLocks, currentRound.id]);
const completedStakeTransactions = useMemo(() => {
const roundId = parseInt(currentRound.id, 10);
return delegator.unbondingLocks.filter(
(item: UnbondingLock) =>
item.withdrawRound && +item.withdrawRound <= roundId
);
}, [delegator.unbondingLocks, currentRound.id]);

return (
<Box css={{ marginTop: "$6" }}>
Expand Down Expand Up @@ -114,7 +75,8 @@ const Index = ({ delegator, transcoders, currentRound, isMyAccount }) => {
</Box>
<Text variant="neutral" size="1">
Tokens will be available for withdrawal in approximately{" "}
{+lock.withdrawRound - roundId} days.
{+lock.withdrawRound - parseInt(currentRound.id, 10)}{" "}
days.
</Text>
</Box>
<Flex
Expand Down
13 changes: 0 additions & 13 deletions hooks/useSwr.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
RegisteredToVote,
VotingPower,
} from "@lib/api/types/get-treasury-proposal";
import { UnbondingLocks } from "@lib/api/types/get-unbonding-locks";
import { formatAddress } from "@utils/web3";
import { isManualPoll } from "constants/manualPolls";
import useSWR from "swr";
Expand Down Expand Up @@ -199,18 +198,6 @@ export const useAccountBalanceData = (address: string | undefined | null) => {
return data ?? null;
};

export const useUnbondingLocksData = (
address: string | undefined | null,
from: number
) => {
// `from` skips the ids the subgraph already has. See /api/unbonding-locks.
const { data } = useSWR<UnbondingLocks>(
address ? `/unbonding-locks/${address.toLowerCase()}?from=${from}` : null
);

return data ?? null;
};

export const useL1DelegatorData = (address: string | undefined | null) => {
const { data } = useSWR<L1Delegator>(
address ? `/l1-delegator/${address.toLowerCase()}` : null
Expand Down
15 changes: 0 additions & 15 deletions lib/api/types/get-unbonding-locks.ts

This file was deleted.

102 changes: 0 additions & 102 deletions pages/api/unbonding-locks/[address].tsx

This file was deleted.

Loading