Skip to content

Commit 2888c79

Browse files
authored
Merge pull request #1023 from makerdao/develop
develop -> master
2 parents 7be48a0 + 910d95a commit 2888c79

30 files changed

+512
-498
lines changed

.github/workflows/e2e.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
- test: executives.spec
1616
- test: delegates.spec
1717
- test: polling.spec
18+
- test: wallet.spec
1819
runs-on: ubuntu-latest
1920
env:
2021
INFURA_KEY: ${{ secrets.INFURA_KEY }}

lib/theme/icons.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,7 @@ export const icons = {
11781178
),
11791179
viewBox: '0 0 20 20'
11801180
},
1181+
'Browser Wallet': brandIcons.ether_circle_color,
11811182
WalletLink: {
11821183
path: (
11831184
<g>

modules/app/components/layout/header/AccountBox.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const AccountBox = ({ address, accountName, change, disconnect }: Props): JSX.El
3535
Connected with {accountName}
3636
</Text>
3737
</Flex>
38-
<Button variant="mutedOutline" onClick={change}>
38+
<Button variant="mutedOutline" onClick={change} data-testid="wallet-change-button">
3939
Change
4040
</Button>
4141
</Flex>
@@ -83,7 +83,7 @@ const AccountBox = ({ address, accountName, change, disconnect }: Props): JSX.El
8383
title="View account page"
8484
styles={{ color: 'accentBlue', width: '100%' }}
8585
>
86-
<Button variant="primaryOutline" sx={{ width: '100%' }}>
86+
<Button variant="primaryOutline" sx={{ width: '100%' }} data-testid="view-account-page-button">
8787
View account page
8888
</Button>
8989
</InternalLink>

modules/app/components/layout/header/AccountSelect.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,12 @@ const AccountSelect = (): React.ReactElement => {
144144
<Icon name="chevron_left" color="primary" size="10px" mr="2" />
145145
Back
146146
</Button>
147-
<Close sx={closeButtonStyle} aria-label="close" onClick={close} />
147+
<Close
148+
sx={closeButtonStyle}
149+
aria-label="close"
150+
data-testid="wallet-modal-close-button"
151+
onClick={close}
152+
/>
148153
</Flex>
149154
);
150155

@@ -175,7 +180,12 @@ const AccountSelect = (): React.ReactElement => {
175180
<>
176181
<Flex sx={{ flexDirection: 'row', justifyContent: 'space-between', mb: 3, mt: 1 }}>
177182
<Text variant="microHeading">{address ? 'Account' : 'Select a Wallet'}</Text>
178-
<Close aria-label="close" sx={closeButtonStyle} onClick={close} />
183+
<Close
184+
aria-label="close"
185+
sx={closeButtonStyle}
186+
data-testid="wallet-modal-close-button"
187+
onClick={close}
188+
/>
179189
</Flex>
180190
{address ? (
181191
<>

modules/app/helpers/getVoteProxyAddresses.ts

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,21 @@ export const getVoteProxyAddresses = async (
4747
try {
4848
// assume account is a proxy contrac
4949
// this will fail if vpContract is not an instance of vote proxy
50-
const [proxyAddressCold, proxyAddressHot] = await Promise.all([
51-
publicClient.readContract({
52-
address: account as `0x${string}`,
53-
abi: voteProxyAbi,
54-
functionName: 'cold'
55-
}),
56-
publicClient.readContract({
57-
address: account as `0x${string}`,
58-
abi: voteProxyAbi,
59-
functionName: 'hot'
60-
})
61-
]);
50+
const [proxyAddressCold, proxyAddressHot] = await publicClient.multicall({
51+
contracts: [
52+
{
53+
address: account as `0x${string}`,
54+
abi: voteProxyAbi,
55+
functionName: 'cold'
56+
},
57+
{
58+
address: account as `0x${string}`,
59+
abi: voteProxyAbi,
60+
functionName: 'hot'
61+
}
62+
],
63+
allowFailure: false
64+
});
6265

6366
// if the calls above didn't fail, account is a proxy contract, so set values
6467
hotAddress = proxyAddressHot;
@@ -72,20 +75,23 @@ export const getVoteProxyAddresses = async (
7275

7376
// if account is not a proxy, check if it is a hot or cold address
7477
if (!hasProxy) {
75-
const [proxyAddressCold, proxyAddressHot] = await Promise.all([
76-
publicClient.readContract({
77-
address: voteProxyFactory,
78-
abi: voteProxyFactoryAbi,
79-
functionName: 'coldMap',
80-
args: [account]
81-
}),
82-
publicClient.readContract({
83-
address: voteProxyFactory,
84-
abi: voteProxyFactoryAbi,
85-
functionName: 'hotMap',
86-
args: [account]
87-
})
88-
]);
78+
const [proxyAddressCold, proxyAddressHot] = await publicClient.multicall({
79+
contracts: [
80+
{
81+
address: voteProxyFactory,
82+
abi: voteProxyFactoryAbi,
83+
functionName: 'coldMap',
84+
args: [account]
85+
},
86+
{
87+
address: voteProxyFactory,
88+
abi: voteProxyFactoryAbi,
89+
functionName: 'hotMap',
90+
args: [account]
91+
}
92+
],
93+
allowFailure: false
94+
});
8995

9096
// if account belongs to a hot or cold map, get proxy contract address
9197
if (proxyAddressCold !== ZERO_ADDRESS) {

modules/delegates/api/fetchChainDelegates.ts

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,33 +22,32 @@ export async function fetchChainDelegates(
2222
const chainId = networkNameToChainId(network);
2323
const data = await gqlRequest<Query>({ chainId, query: allDelegates });
2424

25-
const delegates = data.allDelegates.nodes;
25+
const delegates = data.allDelegates.nodes.filter(delegate => !!delegate);
2626

2727
const publicClient = getPublicClient(chainId);
2828

29-
const delegatesWithMkrStaked: DelegateContractInformation[] = await Promise.all(
30-
delegates.map(async (delegate): Promise<DelegateContractInformation> => {
31-
if (delegate?.voteDelegate && delegate.delegate) {
32-
// Get MKR delegated to each contract
33-
const mkr = await publicClient.readContract({
34-
address: chiefAddress[chainId],
35-
abi: chiefAbi,
36-
functionName: 'deposits',
37-
args: [delegate.voteDelegate as `0x${string}`]
38-
});
39-
40-
const chainDelegate: DelegateContractInformation = {
41-
...(delegate as DelegateContractInformation),
42-
address: delegate.delegate,
43-
voteDelegateAddress: delegate.voteDelegate,
44-
mkrDelegated: formatValue(mkr, 'wad', 18, false)
45-
};
46-
47-
return chainDelegate;
48-
}
49-
return delegate as DelegateContractInformation;
29+
const delegatesWithMkrStaked: DelegateContractInformation[] = (
30+
await publicClient.multicall({
31+
contracts: delegates.map(delegate => ({
32+
address: chiefAddress[chainId],
33+
abi: chiefAbi,
34+
functionName: 'deposits',
35+
args: [delegate.voteDelegate as `0x${string}`]
36+
}))
5037
})
51-
);
38+
).map((mkrRes, i) => {
39+
const delegate = delegates[i];
40+
if (delegate.voteDelegate && delegate.delegate && typeof mkrRes.result === 'bigint') {
41+
const chainDelegate: DelegateContractInformation = {
42+
...(delegate as DelegateContractInformation),
43+
address: delegate.delegate,
44+
voteDelegateAddress: delegate.voteDelegate,
45+
mkrDelegated: formatValue(mkrRes.result, 'wad', 18, false)
46+
};
47+
return chainDelegate;
48+
}
49+
return delegate as DelegateContractInformation;
50+
});
5251

5352
return delegatesWithMkrStaked;
5453
}

modules/delegates/helpers/getDelegateContractAddress.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,21 @@ export async function getDelegateContractAddress(
2121
): Promise<string | undefined> {
2222
const publicClient = getPublicClient(chainId);
2323

24-
const voteDelegateAddress = await publicClient.readContract({
25-
address: voteDelegateFactoryAddress[chainId],
26-
abi: voteDelegateFactoryAbi,
27-
functionName: 'delegates',
28-
args: [address as `0x${string}`]
29-
});
30-
31-
const voteDelegateAddressOld = await publicClient.readContract({
32-
address: voteDelegateFactoryOldAddress[chainId],
33-
abi: voteDelegateFactoryOldAbi,
34-
functionName: 'delegates',
35-
args: [address as `0x${string}`]
24+
const [{ result: voteDelegateAddress }, { result: voteDelegateAddressOld }] = await publicClient.multicall({
25+
contracts: [
26+
{
27+
address: voteDelegateFactoryAddress[chainId],
28+
abi: voteDelegateFactoryAbi,
29+
functionName: 'delegates',
30+
args: [address as `0x${string}`]
31+
},
32+
{
33+
address: voteDelegateFactoryOldAddress[chainId],
34+
abi: voteDelegateFactoryOldAbi,
35+
functionName: 'delegates',
36+
args: [address as `0x${string}`]
37+
}
38+
]
3639
});
3740

3841
return voteDelegateAddressOld !== ZERO_ADDRESS

modules/delegates/hooks/useVoteDelegateAddress.ts

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ SPDX-License-Identifier: AGPL-3.0-or-later
77
*/
88

99
import { ZERO_ADDRESS } from 'modules/web3/constants/addresses';
10-
import { useChainId, useReadContract } from 'wagmi';
10+
import { useChainId, useReadContracts } from 'wagmi';
1111
import {
1212
voteDelegateFactoryAbi,
1313
voteDelegateFactoryAddress,
@@ -26,44 +26,43 @@ type VoteDelegateAddressResponse = {
2626
export const useVoteDelegateAddress = (account?: `0x${string}`): VoteDelegateAddressResponse => {
2727
const chainId = useChainId();
2828

29-
const voteDelegateResponse = useReadContract({
30-
address: voteDelegateFactoryAddress[chainId],
31-
abi: voteDelegateFactoryAbi,
32-
chainId,
33-
functionName: 'delegates',
34-
args: [account as `0x${string}`],
29+
const { data, isLoading, error, refetch } = useReadContracts({
30+
contracts: [
31+
{
32+
address: voteDelegateFactoryAddress[chainId],
33+
abi: voteDelegateFactoryAbi,
34+
chainId,
35+
functionName: 'delegates',
36+
args: [account as `0x${string}`]
37+
},
38+
{
39+
address: voteDelegateFactoryOldAddress[chainId],
40+
abi: voteDelegateFactoryOldAbi,
41+
chainId,
42+
functionName: 'delegates',
43+
args: [account as `0x${string}`]
44+
}
45+
],
46+
allowFailure: false,
3547
scopeKey: `${account}/vote-delegate-address`,
3648
query: {
3749
enabled: !!account
3850
}
3951
});
4052

41-
const voteDelegateOldResponse = useReadContract({
42-
address: voteDelegateFactoryOldAddress[chainId],
43-
abi: voteDelegateFactoryOldAbi,
44-
chainId,
45-
functionName: 'delegates',
46-
args: [account as `0x${string}`],
47-
scopeKey: `${account}/vote-delegate-address`,
48-
query: {
49-
enabled: !!account
50-
}
51-
});
52-
53-
const error = voteDelegateResponse.error || voteDelegateOldResponse.error;
53+
const [voteDelegate, voteDelegateOld] = data || [];
5454

5555
return {
5656
data:
57-
voteDelegateResponse.data !== ZERO_ADDRESS
58-
? voteDelegateResponse.data
59-
: voteDelegateOldResponse.data !== ZERO_ADDRESS
60-
? voteDelegateOldResponse.data
57+
voteDelegate !== ZERO_ADDRESS
58+
? voteDelegate
59+
: voteDelegateOld !== ZERO_ADDRESS
60+
? voteDelegateOld
6161
: undefined,
62-
loading: voteDelegateResponse.isLoading || voteDelegateOldResponse.isLoading,
62+
loading: isLoading,
6363
error,
6464
mutate: () => {
65-
voteDelegateResponse.refetch();
66-
voteDelegateOldResponse.refetch();
65+
refetch();
6766
}
6867
};
6968
};

0 commit comments

Comments
 (0)