Skip to content

Commit 468c0d1

Browse files
authored
Merge pull request #383 from makerdao/develop
Hotfix , delegates api timeout
2 parents e7a2261 + 31462e7 commit 468c0d1

File tree

16 files changed

+102
-51
lines changed

16 files changed

+102
-51
lines changed

lib/theme.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ export default {
6060
tagColorFifteenBg: '#FFFBEF',
6161
tagColorSixteen: '#FF8237',
6262
tagColorSixteenBg: '#FFFBEF',
63+
tagColorSeventeen: '#AD927D',
64+
tagColorSeventeenBg: '#FFF9F4',
6365
voterYellow: '#FDC134',
6466
bull: '#1AAB9B',
6567
bear: '#F77249',
@@ -122,6 +124,8 @@ export default {
122124
tagColorFifteenBg: '#121212',
123125
tagColorSixteen: '#FF8237',
124126
tagColorSixteenBg: '#121212',
127+
tagColorSeventeen: '#AD927D',
128+
tagColorSeventeenBg: '#121212',
125129
bull: '#1AAB9B',
126130
bear: '#F77249'
127131
}

modules/delegates/api/fetchDelegates.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import {
1010
DelegateContractInformation,
1111
DelegateRepoInformation
1212
} from 'modules/delegates/types';
13-
import { getExecutiveProposals, getGithubExecutives } from 'modules/executive/api/fetchExecutives';
13+
import { getGithubExecutives } from 'modules/executive/api/fetchExecutives';
1414
import { getContracts } from 'modules/web3/helpers/getContracts';
1515
import { networkNameToChainId } from 'modules/web3/helpers/chain';
1616
import { ZERO_SLATE_HASH } from 'modules/executive/helpers/zeroSlateHash';
1717
import { getSlateAddresses } from 'modules/executive/helpers/getSlateAddresses';
1818
import { CMSProposal } from 'modules/executive/types';
19-
import { fetchAddressPollVoteHistory } from 'modules/polling/api/fetchAddressPollVoteHistory';
19+
import { fetchLastPollVote } from 'modules/polling/api/fetchLastPollvote';
2020

2121
function mergeDelegateInfo(
2222
onChainDelegate: DelegateContractInformation,
@@ -37,15 +37,14 @@ function mergeDelegateInfo(
3737
picture: githubDelegate?.picture || '',
3838
id: onChainDelegate.voteDelegateAddress,
3939
externalUrl: githubDelegate?.externalUrl,
40-
lastVote: null,
40+
lastVoteDate: null,
4141
communication: githubDelegate?.communication,
4242
combinedParticipation: githubDelegate?.combinedParticipation,
4343
pollParticipation: githubDelegate?.pollParticipation,
4444
executiveParticipation: githubDelegate?.executiveParticipation,
4545
mkrDelegated: onChainDelegate.mkrDelegated,
4646
proposalsSupported: onChainDelegate.proposalsSupported,
47-
execSupported: onChainDelegate.execSupported,
48-
pollVoteHistory: onChainDelegate.pollVoteHistory
47+
execSupported: onChainDelegate.execSupported
4948
};
5049
}
5150

@@ -100,6 +99,7 @@ export async function fetchDelegates(network?: SupportedNetworks): Promise<Deleg
10099

101100
const contracts = getContracts(networkNameToChainId(currentNetwork));
102101
const executives = await getGithubExecutives(currentNetwork);
102+
103103
const delegates = await Promise.all(
104104
delegatesInfo.map(async delegate => {
105105
const votedSlate = await contracts.chief.votes(delegate.voteDelegateAddress);
@@ -109,12 +109,13 @@ export async function fetchDelegates(network?: SupportedNetworks): Promise<Deleg
109109
const execSupported: CMSProposal | undefined = executives?.find(proposal =>
110110
votedProposals?.find(vp => vp.toLowerCase() === proposal?.address?.toLowerCase())
111111
);
112-
const pollVoteHistory = await fetchAddressPollVoteHistory(delegate.voteDelegateAddress, currentNetwork);
112+
113+
const lastVote = await fetchLastPollVote(delegate.voteDelegateAddress, currentNetwork);
113114
return {
114115
...delegate,
115116
proposalsSupported,
116117
execSupported,
117-
pollVoteHistory
118+
lastVoteDate: lastVote ? lastVote.blockTimestamp : null
118119
};
119120
})
120121
);

modules/delegates/components/DelegateCard.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ export function DelegateCard({ delegate }: PropTypes): React.ReactElement {
3838

3939
const isOwner = delegate.voteDelegateAddress.toLowerCase() === voteDelegateContractAddress?.toLowerCase();
4040

41-
const lastVote = delegate.pollVoteHistory.sort((a, b) => (a.blockTimestamp > b.blockTimestamp ? -1 : 1))[0];
42-
4341
return (
4442
<Card
4543
sx={{
@@ -50,10 +48,11 @@ export function DelegateCard({ delegate }: PropTypes): React.ReactElement {
5048
>
5149
<Box px={[3, 4]} pb={[3, 4]} pt={3}>
5250
<Box mb={2}>
53-
{delegate.pollVoteHistory && (
54-
<LastVoted expired={delegate.expired} date={lastVote ? lastVote.blockTimestamp : null} left />
55-
)}
56-
{!delegate.pollVoteHistory && <SkeletonThemed width={'200px'} height={'15px'} />}
51+
<LastVoted
52+
expired={delegate.expired}
53+
date={delegate.lastVoteDate ? delegate.lastVoteDate : ''}
54+
left
55+
/>
5756
</Box>
5857
<Flex
5958
sx={{

modules/delegates/components/DelegatesSort.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default function DelegatesSort(): JSX.Element {
1414
/>
1515
<ListboxPopover sx={{ variant: 'listboxes.default.popover' }}>
1616
<ListboxList sx={{ variant: 'listboxes.default.list' }}>
17-
<ListboxOption value={delegatesSortEnum.random}>Sort order</ListboxOption>
17+
<ListboxOption value={delegatesSortEnum.random}>Sort by default</ListboxOption>
1818
<ListboxOption value={delegatesSortEnum.mkrDelegated}>Sort by MKR delegated</ListboxOption>
1919
<ListboxOption value={delegatesSortEnum.creationDate}>Sort by creation date</ListboxOption>
2020
</ListboxList>

modules/delegates/types/delegate.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export type Delegate = {
3131
picture: string;
3232
status: DelegateStatus;
3333
expired: boolean;
34-
lastVote: Date | null;
34+
lastVoteDate: string | null;
3535
expirationDate: Date;
3636
externalUrl?: string;
3737
combinedParticipation?: string;
@@ -41,7 +41,6 @@ export type Delegate = {
4141
mkrDelegated: string;
4242
proposalsSupported: number;
4343
execSupported: CMSProposal | undefined;
44-
pollVoteHistory: PollVoteHistory;
4544
};
4645

4746
export type DelegationHistory = {

modules/executive/api/fetchExecutives.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,23 @@ export async function getGithubExecutives(network: SupportedNetworks): Promise<C
5050
.filter(x => !!x)
5151
.filter(x => x?.address !== ZERO_ADDRESS) as CMSProposal[];
5252

53+
const sortedProposals = filteredProposals
54+
.sort((a, b) => new Date(b.date || '').getTime() - new Date(a.date || '').getTime())
55+
.sort(a => (a.active ? -1 : 1)) // Sort by active first
56+
.slice(0, 100);
57+
58+
if (config.USE_FS_CACHE) {
59+
fsCacheSet(cacheKey, JSON.stringify(sortedProposals), network);
60+
}
61+
62+
return sortedProposals;
63+
}
64+
65+
async function getGithubExecutivesWithMKR(network: SupportedNetworks): Promise<CMSProposal[]> {
66+
const proposals = await getGithubExecutives(network);
67+
5368
const mkrSupports = await Promise.all(
54-
filteredProposals.map(async proposal => {
69+
proposals.map(async proposal => {
5570
const mkrSupport = await getExecutiveMKRSupport(proposal.address, network);
5671
return {
5772
...proposal,
@@ -62,16 +77,7 @@ export async function getGithubExecutives(network: SupportedNetworks): Promise<C
6277
})
6378
);
6479

65-
const sortedProposals = mkrSupports
66-
.sort((a, b) => new Date(b.date || '').getTime() - new Date(a.date || '').getTime())
67-
.sort(a => (a.active ? -1 : 1)) // Sort by active first
68-
.slice(0, 100);
69-
70-
if (config.USE_FS_CACHE) {
71-
fsCacheSet(cacheKey, JSON.stringify(sortedProposals), network);
72-
}
73-
74-
return sortedProposals;
80+
return mkrSupports;
7581
}
7682

7783
export async function getExecutiveProposals(
@@ -96,7 +102,7 @@ export async function getExecutiveProposals(
96102
}
97103
}
98104

99-
const proposals = await getGithubExecutives(currentNetwork);
105+
const proposals = await getGithubExecutivesWithMKR(currentNetwork);
100106

101107
const sorted = proposals.sort((a, b) => {
102108
if (sortBy === 'mkr') {
@@ -145,7 +151,7 @@ export async function getExecutiveProposal(
145151
// Use goerli as a Key for Goerli fork. In order to pick the the current executives
146152
const currentNetwork = net === SupportedNetworks.GOERLIFORK ? SupportedNetworks.GOERLI : net;
147153

148-
const proposals = await getGithubExecutives(currentNetwork);
154+
const proposals = await getGithubExecutivesWithMKR(currentNetwork);
149155

150156
const proposal = proposals.find(proposal => proposal.key === proposalId || proposal.address === proposalId);
151157
if (!proposal) return null;

modules/executive/components/DateFilter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default function DateFilter(props): JSX.Element {
4242
return (
4343
<FilterButton
4444
name={() => {
45-
if (!startDateDisplay && !endDateDisplay) return 'Date Posted';
45+
if (!startDateDisplay && !endDateDisplay) return 'Date Filter';
4646
if (!startDateDisplay) return `Date Filter: before ${endDateDisplay}`;
4747
if (!endDateDisplay) return `Date Filter: after ${startDateDisplay}`;
4848
return `Date Filter: ${startDateDisplay} - ${endDateDisplay}`;

modules/gql/queries/lastPollVote.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { gql } from 'graphql-request';
2+
3+
export const lastPollVote = gql`
4+
query lastPollVote($argAddress: String!) {
5+
allCurrentVotes(argAddress: $argAddress, first: 1) {
6+
nodes {
7+
pollId
8+
optionId
9+
optionIdRaw
10+
blockTimestamp
11+
}
12+
}
13+
}
14+
`;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { gqlRequest } from 'modules/gql/gqlRequest';
2+
import { lastPollVote } from 'modules/gql/queries/lastPollVote';
3+
import { SupportedNetworks } from 'modules/web3/constants/networks';
4+
import { networkNameToChainId } from 'modules/web3/helpers/chain';
5+
import { parseRawOptinIdRankedChoiceOption } from '../helpers/parseRawOptionIdRankedChoiceOption';
6+
import { PollVote } from '../types';
7+
8+
export async function fetchLastPollVote(
9+
address: string,
10+
network: SupportedNetworks
11+
): Promise<PollVote | null> {
12+
const data = await gqlRequest({
13+
chainId: networkNameToChainId(network),
14+
query: lastPollVote,
15+
variables: { argAddress: address.toLowerCase() }
16+
});
17+
18+
// Parse the rankedChoice option
19+
const res: PollVote[] = data.allCurrentVotes.nodes.map(o => {
20+
const rankedChoiceOption = parseRawOptinIdRankedChoiceOption(o.optionIdRaw);
21+
return {
22+
...o,
23+
rankedChoiceOption
24+
};
25+
});
26+
27+
return res.length > 0 ? res[0] : null;
28+
}

modules/polling/components/PollCategoryTag.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,15 @@ export function PollCategoryTag({
7373
Offboard: {
7474
color: 'tagColorSixteen',
7575
backgroundColor: 'tagColorSixteenBg'
76+
},
77+
Uncategorized: {
78+
color: 'tagColorSeventeen',
79+
backgroundColor: 'tagColorSeventeenBg'
7680
}
7781
};
7882

79-
const color = categories[category] ? categories[category].color : '#AD927D';
80-
const backgroundColor = categories[category] ? categories[category].backgroundColor : '#FFF9F4';
83+
const color = categories[category] ? categories[category].color : 'tagColorSeventeen';
84+
const backgroundColor = categories[category] ? categories[category].backgroundColor : 'tagColorSeventeenBg';
8185

8286
const [categoryFilter, setCategoryFilter] = useUiFiltersStore(
8387
state => [state.pollFilters.categoryFilter, state.setCategoryFilter],

modules/polling/types/pollVote.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ type LegacyPollVote = {
33
optionId: number;
44
optionIdRaw?: string;
55
rankedChoiceOption?: number[];
6-
blockTimestamp: number;
6+
blockTimestamp: string;
77
};
88

99
type RankedChoicePollVote = {
1010
pollId: number;
1111
optionId?: number;
1212
optionIdRaw?: string;
1313
rankedChoiceOption: number[];
14-
blockTimestamp: number;
14+
blockTimestamp: string;
1515
};
1616

1717
export type PollVote = LegacyPollVote | RankedChoicePollVote;

pages/api/delegates/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ export default withApiHandler(async (req: NextApiRequest, res: NextApiResponse<D
1313
invariant(isSupportedNetwork(network), `unsupported network ${network}`);
1414
const delegates = await fetchDelegates(network);
1515

16-
res.setHeader('Cache-Control', 's-maxage=15, stale-while-revalidate');
16+
res.setHeader('Cache-Control', 's-maxage=3600, stale-while-revalidate');
1717
res.status(200).json(delegates);
1818
});

pages/api/delegates/names.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ export default withApiHandler(async (req: NextApiRequest, res: NextApiResponse<D
1515
invariant(isSupportedNetwork(network), `unsupported network ${network}`);
1616
const delegates = await fetchDelegatesInformation(network);
1717

18-
res.setHeader('Cache-Control', 's-maxage=15, stale-while-revalidate');
18+
res.setHeader('Cache-Control', 's-maxage=3600, stale-while-revalidate');
1919
return res.status(200).json(delegates);
2020
});

pages/delegates/index.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,19 @@ const Delegates = ({ delegates, stats }: Props) => {
9191
<Heading variant="microHeading" mr={3} sx={{ display: ['none', 'block'] }}>
9292
Filters
9393
</Heading>
94-
<DelegatesFilter delegates={delegates} />
94+
<DelegatesSort />
9595
</Flex>
9696

9797
<Flex sx={{ ml: [0, 3], mt: [2, 0] }}>
98+
<DelegatesFilter delegates={delegates} />
9899
<Button
99100
variant={'outline'}
100-
sx={{ mr: 3 }}
101+
sx={{ ml: 3 }}
101102
onClick={resetFilters}
102103
data-testid="delegate-reset-filters"
103104
>
104105
Clear filters
105106
</Button>
106-
107-
<DelegatesSort />
108107
</Flex>
109108
</Flex>
110109

pages/executive.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ export const ExecutiveOverview = ({ proposals }: { proposals?: Proposal[] }): JS
136136
});
137137

138138
const isLoadingInitialData = !paginatedProposals && !error;
139+
139140
const isLoadingMore =
140-
isLoadingInitialData ||
141-
(size > 0 && paginatedProposals && typeof paginatedProposals[size - 1] === 'undefined' && isValidating);
141+
size > 0 && paginatedProposals && typeof paginatedProposals[size - 1] === 'undefined' && isValidating;
142142

143143
const loadMore = () => {
144144
setSize(size + 1);

pages/polling.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ const PollingOverview = ({ polls, categories }: Props) => {
141141
/>
142142

143143
<Stack gap={3}>
144-
{bpi <= 3 && account && <BallotStatus />}
145144
<Flex sx={{ alignItems: 'center', flexDirection: ['column', 'row'] }}>
146145
<Flex sx={{ alignItems: 'center' }}>
147146
<Heading variant="microHeading" mr={3} sx={{ display: ['none', 'block'] }}>
@@ -159,14 +158,12 @@ const PollingOverview = ({ polls, categories }: Props) => {
159158
{filteredPolls.length > 0 ? (
160159
<Stack>
161160
<div>
162-
<Heading
163-
mb={3}
164-
mt={4}
165-
as="h4"
166-
sx={{ display: sortedEndDatesActive.length > 0 ? undefined : 'none' }}
167-
>
168-
Active Polls
169-
</Heading>
161+
<Flex sx={{ alignItems: 'center', justifyContent: 'space-between', my: 3 }}>
162+
<Heading as="h4" sx={{ display: sortedEndDatesActive.length > 0 ? undefined : 'none' }}>
163+
Active Polls
164+
</Heading>
165+
{bpi <= 3 && account && <BallotStatus />}
166+
</Flex>
170167
<Stack>
171168
{sortedEndDatesActive.map(date => (
172169
<div key={date}>

0 commit comments

Comments
 (0)