Skip to content

Commit 37825c1

Browse files
authored
Fix/lm unclaimed calc (#975)
* fix: LM Vesting crashes rewards page * fix: unclaimed vesting calculation
1 parent 64be738 commit 37825c1

4 files changed

Lines changed: 135 additions & 4 deletions

File tree

.changeset/modern-ducks-shake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'frontend': patch
3+
---
4+
5+
fix: LM Vesting crashes rewards page

apps/frontend/src/app/5_pages/RewardsPage/components/Vesting/hooks/useLmLimit.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,37 @@ import dayjs from 'dayjs';
55
import { useAccount } from '../../../../../../hooks/useAccount';
66
import { rskClient } from '../../../../../../utils/clients';
77
import {
8+
useGetLastWithdrawOfVestingTypeQuery,
89
useGetUserVestingsOfTypeQuery,
910
VestingContractType,
1011
} from '../../../../../../utils/graphql/rsk/generated';
1112

1213
export const useGetUnclaimedUserVestingCount = () => {
1314
const { account } = useAccount();
14-
const { data } = useGetUserVestingsOfTypeQuery({
15+
const { data, loading } = useGetUserVestingsOfTypeQuery({
1516
variables: {
1617
user: account.toLowerCase(),
1718
type: VestingContractType.Rewards,
1819
},
1920
client: rskClient,
2021
});
2122

23+
const { data: withdraws, loading: loadingWithdraws } =
24+
useGetLastWithdrawOfVestingTypeQuery({
25+
variables: {
26+
user: account,
27+
type: VestingContractType.Rewards,
28+
},
29+
client: rskClient,
30+
});
31+
32+
const lastWithdrawTimestamp = useMemo(
33+
() =>
34+
withdraws?.vestingContracts[0]?.stakeHistory?.[0]?.timestamp ||
35+
dayjs().subtract(4, 'year').unix(),
36+
[withdraws?.vestingContracts],
37+
);
38+
2239
const result = useMemo(() => {
2340
const stakeHistoryItems = data?.vestingContracts[0]?.stakeHistory?.map(
2441
item => ({
@@ -46,10 +63,12 @@ export const useGetUnclaimedUserVestingCount = () => {
4663
}),
4764
).sort((a, b) => a.lockedUntil - b.lockedUntil);
4865

49-
const pastDatesLength = unlockDates?.filter(item => item.isUnlocked).length;
66+
const pastDatesLength = unlockDates
67+
?.filter(item => item.isUnlocked)
68+
.filter(item => item.lockedUntil > lastWithdrawTimestamp).length;
5069

5170
return pastDatesLength;
52-
}, [data?.vestingContracts]);
71+
}, [data?.vestingContracts, lastWithdrawTimestamp]);
5372

54-
return result;
73+
return loading || loadingWithdraws ? 0 : result;
5574
};

apps/frontend/src/utils/graphql/rsk/generated.tsx

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16838,6 +16838,25 @@ export type GetUserVestingsOfTypeQuery = {
1683816838
}>;
1683916839
};
1684016840

16841+
export type GetLastWithdrawOfVestingTypeQueryVariables = Exact<{
16842+
user?: InputMaybe<Scalars['String']>;
16843+
type?: InputMaybe<VestingContractType>;
16844+
}>;
16845+
16846+
export type GetLastWithdrawOfVestingTypeQuery = {
16847+
__typename?: 'Query';
16848+
vestingContracts: Array<{
16849+
__typename?: 'VestingContract';
16850+
id: string;
16851+
stakeHistory?: Array<{
16852+
__typename?: 'VestingHistoryItem';
16853+
id: string;
16854+
amount: string;
16855+
timestamp: number;
16856+
}> | null;
16857+
}>;
16858+
};
16859+
1684116860
export type GetVestingHistoryItemsQueryVariables = Exact<{
1684216861
stakers?: InputMaybe<Array<Scalars['String']> | Scalars['String']>;
1684316862
skip: Scalars['Int'];
@@ -19852,6 +19871,78 @@ export type GetUserVestingsOfTypeQueryResult = Apollo.QueryResult<
1985219871
GetUserVestingsOfTypeQuery,
1985319872
GetUserVestingsOfTypeQueryVariables
1985419873
>;
19874+
export const GetLastWithdrawOfVestingTypeDocument = gql`
19875+
query getLastWithdrawOfVestingType(
19876+
$user: String
19877+
$type: VestingContractType
19878+
) {
19879+
vestingContracts(where: { user: $user, type: $type }) {
19880+
id
19881+
stakeHistory(
19882+
where: { action: TokensWithdrawn }
19883+
orderBy: timestamp
19884+
orderDirection: desc
19885+
first: 1
19886+
) {
19887+
id
19888+
amount
19889+
timestamp
19890+
}
19891+
}
19892+
}
19893+
`;
19894+
19895+
/**
19896+
* __useGetLastWithdrawOfVestingTypeQuery__
19897+
*
19898+
* To run a query within a React component, call `useGetLastWithdrawOfVestingTypeQuery` and pass it any options that fit your needs.
19899+
* When your component renders, `useGetLastWithdrawOfVestingTypeQuery` returns an object from Apollo Client that contains loading, error, and data properties
19900+
* you can use to render your UI.
19901+
*
19902+
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
19903+
*
19904+
* @example
19905+
* const { data, loading, error } = useGetLastWithdrawOfVestingTypeQuery({
19906+
* variables: {
19907+
* user: // value for 'user'
19908+
* type: // value for 'type'
19909+
* },
19910+
* });
19911+
*/
19912+
export function useGetLastWithdrawOfVestingTypeQuery(
19913+
baseOptions?: Apollo.QueryHookOptions<
19914+
GetLastWithdrawOfVestingTypeQuery,
19915+
GetLastWithdrawOfVestingTypeQueryVariables
19916+
>,
19917+
) {
19918+
const options = { ...defaultOptions, ...baseOptions };
19919+
return Apollo.useQuery<
19920+
GetLastWithdrawOfVestingTypeQuery,
19921+
GetLastWithdrawOfVestingTypeQueryVariables
19922+
>(GetLastWithdrawOfVestingTypeDocument, options);
19923+
}
19924+
export function useGetLastWithdrawOfVestingTypeLazyQuery(
19925+
baseOptions?: Apollo.LazyQueryHookOptions<
19926+
GetLastWithdrawOfVestingTypeQuery,
19927+
GetLastWithdrawOfVestingTypeQueryVariables
19928+
>,
19929+
) {
19930+
const options = { ...defaultOptions, ...baseOptions };
19931+
return Apollo.useLazyQuery<
19932+
GetLastWithdrawOfVestingTypeQuery,
19933+
GetLastWithdrawOfVestingTypeQueryVariables
19934+
>(GetLastWithdrawOfVestingTypeDocument, options);
19935+
}
19936+
export type GetLastWithdrawOfVestingTypeQueryHookResult = ReturnType<
19937+
typeof useGetLastWithdrawOfVestingTypeQuery
19938+
>;
19939+
export type GetLastWithdrawOfVestingTypeLazyQueryHookResult = ReturnType<
19940+
typeof useGetLastWithdrawOfVestingTypeLazyQuery
19941+
>;
19942+
export type GetLastWithdrawOfVestingTypeQueryResult = Apollo.QueryResult<
19943+
GetLastWithdrawOfVestingTypeQuery,
19944+
GetLastWithdrawOfVestingTypeQueryVariables
19945+
>;
1985519946
export const GetVestingHistoryItemsDocument = gql`
1985619947
query getVestingHistoryItems(
1985719948
$stakers: [String!]

apps/frontend/src/utils/graphql/rsk/operations/getVestingHistory.graphql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,19 @@ query getUserVestingsOfType($user: String, $type: VestingContractType) {
2929
}
3030
}
3131
}
32+
33+
query getLastWithdrawOfVestingType($user: String, $type: VestingContractType) {
34+
vestingContracts(where: { user: $user, type: $type }) {
35+
id
36+
stakeHistory(
37+
where: { action: TokensWithdrawn }
38+
orderBy: timestamp
39+
orderDirection: desc
40+
first: 1
41+
) {
42+
id
43+
amount
44+
timestamp
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)