Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unhide migration banner for delegators & only count v2 renewals for delegator migration #949

Merged
merged 3 commits into from
Nov 20, 2024
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
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
Loading