Skip to content

Commit

Permalink
Merge pull request #949 from makerdao/delegators-flow
Browse files Browse the repository at this point in the history
unhide migration banner for delegators & only count v2 renewals for delegator migration
  • Loading branch information
tyler17 authored Nov 20, 2024
2 parents f914847 + b3519e1 commit f2c44d8
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 29 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
3 changes: 1 addition & 2 deletions modules/migration/components/MigrationBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ export function MigrationBanner(): React.ReactElement | null {
isDelegateV1Contract,
isDelegatedToV1Contract
} = useMigrationStatus();
//TODO: uncomment the isDelegatedToV1Contract code once we're ready for the delegator migration
const showDelegationMigrationBanner = (isDelegateV1Contract && !isShadowDelegate) ;//|| isDelegatedToV1Contract;
const showDelegationMigrationBanner = (isDelegateV1Contract && !isShadowDelegate) || isDelegatedToV1Contract;

const { variant, href, copy } = getMigrationBannerContent({
isDelegateV1Contract,
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 f2c44d8

Please sign in to comment.