Skip to content

Commit

Permalink
Merge pull request #240 from makerdao/develop
Browse files Browse the repository at this point in the history
Release v0.2.4
  • Loading branch information
b-pmcg authored Nov 23, 2021
2 parents f5a699d + 4fbdb15 commit 3712e9f
Show file tree
Hide file tree
Showing 161 changed files with 4,951 additions and 4,331 deletions.
2 changes: 1 addition & 1 deletion PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### Link to Clubhouse story
### Link to Shortcut ticket:

### What does this PR do?

Expand Down
4 changes: 2 additions & 2 deletions __tests__/pages/account.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ describe('Delegate Create page', () => {
});

// Transaction is initialized
await screen.findByText('Confirm transaction');
await screen.findByText('Confirm Transaction');

// Transaction state moved to pending
await screen.findByText('Transaction pending');
await screen.findByText('Transaction Pending');

// Transaction state moved to mined
await screen.findByText('Transaction Sent');
Expand Down
32 changes: 16 additions & 16 deletions __tests__/pages/delegates.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
sendMkrToAddress
} from '../helpers';
import { SWRConfig } from 'swr';
import * as utils from '../../lib/utils';
import { DelegatesAPIResponse } from 'modules/delegates/types';
import { DelegateStatusEnum } from 'modules/delegates/delegates.constants';

