Skip to content
Permalink
Browse files

Merge pull request #32 from makerdao/develop

Develop
  • Loading branch information
levity committed Feb 7, 2020
2 parents e25883e + 628bf38 commit 0959708eaebe9ff21857c8793816f38aeb564cef
@@ -28,6 +28,7 @@ jobs:
- run:
name: Run tests
command: |
source /home/circleci/setup-env.sh
yarn test --coverage
npm i --no-save codecov
./node_modules/.bin/codecov
@@ -26,7 +26,7 @@ const ProxyAndTransfer = ({
const { setup_text, confirmations_text } = labels;
const [isTransferringCDP, setIsTransferringCDP] = useState(false);
const { maker } = useMaker();
if(proxyErrors) showErrorMessageAndAllowExiting();
if (proxyErrors) showErrorMessageAndAllowExiting();
const transferCDP = useCallback(async () => {
try {
if (!proxyAddress)
@@ -85,9 +85,8 @@ const ProxyAndTransfer = ({
<Grid gridRowGap="xs" mt="l">
<Text.h4>Transfer CDP ownership to proxy</Text.h4>
<Text.p color="darkLavender" fontSize="l" lineHeight="normal">
Proxies are used to bundle multiple transactions
into one, saving transaction time and gas costs. This only has to be
done once.
Proxies are used to bundle multiple transactions into one, saving
transaction time and gas costs. This only has to be done once.
</Text.p>
{cdpTransferred ? (
<SuccessButton />
@@ -2,17 +2,20 @@ import React from 'react';
import checkmark from '../assets/icons/largeCheckmark.svg';
import { Button, Text } from '@makerdao/ui-components-core';

const SuccessButton = () => {
const SuccessButton = props => {
return (
<Button
variant="primary-outline"
justifySelf={['center', 'left']}
width={["26.0rem", "13.0rem"]}
width={['26.0rem', '13.0rem']}
mt="xs"
disabled
{...props}
>
<img src={checkmark} />
<Text ml={'s'} display={['inline', 'none']} color='teal.500'>Transaction Complete</Text>
<Text ml={'s'} display={['inline', 'none']} color="teal.500">
Transaction Complete
</Text>
</Button>
);
};
@@ -23,6 +23,10 @@ const APPROVAL_FUDGE = 2;
const HIGH_FEE_LOWER_BOUND = 50;
const CDP_MIN_RATIO = 170;

const TAB_PAY_WITH_MKR = 0;
const TAB_PAY_WITH_DEBT = 1;
const TAB_LABELS = ['Pay with MKR', 'Pay with CDP debt'];

const TOSCheck = ({ hasReadTOS, setHasReadTOS }) => {
return (
<Grid alignItems="center" gridTemplateColumns="auto 1fr">
@@ -31,6 +35,7 @@ const TOSCheck = ({ hasReadTOS, setHasReadTOS }) => {
fontSize="l"
checked={hasReadTOS}
onChange={() => setHasReadTOS(!hasReadTOS)}
data-testid="tosCheck"
/>
<Text
t="caption"
@@ -174,32 +179,37 @@ const PayAndMigrate = ({

useEffect(() => {
(async () => {
if (maker && account) {
const mig = maker
.service('migration')
.getMigration('single-to-multi-cdp');
const mkrToken = maker.service('token').getToken(MKR);
const [
mkrBalanceFromSdk,
proxyAddress,
saiNeededInMarketFromSdk
] = await Promise.all([
mkrToken.balance(),
maker.service('proxy').currentProxy(),
mig.saiAmountNeededToBuyMkr(govFeeMKRExact)
]);
setMkrBalance(mkrBalanceFromSdk);
setSaiNeededInMarket(saiNeededInMarketFromSdk);
if (proxyAddress) {
const connectedWalletAllowance = await maker
.getToken(MKR)
.allowance(account.address, proxyAddress);
const hasMkrAllowance = connectedWalletAllowance.gte(
govFeeMKRExact.times(APPROVAL_FUDGE)
);
setProxyDetails({ hasMkrAllowance, address: proxyAddress });
}
}
if (!maker || !account) return;

const mig = maker
.service('migration')
.getMigration('single-to-multi-cdp');
const mkrToken = maker.service('token').getToken(MKR);
await Promise.all([
mkrToken.balance().then(setMkrBalance),

maker
.service('proxy')
.currentProxy()
.then(async address => {
if (!address) return;

const connectedWalletAllowance = await maker
.getToken(MKR)
.allowance(account.address, address);
const hasMkrAllowance = connectedWalletAllowance.gte(
govFeeMKRExact.times(APPROVAL_FUDGE)
);
setProxyDetails({ hasMkrAllowance, address });
}),

mig
.saiAmountNeededToBuyMkr(govFeeMKRExact)
.then(setSaiNeededInMarket)
.catch(err => {
console.error(`Couldn't calculate Sai needed for fee: ${err}`);
})
]);
})();
}, [account, maker, govFeeMKRExact]);

@@ -219,10 +229,7 @@ const PayAndMigrate = ({
saiNeededInMarket &&
maxCost.toBigNumber().gt(saiNeededInMarket.toBigNumber());

const TAB_PAY_WITH_MKR = 0;
const TAB_PAY_WITH_DEBT = 1;
const TABS = ['Pay with MKR', 'Pay with CDP debt'];
const [selectedTab, setSelectedTab] = useState(0);
const [selectedTab, setSelectedTab] = useState(TAB_PAY_WITH_MKR);

return (
<Grid
@@ -233,7 +240,7 @@ const PayAndMigrate = ({
width={['100vw', 'auto']}
>
<Text.h2 textAlign="center">Confirm CDP Upgrade</Text.h2>
<CardTabs onChange={setSelectedTab} headers={TABS}>
<CardTabs onChange={setSelectedTab} headers={TAB_LABELS}>
<Grid gridRowGap="m" color="darkPurple" pt="2xs" pb="l" px="l">
<Table width="100%">
<Table.tbody>
@@ -292,14 +299,13 @@ const PayAndMigrate = ({
completeText={'MKR unlocked'}
loadingText={'Unlocking MKR'}
defaultText={'Unlock MKR to continue'}
tokenDisplayName={'MKR'}
isLoading={mkrApprovePending}
isComplete={proxyDetails.hasMkrAllowance}
onToggle={giveProxyMkrAllowance}
disabled={
proxyDetails.hasMkrAllowance || !proxyDetails.address
}
data-testid="allowance-toggle"
testId="allowance-toggle"
/>
</Grid>
<TOSCheck {...{ hasReadTOS, setHasReadTOS }} />
@@ -14,6 +14,7 @@ import {
import { getColor } from '../../utils/theme';
import useStore from '../../hooks/useStore';
import { prettifyNumber } from '../../utils/ui';
import { CDP_MIGRATION_MINIMUM_DEBT } from '../../utils/constants';

const RADIO_WIDTH = '2rem';
const RADIO_CONTAINER_WIDTH = '4rem';
@@ -41,13 +42,14 @@ function ListItemRow({ label, value, dark }) {
);
}

function ListItem({ cdp, onSelect, checked, selectable }) {
function ListItem({ cdp, onSelect, checked, selectable, ...otherProps }) {
return (
<Card
px={['0', 'l']}
py={['0', 'm']}
borderColor={checked ? '#1AAB9B' : '#D4D9E1'}
border={checked ? '2px solid' : '1px solid'}
{...otherProps}
>
<Box display={['none', 'block']}>
<Grid
@@ -66,6 +68,7 @@ function ListItem({ cdp, onSelect, checked, selectable }) {
onChange={() => onSelect(cdp)}
fontSize={RADIO_WIDTH}
checked={checked}
data-testid={'cdpRadio'}
/>
) : (
<span></span>
@@ -120,7 +123,7 @@ export default ({
const [{ saiAvailable }] = useStore();

const isSelectable = cdp =>
cdp.debtValueExact.gt(20) &&
cdp.debtValueExact.gte(CDP_MIGRATION_MINIMUM_DEBT) &&
cdp.debtValueExact.lt(saiAvailable.toBigNumber());

return (
@@ -180,6 +183,7 @@ export default ({
selectable={isSelectable(cdp)}
key={cdp.id}
onSelect={onSelect}
data-testid="cdpListItem"
/>
))}
</Grid>
@@ -213,15 +217,15 @@ const DebtLimitMessage = ({ saiAvailable }) => (
lineHeight="normal"
p="m"
>
{saiAvailable && saiAvailable.lt(20) ? (
{saiAvailable && saiAvailable.lt(CDP_MIGRATION_MINIMUM_DEBT) ? (
<span>
There is not enough Sai available to migrate CDPs at this time. Please
try again later.
</span>
) : (
<span>
CDPs with less than 20 or more than {prettifyNumber(saiAvailable)} of
debt cannot be migrated at this time.
CDPs with less than {CDP_MIGRATION_MINIMUM_DEBT} or more than{' '}
{prettifyNumber(saiAvailable)} of debt cannot be migrated at this time.
</span>
)}
<br />
@@ -51,7 +51,13 @@ export async function instantiateMaker(network) {
}
],
migrationPlugin
]
],
addressOverrides: {
MAKER_OTC: {
mainnet: '0x794e6e91555438afc3ccf1c5076a74f42133d08d',
kovan: '0xe325acb9765b02b8b418199bf9650972299235f4'
}
}
};

maker = await Maker.create('http', config);
@@ -15,10 +15,10 @@
},
"dependencies": {
"@makerdao/currency": "^0.9.5",
"@makerdao/dai": "^0.23.0-rc.2",
"@makerdao/dai": "^0.23.2",
"@makerdao/dai-plugin-ledger-web": "^0.9.7",
"@makerdao/dai-plugin-mcd": "^1.0.3",
"@makerdao/dai-plugin-migrations": "1.0.3",
"@makerdao/dai-plugin-mcd": "^1.0.6",
"@makerdao/dai-plugin-migrations": "1.0.12",
"@makerdao/dai-plugin-trezor-web": "^0.9.6",
"@makerdao/dai-plugin-walletconnect": "^0.0.8",
"@makerdao/dai-plugin-walletlink": "^0.0.1",
@@ -45,7 +45,7 @@
},
"devDependencies": {
"@makerdao/test-helpers": "^0.2.1",
"@makerdao/testchain": "^1.0.1",
"@makerdao/testchain": "^1.0.5",
"@testing-library/react": "^9.3.2",
"babel-eslint": "^10.0.3",
"babel-plugin-styled-components": "^1.10.6",
@@ -58,6 +58,9 @@
"lint-staged": "^9.4.3",
"wait-for-expect": "^3.0.1"
},
"engines": {
"node": ">=10.x.x"
},
"lint-staged": {
"*.js": [
"prettier --write --single-quote",
@@ -102,7 +102,8 @@ export default function() {
useEffect(() => {
(async () => {
if (!maker || !account || !cdpMigrationCheck) return;
setCdps(await getAllCdpData(cdpMigrationCheck, maker));
const data = await getAllCdpData(cdpMigrationCheck, maker);
setCdps(data);
setLoadingCdps(false);
})();
}, [maker, account, cdpMigrationCheck]);
@@ -90,7 +90,9 @@ function Overview() {
saiBalance,
daiBalance,
saiAvailable,
daiAvailable
daiAvailable,
oldMkrBalance,
chiefMigrationCheck
},
dispatch
] = useStore();
@@ -112,16 +114,28 @@ function Overview() {
payload: {
cdpMigrationCheck: checks['single-to-multi-cdp'],
saiBalance: SAI(checks['sai-to-dai']),
daiBalance: _daiBalance
daiBalance: _daiBalance,
oldMkrBalance: checks['mkr-redeemer'],
chiefMigrationCheck: checks['chief-migrate']
}
});
})();
}, [maker, account, dispatch]);

const { mkrLockedDirectly, mkrLockedViaProxy } = chiefMigrationCheck || {};

const shouldShowCdps = countCdps(cdps) > 0;
const shouldShowDai = saiBalance && saiBalance.gt(0);
const shouldShowMkr = oldMkrBalance && oldMkrBalance.gt(0);
const shouldShowReverse = daiBalance && daiBalance.gt(0);
const noMigrations = !shouldShowDai && !shouldShowCdps && !shouldShowReverse;
const shouldShowChief =
chiefMigrationCheck && (mkrLockedDirectly.gt(0) || mkrLockedViaProxy.gt(0));
const noMigrations =
!shouldShowCdps &&
!shouldShowDai &&
!shouldShowMkr &&
!shouldShowReverse &&
!shouldShowChief;

return (
<Flex flexDirection="column" minHeight="100vh">
@@ -187,16 +201,31 @@ function Overview() {
}}
/>
)}
{/* { mkr &&
<MigrationCard
recommended
title="DSChief MKR Withdrawal"
body="Due to the recent discovery of a potential exploit in the Maker Governance Contract (DSChief), all users are requested to withdraw any MKR deposited into one of the voting contracts back to their wallet."
metadataTitle="SCD Balance"
metadataValue="1,400.00 DAI"
onSelected={showModal}
/>}
*/}
{shouldShowChief && (
<MigrationCard
recommended
title="DSChief MKR Withdrawal"
body="Due to the recent discovery of a potential exploit in the Maker Governance Contract (DSChief), all users are requested to withdraw any MKR deposited into one of the voting contracts back to their wallet."
metadataTitle="MKR to claim"
metadataValue={showAmount(
mkrLockedDirectly.plus(mkrLockedViaProxy)
)}
onSelected={() => {
window.open('https://chief-migration.makerdao.com/', '_blank');
}}
/>
)}

{shouldShowMkr && (
<MigrationCard
recommended
title="Redeem New MKR"
body="Swap your old MKR for new MKR by upgrading to the new ds-token."
onSelected={() => {
window.open('https://makerdao.com/redeem/', '_blank');
}}
/>
)}
</Grid>
{initialFetchComplete ? (
noMigrations && (
@@ -52,6 +52,6 @@ function StoreAccess({ callback, children }) {
// `window.maker`
function MakerAccess({ callback, children }) {
const { maker } = useMaker();
if (callback) callback(maker);
if (callback && maker) callback(maker);
return <Fragment>{children}</Fragment>;
}

0 comments on commit 0959708

Please sign in to comment.
You can’t perform that action at this time.