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

Master -> develop #948

Merged
merged 6 commits into from
Oct 24, 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
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
Loading