Expand Down Expand Up @@ -98,9 +97,9 @@ describe('Delegates list page', () => {
click(approveMKRButton);

// Transaction is initialized
await screen.findByText('Confirm transaction');
await screen.findByText('Confirm Transaction');
// Transaction state moved to pending
await screen.findByText('Transaction pending');
await screen.findByText('Transaction Pending');
// Deposit input appears
await screen.findByText('Deposit into delegate contract');

Expand All @@ -123,7 +122,7 @@ describe('Delegates list page', () => {
click(confirmButton);

// Wait for transactions again...
await screen.findByText('Transaction pending');
await screen.findByText('Transaction Pending');
await screen.findByText('Transaction Sent');

// UI updates to display totals correctly
Expand All @@ -140,8 +139,8 @@ describe('Delegates list page', () => {
click(approveIOUButton);

// More transaction screens...
await screen.findByText('Confirm transaction');
await screen.findByText('Transaction pending');
await screen.findByText('Confirm Transaction');
await screen.findByText('Transaction Pending');
await screen.findByText('Withdraw from delegate contract');

// Set max button adds input value correctly
Expand All @@ -155,7 +154,7 @@ describe('Delegates list page', () => {
click(undelegateMKRButton);

// Wait for transactions again...
await screen.findByText('Transaction pending');
await screen.findByText('Transaction Pending');
await screen.findByText('Transaction Sent');

// Close the modal
Expand All @@ -170,14 +169,15 @@ describe('Delegates list page', () => {
expect(newByYou.previousSibling).toHaveTextContent('0.00');
});


test('Find info', async () => {
await screen.findByText('System Info', {

}, {
timeout: 30000
});

await screen.findByText(
'System Info',
{},
{
timeout: 30000
}
);

const totalDelegatesSystemInfo = screen.getByTestId('total-delegates-system-info');
expect(totalDelegatesSystemInfo).toHaveTextContent('1');

Expand All @@ -186,8 +186,8 @@ describe('Delegates list page', () => {

const totalShadowDelegatesSystemInfo = screen.getByTestId('total-shadow-delegates-system-info');
expect(totalShadowDelegatesSystemInfo).toHaveTextContent('0');

const totalMkr = screen.getByTestId('total-mkr-system-info');
expect(totalMkr).toHaveTextContent('10.24');
})
});
});
27 changes: 12 additions & 15 deletions __tests__/pages/esmodule.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// @ts-nocheck
import { renderWithTheme } from '../helpers';
import { cleanup, fireEvent, waitFor, configure , screen } from '@testing-library/react';
import { cleanup, fireEvent, waitFor, configure, screen } from '@testing-library/react';
import waitForExpect from 'wait-for-expect';
import { TestAccountProvider } from '@makerdao/test-helpers';
import { cache } from 'swr';
import ESModule from '../../pages/esmodule';
import getMaker from '../../lib/maker';
import { accountsApi } from '../../stores/accounts';
import BigNumber from 'bignumber.js';
import { ethers } from 'ethers';

export const UINT256_MAX = '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff';

configure({
getElementError: (message, container) => {
Expand Down Expand Up @@ -43,31 +45,26 @@ describe('ES Module', () => {
}, 30000);
});

afterEach(() => {
cache.clear();
cleanup();
});

describe('emergency shutdown render', () => {
// tests render on mobile view automatically
test('show progress bar', () => {
renderWithTheme(<ESModule />);
renderWithTheme(<ESModule />);
const progressBar = screen.getByTestId('progress-ring');
expect(progressBar).toBeTruthy();
expect(progressBar).toBeInTheDocument();
});

test('show esm history', async () => {
renderWithTheme(<ESModule />);

const title = await screen.findByText('ESM History');
expect(title).toBeTruthy();
expect(title).toBeInTheDocument();
});

test('show "Burn your MKR" button', async () => {
renderWithTheme(<ESModule />);

const buttonBurn = await screen.findByText('Burn Your MKR', {}, { timeout: 15000 });
expect(buttonBurn).toBeDefined();
expect(buttonBurn).toBeInTheDocument();
// Initiate Emergency Shutdow
});

Expand Down Expand Up @@ -110,7 +107,7 @@ describe('ES Module', () => {
const amount = 35;
fireEvent.change(screen.getByTestId('mkr-input'), { target: { value: amount } });
const tooLow = await screen.findByText('MKR balance too low', {}, { timeout: 3000 });
expect(tooLow).toBeTruthy();
expect(tooLow).toBeInTheDocument();

// Wait until user balance is loaded
await screen.findByTestId('mkr-input-balance');
Expand Down Expand Up @@ -166,7 +163,7 @@ describe('ES Module', () => {

// Third Step Render
const signTransaction = await screen.findByText('Sign Transaction');
expect(signTransaction).toBeTruthy();
expect(signTransaction).toBeInTheDocument();

// Fourth Step Success Render
await screen.findByText('MKR successfully burned in ESM', {}, { timeout: 10000 });
Expand All @@ -181,14 +178,14 @@ describe('ES Module', () => {
const token = maker.service('smartContract').getContract('MCD_GOV');
await token['mint(uint256)'](WAD.times(50000).toFixed());
const esm = maker.service('smartContract').getContract('MCD_ESM');
await token.approve(esm.address, -1); //approve unlimited
await token.approve(esm.address, ethers.BigNumber.from(UINT256_MAX)); //approve unlimited
await esm.join(WAD.times(50000).toFixed());
});

test('show Initiate Shutdown button on threshold reached', async () => {
await renderWithTheme(<ESModule />);
const el = await screen.findByText('Initiate Emergency Shutdown', {}, { timeout: 30000 });
expect(el).toBeTruthy();
expect(el).toBeInTheDocument();
});

// TODO: this test passing is a false positive bc 'waitFor' is async, but not awaited.
Expand Down
10 changes: 4 additions & 6 deletions __tests__/pages/executive.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,10 @@ describe('Executive page', () => {
const submitButton = screen.getByText('Submit Vote');
click(submitButton);

await screen.findByText('Sign Transaction');
await screen.findByText('Transaction Sent!');
//TODO: get the UI to reflect the vote and test for that

const dialog = screen.getByRole('dialog');
await waitForElementToBeRemoved(dialog);
// wait for transaction to progress
await screen.findByText('Confirm Transaction');
await screen.findByText('Transaction Sent');
await screen.findByText('Close');
});

test('shows delegated balance if account is a delegate', async () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/pages/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ beforeAll(async () => {
});

test('renders', async () => {
const { debug } = render(<Index blogPosts={blogPosts} polls={polls} proposals={proposals} />);
const { debug } = render(<Index blogPosts={blogPosts} polls={polls.polls} proposals={proposals} />);
});
3 changes: 2 additions & 1 deletion lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export const SPELL_SCHEDULED_DATE_OVERRIDES = {
export const POLL_CATEGORIZATION_ENDPOINT =
'https://raw.githubusercontent.com/makerdao/community/master/governance/polls/meta/retroactive-poll-categorization.json';

const expr = /(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})/gi;
const expr =
/(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})/gi;
export const URL_REGEX = new RegExp(expr);

export const EXEC_PROPOSAL_INDEX =
Expand Down
11 changes: 11 additions & 0 deletions lib/datetime.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { formatDistance } from 'date-fns';
import { format, utcToZonedTime } from 'date-fns-tz';

export const formatDateWithTime = (dateString: Date | undefined | number | string): string => {
Expand All @@ -24,3 +25,13 @@ export const formatDateWithoutTime = (dateString: Date | undefined | number | st
return '--';
}
};

export const formatTimeAgo = (dateString: Date | undefined | number | string): string => {
if (!dateString) return '';
const date = new Date(dateString);
try {
return formatDistance(date, new Date(), { addSuffix: true });
} catch (err) {
return '--';
}
};
1 change: 0 additions & 1 deletion lib/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './useTokenAllowance';
export * from './useAllUserVotes';
export * from './useDelegateAddressMap';
4 changes: 3 additions & 1 deletion lib/hooks/useDelegateAddressMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ type DelegateAddressMapResponse = {
};

export const useDelegateAddressMap = (): DelegateAddressMapResponse => {
const { data: delegatesApiResponse, error } = useSWR(`/api/delegates?network=${getNetwork()}`);
const { data: delegatesApiResponse, error } = useSWR(`/api/delegates?network=${getNetwork()}`, null, {
refreshInterval: 0
});

const data =
delegatesApiResponse &&
Expand Down
6 changes: 4 additions & 2 deletions lib/hooks/useTokenAllowance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type TokenAllowanceResponse = {
data?: BigNumber;
loading: boolean;
error?: Error;
mutate: () => void;
};

// Checks if the user allowed the spending of a token and contract address
Expand All @@ -14,7 +15,7 @@ export const useTokenAllowance = (
userAddress?: string,
contractAddress?: string
): TokenAllowanceResponse => {
const { data, error } = useSWR(
const { data, error, mutate } = useSWR(
userAddress && contractAddress ? ['token-balance', token, userAddress, contractAddress] : null,
(_, token, userAddress, contractAddress) =>
getMaker().then(maker => maker.getToken(token).allowance(userAddress, contractAddress))
Expand All @@ -23,6 +24,7 @@ export const useTokenAllowance = (
return {
data,
loading: !error && !data,
error
error,
mutate
};
};
4 changes: 2 additions & 2 deletions lib/maker/web3react/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import ProviderSubprovider from 'web3-provider-engine/dist/es5/subproviders/provider';
import { InjectedConnector } from '@web3-react/injected-connector';
import { WalletConnectConnector } from '@web3-react/walletconnect-connector';
import { WalletConnectConnector, WalletConnectConnectorArguments } from '@web3-react/walletconnect-connector';
import { WalletLinkConnector } from '@web3-react/walletlink-connector';
import { AbstractConnector } from '@web3-react/abstract-connector';
import { networkToRpc } from '../network';
Expand Down Expand Up @@ -33,7 +33,7 @@ export const connectors: Array<[ConnectorName, AbstractConnector]> = [
bridge: 'https://bridge.walletconnect.org',
qrcode: true,
pollingInterval: POLLING_INTERVAL
})
} as WalletConnectConnectorArguments)
],
[
'Coinbase Wallet',
Expand Down
28 changes: 28 additions & 0 deletions modules/address/components/Address.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { formatAddress } from 'lib/utils';
import { getENS } from 'modules/web3/ens';
import React, { useEffect, useState } from 'react';

export function Address({ address }: { address: string }): React.ReactElement {
const [addressFormated, setAddressFormatted] = useState(formatAddress(address || ''));

async function fetchENSName(address: string) {
try {
if (!address) {
return;
}

const ens = await getENS(address);
setAddressFormatted(ens);
} catch (e) {
setAddressFormatted(formatAddress(address));
}
}

useEffect(() => {
if (address) {
fetchENSName(address);
}
}, [address]);

return <React.Fragment>{addressFormated}</React.Fragment>;
}
5 changes: 3 additions & 2 deletions modules/address/components/AddressDetail.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { jsx, Box, Text, Link as ExternalLink, Flex, Divider } from 'theme-ui';
import { Box, Text, Link as ExternalLink, Flex, Divider } from 'theme-ui';
import { useBreakpointIndex } from '@theme-ui/match-media';
import { Icon } from '@makerdao/dai-ui-icons';
import { getNetwork } from 'lib/maker';
Expand All @@ -10,6 +10,7 @@ import { AddressAPIStats, VoteProxyInfo } from '../types/addressApiResponse';
import Tooltip from 'modules/app/components/Tooltip';
import { cutMiddle } from 'lib/string';
import { PollingParticipationOverview } from 'modules/polling/components/PollingParticipationOverview';
import { Address } from './Address';

type PropTypes = {
address: string;
Expand Down Expand Up @@ -52,7 +53,7 @@ export function AddressDetail({ address, stats, voteProxyInfo }: PropTypes): Rea
target="_blank"
>
<Text as="p" sx={{ fontSize: [1, 3], ml: 2 }}>
{bpi > 0 ? address : cutMiddle(address, 6, 6)}
<Address address={address} />
</Text>
</ExternalLink>
{voteProxyInfo && (
Expand Down
2 changes: 1 addition & 1 deletion modules/address/components/AddressIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { jsx, Box } from 'theme-ui';
import { Box } from 'theme-ui';
import { Jazzicon } from '@ukstv/jazzicon-react';

export default function AddressIcon({
Expand Down
1 change: 1 addition & 0 deletions modules/address/types/addressApiResponse.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Delegate } from 'modules/delegates/types';

export type AddressAPIStats = {
pollVoteHistory: PollVoteHistory[];
lastVote: PollVoteHistory;
};

export type VoteProxyInfo = {
Expand Down
2 changes: 1 addition & 1 deletion modules/app/components/Cookies.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useContext } from 'react';

import Link from 'next/link';
import { Box, Button, Flex, jsx, Text, Label, Checkbox } from 'theme-ui';
import { Box, Button, Flex, Text, Label, Checkbox } from 'theme-ui';
import { CookiesContext } from 'modules/app/client/cookies/CookiesContext';

export default function Cookies(): React.ReactElement | null {
Expand Down
2 changes: 1 addition & 1 deletion modules/app/components/CountdownTimer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState } from 'react';
import { Text, Flex, jsx, ThemeUIStyleObject } from 'theme-ui';
import { Text, Flex, ThemeUIStyleObject } from 'theme-ui';
import { Icon } from '@makerdao/dai-ui-icons';

import useInterval from 'lib/useInterval';
Expand Down
1 change: 0 additions & 1 deletion modules/app/components/FilterButton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { jsx } from 'theme-ui';
import { Icon } from '@makerdao/dai-ui-icons';
import { Menu, MenuButton, MenuList } from '@reach/menu-button';

Expand Down
Loading

1 comment on commit 3712e9f

@vercel
Copy link

@vercel vercel bot commented on 3712e9f Nov 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.