Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #412 from 0xProject/governance-updates
Browse files Browse the repository at this point in the history
Merging in recent governance updates into development
  • Loading branch information
lyaunzbe authored Oct 2, 2021
2 parents f4c8105 + da0019c commit 45dd031
Show file tree
Hide file tree
Showing 32 changed files with 2,965 additions and 123 deletions.
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"eslint": "eslint 'ts/**/*.{ts,tsx}'",
"lint": "tslint --format stylish --project . 'ts/**/*.ts' 'ts/**/*.tsx'",
"fix": "yarn lint --fix",
"pre_push": "yarn typecheck && yarn lint:prettier && yarn lint && yarn test",
"pre_push": "yarn lint:prettier && yarn lint && yarn test",
"update:tools": "aws s3 sync --delete s3://docs-markdown/ mdx/tools/ --profile $(npm config get awscli_profile)",
"dev": "npm run update:tools && node --max-old-space-size=16384 ./node_modules/webpack-dev-server/bin/webpack-dev-server.js --mode development --content-base public --https",
"deploy_dogfood": "npm run update:tools && yarn index_docs --environment dogfood && npm run build:prod && aws s3 sync ./public/. s3://dogfood.0xproject.com --profile $(npm config get awscli_profile) --region us-east-1 --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers && ./cdn-cache-clear.sh dogfood",
Expand Down Expand Up @@ -77,8 +77,8 @@
"find-versions": "^2.0.0",
"flickity": "^2.2.2",
"fuse.js": "^3.4.6",
"graphql": "^15.5.0",
"graphql-request": "^3.4.0",
"graphql": "^15.5.1",
"graphql-request": "^3.5.0",
"is-mobile": "^0.2.2",
"less": "^2.7.2",
"lodash": "^4.17.11",
Expand All @@ -89,6 +89,7 @@
"moment": "2.21.0",
"moment-precise-range-plugin": "^1.3.0",
"moment-timezone": "^0.5.33",
"nice-color-palettes": "^3.0.0",
"numeral": "^2.0.6",
"polished": "^1.9.2",
"query-string": "^6.0.0",
Expand All @@ -104,6 +105,7 @@
"react-highlight": "0xproject/react-highlight#react-peer-deps",
"react-instantsearch-dom": "^5.7.0",
"react-markdown": "^4.0.6",
"react-minimal-pie-chart": "^8.2.0",
"react-popper": "^1.0.0-beta.6",
"react-query": "^3.7.1",
"react-redux": "^7.1.3",
Expand All @@ -127,6 +129,7 @@
"styled-components": "^5.0.0",
"thenby": "^1.2.3",
"truffle-contract": "2.0.1",
"urql": "^2.0.4",
"valid-url": "^1.0.9",
"web3-provider-engine": "14.0.6",
"xml-js": "^1.6.4"
Expand Down
Binary file added public/images/mail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions ts/components/dialogs/connect_wallet_dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ export const ConnectWalletDialog = () => {
const handleAccount = async (currentConnector: AbstractConnector, option: Option) => {
let address: string = '';

(window as any).heap.track('Wallet connected', { wallet: option.type });
// console.log(currentConnector, option)
try {
await activate(currentConnector, undefined, true);
setActivatingConnector(currentConnector);
Expand Down
326 changes: 326 additions & 0 deletions ts/components/governance/hero.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,326 @@
import { Web3Wrapper } from '@0x/web3-wrapper';
import * as React from 'react';
import styled from 'styled-components';
import { GOVERNOR_CONTRACT_ADDRESS } from 'ts/utils/configs';
import { formatNumber } from 'ts/utils/format_number';

import { ERC20TokenContract } from '@0x/contract-wrappers';

import { BigNumber } from '@0x/utils';
import { useSelector } from 'react-redux';

import { State } from 'ts/redux/reducer';
import { backendClient } from 'ts/utils/backend_client';

import { ZeroExProvider } from '@0x/asset-buyer';
import { colors } from 'ts/style/colors';

interface GovernanceHeroProps {
title: string | React.ReactNode;
numProposals?: number | null;
titleMobile: string | React.ReactNode;
description: string | React.ReactNode;
figure: React.ReactNode;
actions: React.ReactNode;
provider?: ZeroExProvider;
videoId?: string;
videoChannel?: string;
videoRatio?: string;
youtubeOptions?: any;
averageVotingPower?: number | undefined;
metrics?: {
zrxStaked: number;
currentEpochRewards: BigNumber;
nextEpochStartDate: Date;
};
}

interface WrapperProps {}

interface InnerProps {}

interface RowProps {}

const Wrapper = styled.div<WrapperProps>`
width: 100%;
text-align: center;
max-width: 1450px;
margin: 0 auto;
@media (min-width: 768px) {
padding: 30px;
text-align: left;
}
`;

const Inner = styled.div<InnerProps>`
background-color: #f3f6f4;
background-image: url(/images/stakingGraphic.svg);
background-repeat: no-repeat;
background-position-x: right;
background-position-y: center;
@media (min-width: 768px) {
padding: 30px;
}
`;

const Row = styled.div<RowProps>`
max-width: 1152px;
margin: 0 auto;
display: flex;
justify-content: space-between;
align-items: center;
flex-direction: column;
@media (min-width: 768px) {
flex-direction: row;
& > * {
}
}
`;

const Column = styled.div`
padding: 30px;
@media (min-width: 768px) {
padding: 60px 28px;
&:first-child {
padding-left: 0;
}
&:last-child {
padding-right: 0;
}
}
`;

const Title = styled.h1`
font-size: 46px;
line-height: 1.2;
font-weight: 300;
margin-bottom: 20px;
display: none;
@media (min-width: 768px) {
font-size: 50px;
display: block;
}
`;

const TitleMobile = styled(Title)`
display: block;
@media (min-width: 768px) {
display: none;
}
`;

const Description = styled.h2`
font-size: 18px;
line-height: 1.45;
font-weight: 300;
margin-bottom: 30px;
color: ${colors.textDarkSecondary};
`;

const Actions = styled.div`
display: flex;
flex-direction: column;
& > * {
margin-right: 13px;
margin-bottom: 10px;
}
@media (min-width: 768px) {
flex-direction: row;
}
`;

const MetricsWrapper = styled.div`
display: flex;
flex-direction: column;
`;

const FiguresList = styled.ol`
display: flex;
flex-direction: column;
flex-wrap: wrap;
padding-top: 15px;
`;

const Figure = styled.li`
display: flex;
flex-direction: column;
justify-content: space-between;
text-align: left;
padding: 10px;
margin-bottom: 15px;
max-width: 50%;
@media (min-width: 480px) {
padding: 20px;
}
`;

const FigurePair = styled.div`
display: flex;
justify-content: space-between;
`;
const FigureHeader = styled.header`
display: flex;
justify-content: space-between;
align-items: baseline;
`;

const FigureTitle = styled.span`
display: block;
font-size: 16px;
line-height: 1.35;
margin-bottom: 5px;
`;

const FigureNumber = styled.span`
display: block;
font-feature-settings: 'tnum' on, 'lnum' on;
font-size: 20px;
line-height: 1.35;
@media (min-width: 768px) {
font-size: 34px;
}
@media (min-width: 991px) {
font-size: 44px;
}
`;

export const GovernanceHero: React.FC<GovernanceHeroProps> = (props) => {
const { title, titleMobile, description, actions, numProposals, averageVotingPower } = props;
const providerState = useSelector((state: State) => state.providerState);

const [totalTreasuryAmountUSD, setTotalTreasuryAmountUSD] = React.useState('-');
const [totalTreasuryDistributedUSD, setTotalTreasuryDistributedUSD] = React.useState('-');

const parseTotalDistributed = (transferData: any) => {
let totalDistributed = 0;
if (transferData) {
transferData.forEach((tf: any) => {
if (tf.data.items) {
tf.data.items.forEach((item: any) => {
item.transfers.forEach((transfer: any) => {
if (transfer.transfer_type === 'OUT') {
const delta_quote =
parseInt(transfer.delta, 10) *
Math.pow(10, -transfer.contract_decimals) *
transfer.quote_rate;

totalDistributed += delta_quote;
}
});
});
}
});
}

return totalDistributed;
};

React.useEffect(() => {
const zrxTokenContract = new ERC20TokenContract(
'0xe41d2489571d322189246dafa5ebde1f4699f498',
providerState.provider,
);
const maticTokenContract = new ERC20TokenContract(
'0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0',
providerState.provider,
);

// tslint:disable-next-line:no-floating-promises
(async () => {
const [zrxBalance, maticBalance] = await Promise.all([
zrxTokenContract.balanceOf(GOVERNOR_CONTRACT_ADDRESS.ZRX).callAsync(),
maticTokenContract.balanceOf(GOVERNOR_CONTRACT_ADDRESS.ZRX).callAsync(),
]);
const res = await backendClient.getTreasuryTokenPricesAsync();
const zrxAmount = Web3Wrapper.toUnitAmount(zrxBalance, 18);
const maticAmount = Web3Wrapper.toUnitAmount(maticBalance, 18);
const zrxUSD = zrxAmount.multipliedBy(res['0x'].usd);
const maticUSD = maticAmount.multipliedBy(res['matic-network'].usd);

const treasuryTokenTransferData = await backendClient.getTreasuryTokenTransfersAsync();
const totalDistributed = parseTotalDistributed(treasuryTokenTransferData);
setTotalTreasuryDistributedUSD(
`$${
formatNumber(totalDistributed, {
decimals: 6,
decimalsRounded: 6,
bigUnitPostfix: true,
}).formatted
}`,
);
setTotalTreasuryAmountUSD(
`$${
formatNumber(zrxUSD.plus(maticUSD).toString(), {
decimals: 6,
decimalsRounded: 6,
bigUnitPostfix: true,
}).formatted
}`,
);
})();
}, [providerState]);

const averageVotingPowerFormatted = averageVotingPower
? formatNumber(averageVotingPower, {
decimals: 6,
decimalsRounded: 6,
bigUnitPostfix: true,
}).formatted
: '-';
return (
<Wrapper>
<Inner>
<Row>
<Column>
<Title>{title}</Title>
<TitleMobile>{titleMobile}</TitleMobile>
<Description>{description}</Description>
<Actions>{actions}</Actions>
</Column>
<Column>
<MetricsWrapper>
{/* <FiguresListHeader>Treasury Stats</FiguresListHeader> */}
<FiguresList>
<FigurePair>
<Figure key={1}>
<FigureHeader>
<FigureTitle>Available Treasury</FigureTitle>
</FigureHeader>
<FigureNumber>{totalTreasuryAmountUSD}</FigureNumber>
</Figure>
<Figure key={2}>
<FigureHeader>
<FigureTitle>Total Distributed</FigureTitle>
</FigureHeader>
<FigureNumber>{totalTreasuryDistributedUSD}</FigureNumber>
</Figure>
</FigurePair>

<FigurePair>
<Figure key={3}>
<FigureHeader>
<FigureTitle>Votes Passed</FigureTitle>
</FigureHeader>
<FigureNumber>{numProposals || 0}</FigureNumber>
</Figure>
<Figure key={4} style={{}}>
<FigureHeader>
<FigureTitle>Avg. ZRX Voted Per Proposal</FigureTitle>
</FigureHeader>
<FigureNumber>{averageVotingPowerFormatted}</FigureNumber>
</Figure>
</FigurePair>
{/* <ProgressbarText>Treasury Details</ProgressbarText> */}
</FiguresList>
</MetricsWrapper>
</Column>
</Row>
</Inner>
</Wrapper>
);
};

GovernanceHero.defaultProps = {
videoChannel: 'youtube',
videoRatio: '21:9',
};
Loading

1 comment on commit 45dd031

@vercel
Copy link

@vercel vercel bot commented on 45dd031 Oct 2, 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.