Skip to content

Commit

Permalink
only count renewals to v2 contracts for delegator migration, delete u…
Browse files Browse the repository at this point in the history
…nused code from hook
  • Loading branch information
tyler17 committed Oct 25, 2024
1 parent f984329 commit 2665b72
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 27 deletions.
3 changes: 2 additions & 1 deletion modules/delegates/api/fetchDelegatedTo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ export async function fetchDelegatedTo(
isExpired,
isAboutToExpire: !isExpired && isAboutToExpire,
lockAmount: utils.formatEther(lockAmount),
isRenewed: !!newRenewedContract,
// @ts-ignore: Property 'delegateVersion' might not exist on type 'AllDelegatesRecord'
isRenewedToV2: !!newRenewedContract && newRenewedContract.delegateVersion === 2,
events: [{ lockAmount: utils.formatEther(lockAmount), blockTimestamp, hash, isLockstake }]
} as DelegationHistoryWithExpirationDate);
}
Expand Down
2 changes: 1 addition & 1 deletion modules/delegates/types/delegate.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export type DelegationHistoryWithExpirationDate = DelegationHistory & {
expirationDate?: Date | null;
isAboutToExpire: boolean;
isExpired: boolean;
isRenewed: boolean;
isRenewedToV2: boolean;
};

export type DelegationHistoryEvent = {
Expand Down
26 changes: 1 addition & 25 deletions modules/migration/hooks/useMigrationStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ import { AddressApiResponse } from 'modules/address/types/addressApiResponse';
import { fetchJson } from 'lib/fetchJson';

export function useMigrationStatus(): {
isDelegatedToExpiredContract: boolean;
isDelegatedToExpiringContract: boolean;
isDelegateContractExpired: boolean;
isDelegateContractExpiring: boolean;
isShadowDelegate: boolean;
isDelegateV1Contract: boolean;
isDelegatedToV1Contract: boolean;
Expand Down Expand Up @@ -52,41 +49,20 @@ export function useMigrationStatus(): {

const isDelegateV1Contract = !!delegateContractExpirationDate;

const isDelegateContractExpiring =
isDelegateV1Contract && delegateContractExpirationDate
? isAboutToExpireCheck(delegateContractExpirationDate)
: false;

// check if is delegating to an expired contract, independently of its renewal status
const isDelegateContractExpired =
isDelegateV1Contract && delegateContractExpirationDate
? isExpiredCheck(delegateContractExpirationDate)
: false;

// Checks if its delegating to an expiring contract that is already renewed.
const isDelegatedToExpiringContract = delegatedToData
? delegatedToData.delegatedTo.reduce((acc, cur) => {
return acc || (cur.isAboutToExpire && cur.isRenewed && new BigNumber(cur.lockAmount).gt(0));
}, false)
: false;

const isDelegatedToExpiredContract = delegatedToData
? delegatedToData.delegatedTo.reduce((acc, cur) => {
return acc || (cur.isExpired && new BigNumber(cur.lockAmount).gt(0));
}, false)
: false;

const isDelegatedToV1Contract = delegatedToData
? delegatedToData.delegatedTo.reduce((acc, cur) => {
return acc || (!!cur.expirationDate && cur.isRenewed &&new BigNumber(cur.lockAmount).gt(0));
return acc || (!!cur.expirationDate && cur.isRenewedToV2 && new BigNumber(cur.lockAmount).gt(0));
}, false)
: false;

return {
isDelegatedToExpiredContract,
isDelegatedToExpiringContract,
isDelegateContractExpired,
isDelegateContractExpiring,
isShadowDelegate,
isDelegateV1Contract,
isDelegatedToV1Contract
Expand Down

0 comments on commit 2665b72

Please sign in to comment.