Skip to content

Commit fa07f96

Browse files
committed
fix migration issue for already linked delegate address
1 parent aadf438 commit fa07f96

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
3+
SPDX-FileCopyrightText: © 2023 Dai Foundation <www.daifoundation.org>
4+
5+
SPDX-License-Identifier: AGPL-3.0-or-later
6+
7+
*/
8+
9+
import useSWR from 'swr';
10+
import { useContracts } from 'modules/web3/hooks/useContracts';
11+
import { ZERO_ADDRESS } from 'modules/web3/constants/addresses';
12+
13+
type VoteDelegateAddressResponse = {
14+
data?: boolean | undefined;
15+
loading: boolean;
16+
error: Error;
17+
mutate: () => void;
18+
};
19+
20+
// Returns whether the address has a v2 vote delegate contract
21+
export const useHasV1VoteDelegate = (account?: string): VoteDelegateAddressResponse => {
22+
const { voteDelegateFactoryOld } = useContracts();
23+
console.log('voteDelegateFactory', voteDelegateFactoryOld);
24+
const { data, error, mutate } = useSWR(account ? `${account}/has-v1-vote-delegate-address` : null, async () => {
25+
if (!account) return false;
26+
const newVdAddress = await voteDelegateFactoryOld.delegates(account);
27+
28+
return newVdAddress !== ZERO_ADDRESS;
29+
});
30+
return {
31+
data,
32+
loading: !error && !data,
33+
error,
34+
mutate
35+
};
36+
};

pages/migration/delegate.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { ConnectWallet } from 'modules/migration/components/ConnectWallet';
2222
import { NewDelegateContract } from 'modules/migration/components/NewDelegateContract';
2323
import { sign } from 'modules/web3/helpers/sign';
2424
import { useLinkedDelegateInfo } from 'modules/migration/hooks/useLinkedDelegateInfo';
25+
import { useHasV1VoteDelegate } from 'modules/delegates/hooks/useHasV2VoteDelegate';
2526

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

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

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

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

75-
// delegate contract is either expired or expiring or needs to migrate to v2
78+
// delegate contract needs to migrate to v2
7679
// and we have processed the request to migrate
7780
// but user is connected with old address
7881
if (

0 commit comments

Comments
 (0)