From 2665b722b47a8826c5e0c92f9555bbf123d63096 Mon Sep 17 00:00:00 2001 From: tyler17 Date: Thu, 24 Oct 2024 17:35:04 -0700 Subject: [PATCH] only count renewals to v2 contracts for delegator migration, delete unused code from hook --- modules/delegates/api/fetchDelegatedTo.ts | 3 ++- modules/delegates/types/delegate.d.ts | 2 +- .../migration/hooks/useMigrationStatus.tsx | 26 +------------------ 3 files changed, 4 insertions(+), 27 deletions(-) diff --git a/modules/delegates/api/fetchDelegatedTo.ts b/modules/delegates/api/fetchDelegatedTo.ts index ffe8e176c..e1b1de39a 100644 --- a/modules/delegates/api/fetchDelegatedTo.ts +++ b/modules/delegates/api/fetchDelegatedTo.ts @@ -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); } diff --git a/modules/delegates/types/delegate.d.ts b/modules/delegates/types/delegate.d.ts index d2dedf1f2..dad6a96d9 100644 --- a/modules/delegates/types/delegate.d.ts +++ b/modules/delegates/types/delegate.d.ts @@ -98,7 +98,7 @@ export type DelegationHistoryWithExpirationDate = DelegationHistory & { expirationDate?: Date | null; isAboutToExpire: boolean; isExpired: boolean; - isRenewed: boolean; + isRenewedToV2: boolean; }; export type DelegationHistoryEvent = { diff --git a/modules/migration/hooks/useMigrationStatus.tsx b/modules/migration/hooks/useMigrationStatus.tsx index a1a116126..8520d4311 100644 --- a/modules/migration/hooks/useMigrationStatus.tsx +++ b/modules/migration/hooks/useMigrationStatus.tsx @@ -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; @@ -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