Skip to content

Commit

Permalink
Merge pull request #948 from makerdao/master
Browse files Browse the repository at this point in the history
Master -> develop
  • Loading branch information
tyler17 authored Oct 24, 2024
2 parents aadf438 + e3f5b24 commit b05d9c6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
35 changes: 35 additions & 0 deletions modules/delegates/hooks/useHasV2VoteDelegate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
SPDX-FileCopyrightText: © 2023 Dai Foundation <www.daifoundation.org>
SPDX-License-Identifier: AGPL-3.0-or-later
*/

import useSWR from 'swr';
import { useContracts } from 'modules/web3/hooks/useContracts';
import { ZERO_ADDRESS } from 'modules/web3/constants/addresses';

type HasV1VoteDelegateResponse = {
data?: boolean | undefined;
loading: boolean;
error: Error;
mutate: () => void;
};

// Returns whether the address has a v1 vote delegate contract
export const useHasV1VoteDelegate = (account?: string): HasV1VoteDelegateResponse => {
const { voteDelegateFactoryOld } = useContracts();
const { data, error, mutate } = useSWR(account ? `${account}/has-v1-vote-delegate-address` : null, async () => {
if (!account) return false;
const newVdAddress = await voteDelegateFactoryOld.delegates(account);

return newVdAddress !== ZERO_ADDRESS;
});
return {
data,
loading: !error && !data,
error,
mutate
};
};
9 changes: 6 additions & 3 deletions pages/migration/delegate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { ConnectWallet } from 'modules/migration/components/ConnectWallet';
import { NewDelegateContract } from 'modules/migration/components/NewDelegateContract';
import { sign } from 'modules/web3/helpers/sign';
import { useLinkedDelegateInfo } from 'modules/migration/hooks/useLinkedDelegateInfo';
import { useHasV1VoteDelegate } from 'modules/delegates/hooks/useHasV2VoteDelegate';

export default function DelegateMigrationPage(): React.ReactElement {
const { account, provider } = useWeb3();
Expand All @@ -38,7 +39,9 @@ export default function DelegateMigrationPage(): React.ReactElement {
latestOwnerHasDelegateContract
} = useLinkedDelegateInfo();

const connectedAddressFound = !!originalOwnerAddress || !!latestOwnerAddress;
//if latest is a v1 delegate contract, then they still haven't started the v2 linking process
const { data: latestIsV1Delegate } = useHasV1VoteDelegate(latestOwnerAddress);
const connectedAddressFound = (!!originalOwnerAddress || !!latestOwnerAddress) && !latestIsV1Delegate;

// the user should be shown the steps to take action if:
// a - the connected account needs to migrate to v2
Expand All @@ -53,7 +56,7 @@ export default function DelegateMigrationPage(): React.ReactElement {

const getCurrentStep = useMemo((): string => {
// delegate contract is v1 and we don't have
// a request to migrate the address yet, show migration info
// a request to migrate the address to v2 yet, show migration info
if (
(isDelegateV1Contract) &&
!connectedAddressFound &&
Expand All @@ -72,7 +75,7 @@ export default function DelegateMigrationPage(): React.ReactElement {
return STEPS.NEW_ADDRESS;
}

// delegate contract is either expired or expiring or needs to migrate to v2
// delegate contract needs to migrate to v2
// and we have processed the request to migrate
// but user is connected with old address
if (
Expand Down

0 comments on commit b05d9c6

Please sign in to comment.