Skip to content

Commit

Permalink
Merge Dev into Master (#523)
Browse files Browse the repository at this point in the history
* move network switch to sidebar

* polish responsive

* responsive polish

* display user date time format

* display user date time format

* add snx token logo

* disable gas fee selection for optimistic networks

* responsive polish

* remove TestnetNetwork from production build

* polish header

* remove unused vars

* change optimistic maiinet SA loupe address

* polish

* add sunset SE alert text, disable deposit

* change sa loupe address

* disable FLOKI pools

* display network switcher at header for desktop

* polish

* Add Governance Reward 2 support (#507)

* Update tokensProvider.tsx

* Update tokensProvider.tsx

* polish sidebar

* polish governance

* polish portfolio and proposals view

* *

* Fix DAO card (#511)

* Merge Dev into Master (#509)

* move network switch to sidebar

* polish responsive

* responsive polish

* display user date time format

* display user date time format

* add snx token logo

* disable gas fee selection for optimistic networks

* responsive polish

* remove TestnetNetwork from production build

* polish header

* remove unused vars

* change optimistic maiinet SA loupe address

* polish

* add sunset SE alert text, disable deposit

* change sa loupe address

* disable FLOKI pools

* display network switcher at header for desktop

* polish

* Add Governance Reward 2 support (#507)

Co-authored-by: Alexandr <[email protected]>
Co-authored-by: Alex <[email protected]>

* *

Co-authored-by: Alexandr <[email protected]>
Co-authored-by: Alex <[email protected]>

* *

* auto copyright year

* update proposals search

* auto copyright year (#512)

* auto copyright year

* update proposals search

* *

* display connect button for mobile

* mobile polish

* revert VisibilityState type

* update visibilityState type

* Add Airdrop

* Add Mainnet Airdrop

* update icons

* clear unused icons

* mobile polish (#515)

* mobile polish

* revert VisibilityState type

* update visibilityState type

* update icons

* clear unused icons

* rollback package-lock

* rollback package-lock

* fix colors

* * (#521)

* Dev/airdrop (#522)

* *

* *

* *

Co-authored-by: Alexandr <[email protected]>
Co-authored-by: Alex <[email protected]>
  • Loading branch information
3 people authored Feb 3, 2022
1 parent 5376acd commit 966c608
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 71 deletions.
25 changes: 8 additions & 17 deletions src/modules/governance/components/dao-provider/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { useMemo } from 'react';
import React from 'react';
import BigNumber from 'bignumber.js';
import { useContractManager } from 'web3/components/contractManagerProvider';
import Erc20Contract from 'web3/erc20Contract';

import { MerkleDistributor, useAirdrop } from 'airdrop/airdrop';
import { useConfig } from 'components/providers/configProvider';
import { useKnownTokens } from 'components/providers/knownTokensProvider';
import useMergeState from 'hooks/useMergeState';
Expand Down Expand Up @@ -35,8 +36,7 @@ type DAOContextType = DAOProviderState & {
daoBarn: DaoBarnContract;
daoGovernance: DaoGovernanceContract;
daoReward: DaoRewardContract;
daoReward2?: DaoRewardContract;
activeDaoReward?: DaoRewardContract;
airdrop?: MerkleDistributor;
actions: {
activate: () => Promise<void>;
hasActiveProposal: () => Promise<boolean>;
Expand All @@ -55,7 +55,7 @@ const DAOProvider: React.FC = props => {

const config = useConfig();
const walletCtx = useWallet();
const [reloadReward, rewardVersion] = useReload();
const [reloadReward] = useReload();

const { getContract } = useContractManager();

Expand All @@ -68,23 +68,15 @@ const DAOProvider: React.FC = props => {
const daoReward = getContract(config.contracts.dao?.reward!, () => {
return new DaoRewardContract(config.contracts.dao?.reward!);
});
const daoReward2 = config.contracts.dao?.reward2
? getContract(config.contracts.dao?.reward2, () => {
return new DaoRewardContract(config.contracts.dao?.reward2!);
})
: undefined;
const airdropDaoConfig = config.contracts.airdrop?.dao;
const airdrop = useAirdrop(airdropDaoConfig?.merkleDistributor, airdropDaoConfig?.data);
const { projectToken } = useKnownTokens();

const [state, setState] = useMergeState<DAOProviderState>(InitialState);

const activeDaoReward = useMemo(() => {
return [daoReward, daoReward2].find(rw => rw && rw.isStarted && !rw.isEnded);
}, [daoReward, daoReward2, rewardVersion]);

React.useEffect(() => {
daoGovernance.loadCommonData();
daoReward.loadCommonData().then(reloadReward);
daoReward2?.loadCommonData().then(reloadReward);
daoBarn.loadCommonData();
}, []);

Expand All @@ -96,7 +88,7 @@ const DAOProvider: React.FC = props => {
if (walletCtx.account) {
daoGovernance.loadUserData();
daoReward.loadUserData();
daoReward2?.loadUserData();
airdrop?.loadUserData();
daoBarn.loadUserData();
bondContract.loadAllowance(config.contracts.dao?.barn!).catch(Error);
}
Expand Down Expand Up @@ -172,8 +164,7 @@ const DAOProvider: React.FC = props => {
...state,
daoBarn,
daoReward,
daoReward2,
activeDaoReward,
airdrop,
daoGovernance,
actions: {
activate,
Expand Down
23 changes: 8 additions & 15 deletions src/modules/governance/components/voting-header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import cn from 'classnames';
import Erc20Contract from 'web3/erc20Contract';
import { formatBigValue, formatToken } from 'web3/utils';

import { MerkleDistributor, useAirdrop } from 'airdrop/airdrop';
import { MerkleDistributor } from 'airdrop/airdrop';
import Button from 'components/antd/button';
import Modal from 'components/antd/modal';
import Skeleton from 'components/antd/skeleton';
import Tooltip from 'components/antd/tooltip';
import { ExternalLink } from 'components/button';
import Grid from 'components/custom/grid';
import { Hint, Text } from 'components/custom/typography';
import { useConfig } from 'components/providers/configProvider';
import { useKnownTokens } from 'components/providers/knownTokensProvider';
import { TokenIcon } from 'components/token-icon';
import { UseLeftTime } from 'hooks/useLeftTime';
Expand All @@ -30,19 +29,13 @@ import s from './s.module.scss';
const VotingHeader: React.FC = () => {
const daoCtx = useDAO();
const walletCtx = useWallet();
const config = useConfig();
const { projectToken } = useKnownTokens();

const [showDetailedView, setShowDetailedView] = useState(false);
const [claimModalVisible, setClaimModalVisible] = useState(false);
const [claimingReward, setClaimingReward] = useState<DaoRewardContract | MerkleDistributor | undefined>();

const airdropDaoConfig = config.contracts.airdrop?.dao;
const merkleDistributor = useAirdrop(airdropDaoConfig?.merkleDistributor, airdropDaoConfig?.data);

const toClaimReward = merkleDistributor?.toClaim;
const { toClaim: toClaimReward2 } = daoCtx.daoReward2 ?? {};
const totalToClaim = toClaimReward?.plus(toClaimReward2 ?? 0);
const totalToClaim = daoCtx.daoReward.toClaim?.plus(daoCtx.airdrop?.toClaim ?? 0);

const projectTokenBalance = (projectToken.contract as Erc20Contract).balance?.unscaleBy(projectToken.decimals);
const { votingPower, userLockedUntil } = daoCtx.daoBarn;
Expand All @@ -61,12 +54,12 @@ const VotingHeader: React.FC = () => {
}

function handleClaim() {
if (toClaimReward?.gt(0) && toClaimReward2?.gt(0)) {
if (daoCtx.daoReward.toClaim?.gt(0) && daoCtx.airdrop?.toClaim?.gt(0)) {
setClaimModalVisible(true);
} else if (toClaimReward?.gt(0) && merkleDistributor) {
handleRewardClaim(merkleDistributor);
} else if (toClaimReward2?.gt(0) && daoCtx.daoReward2) {
handleRewardClaim(daoCtx.daoReward2);
} else if (daoCtx.airdrop?.toClaim?.gt(0) && daoCtx.airdrop) {
handleRewardClaim(daoCtx.airdrop);
} else if (daoCtx.daoReward.toClaim?.gt(0) && daoCtx.daoReward) {
handleRewardClaim(daoCtx.daoReward);
}
}

Expand Down Expand Up @@ -214,7 +207,7 @@ const VotingHeader: React.FC = () => {
</Text>
</div>
<div className="flex flow-row row-gap-24">
{[merkleDistributor, daoCtx.daoReward2].map((reward, rewardIndex) =>
{[daoCtx.airdrop, daoCtx.daoReward].map((reward, rewardIndex) =>
reward ? (
<Spin key={reward.address} spinning={claimingReward === reward}>
<button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const VotingStatList: React.FC<VotingStatListProps> = props => {
}, []);

const apr = daoCtx.daoBarn.bondStaked
? daoCtx.activeDaoReward?.weeklyRewards?.multipliedBy(52).dividedBy(daoCtx.daoBarn.bondStaked)
? daoCtx.daoReward?.weeklyRewards?.multipliedBy(52).dividedBy(daoCtx.daoBarn.bondStaked)
: undefined;

return (
Expand Down Expand Up @@ -146,31 +146,31 @@ const VotingStatList: React.FC<VotingStatListProps> = props => {
</Grid>
</div>

{daoCtx.activeDaoReward && (
{daoCtx.daoReward && (
<div className="card p-24">
<Grid flow="row" gap={48}>
<Hint
text={
<Text type="p2">
This number shows the ${projectToken.symbol} token rewards distributed so far out of the total of{' '}
{formatToken(daoCtx.activeDaoReward.pullFeature?.totalAmount)} that are going to be available for the
DAO Staking.
{formatToken(daoCtx.daoReward.pullFeature?.totalAmount)} that are going to be available for the DAO
Staking.
</Text>
}>
<Text type="lb2" weight="semibold" color="red">
{projectToken.symbol} Rewards
</Text>
</Hint>
<Grid flow="row" gap={4}>
<UseLeftTime end={(daoCtx.activeDaoReward.pullFeature?.endTs ?? 0) * 1000} delay={5_000}>
<UseLeftTime end={(daoCtx.daoReward.pullFeature?.endTs ?? 0) * 1000} delay={5_000}>
{() => (
<Text type="h2" weight="bold" color="primary" wrap>
{formatToken(daoCtx.activeDaoReward?.bondRewards)}
{formatToken(daoCtx.daoReward?.bondRewards)}
</Text>
)}
</UseLeftTime>
<Text type="p1" color="secondary">
out of {formatToken(daoCtx.activeDaoReward.pullFeature?.totalAmount)}
out of {formatToken(daoCtx.daoReward.pullFeature?.totalAmount)}
</Text>
</Grid>
</Grid>
Expand Down Expand Up @@ -238,7 +238,7 @@ const VotingStatList: React.FC<VotingStatListProps> = props => {
</Grid>
</div>

{daoCtx.activeDaoReward && (
{daoCtx.daoReward && (
<>
<div className="card p-24">
<Grid flow="row" gap={48}>
Expand All @@ -259,7 +259,7 @@ const VotingStatList: React.FC<VotingStatListProps> = props => {
</Text>
<Grid flow="row" gap={4}>
<Text type="h2" weight="bold" color="primary" wrap>
{formatToken(daoCtx.activeDaoReward.weeklyRewards) ?? '-'}
{formatToken(daoCtx.daoReward.weeklyRewards) ?? '-'}
</Text>
</Grid>
</Grid>
Expand Down
44 changes: 17 additions & 27 deletions src/modules/yield-farming/components/dao-reward-card/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { FC, useEffect, useMemo, useState } from 'react';
import React, { FC, useEffect, useState } from 'react';
import { Link } from 'react-router-dom';
import { formatPercent, formatToken } from 'web3/utils';

import { useAirdrop } from 'airdrop/airdrop';
import StatusTag from 'components/custom/status-tag';
import { Tabs as ElasticTabs } from 'components/custom/tabs';
import { Text } from 'components/custom/typography';
Expand All @@ -18,7 +19,7 @@ import { useWallet } from 'wallets/walletProvider';
const DaoRewardCard: FC<{}> = () => {
const config = useConfig();
const wallet = useWallet();
const [reload, version] = useReload();
const [reload] = useReload();

const [activeTab, setActiveTab] = useState('dao');

Expand Down Expand Up @@ -48,36 +49,25 @@ const DaoRewardCard: FC<{}> = () => {
},
);

const daoReward2 = config.contracts.dao?.reward2
? getOrCreateContract(
config.contracts.dao?.reward2,
() => {
return new DaoRewardContract(config.contracts.dao?.reward2!);
},
{
afterInit: contract => {
contract.onUpdateData(reload);
contract.loadCommonData().catch(Error);
},
},
)
: undefined;

const activeDaoReward = useMemo(() => {
return [daoReward, daoReward2].find(rw => rw && rw.isStarted && !rw.isEnded);
}, [daoReward, daoReward2, version]);
const airdropDaoConfig = config.contracts.airdrop?.dao;
const airdrop = useAirdrop(airdropDaoConfig?.merkleDistributor, airdropDaoConfig?.data);

const apr = daoBarnContract.bondStaked
? activeDaoReward?.weeklyRewards?.multipliedBy(52).dividedBy(daoBarnContract.bondStaked)
? daoReward?.weeklyRewards?.multipliedBy(52).dividedBy(daoBarnContract.bondStaked)
: undefined;

const totalToClaim = daoReward?.toClaim?.plus(airdrop?.toClaim ?? 0);

useEffect(() => {
if (wallet.account) {
daoBarnContract.setAccount(wallet.account);
daoBarnContract.loadUserData().catch(Error);

activeDaoReward?.setAccount(wallet.account);
activeDaoReward?.loadUserData().catch(Error);
daoReward?.setAccount(wallet.account);
daoReward?.loadUserData().catch(Error);

airdrop?.setAccount(wallet.account);
airdrop?.loadUserData().catch(Error);
}
}, [wallet.account]);

Expand All @@ -93,7 +83,7 @@ const DaoRewardCard: FC<{}> = () => {
DAO Rewards
</Text>

{activeDaoReward?.isEnded === false && (
{daoReward?.isEnded === false && (
<StatusTag
text={
<Text type="lb2" weight="bold" color="green">
Expand All @@ -103,7 +93,7 @@ const DaoRewardCard: FC<{}> = () => {
color="green"
/>
)}
{activeDaoReward?.isEnded && (
{daoReward?.isEnded && (
<StatusTag
text={
<Text type="lb2" weight="bold" color="green">
Expand Down Expand Up @@ -161,7 +151,7 @@ const DaoRewardCard: FC<{}> = () => {
<div className="flex align-center">
<TokenIcon name={ProjectToken.icon} size={16} className="mr-8" />
<Text type="p1" weight="semibold" color="primary">
{formatToken(activeDaoReward?.weeklyRewards) ?? '-'}
{formatToken(daoReward?.weeklyRewards) ?? '-'}
</Text>
</div>
</div>
Expand All @@ -187,7 +177,7 @@ const DaoRewardCard: FC<{}> = () => {
<div className="flex align-center">
<TokenIcon name={ProjectToken.icon} size={16} className="mr-8" />
<Text type="p1" weight="semibold" color="primary">
{formatToken(activeDaoReward?.toClaim) ?? '-'}
{formatToken(totalToClaim) ?? '-'}
</Text>
</div>
</div>
Expand Down
3 changes: 1 addition & 2 deletions src/networks/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ export const MainnetConfig: NetworkConfig = {
dao: {
governance: '0x4cAE362D7F227e3d306f70ce4878E245563F3069',
barn: '0x10e138877df69Ca44Fdc68655f86c88CDe142D7F',
reward: '0x9d0CF50547D848cC4b6A12BeDCF7696e9b334a22',
reward2: '0x85B86b749aD4B898407aC3c86DbA8d13E652e521',
reward: '0x85B86b749aD4B898407aC3c86DbA8d13E652e521',
},
se: {
ePoolPeriphery: '0x33c8d6f8271675eda1a0e72558d4904c96c7a888',
Expand Down
1 change: 0 additions & 1 deletion src/networks/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export type NetworkConfig = {
governance: string;
barn: string;
reward: string;
reward2?: string;
};
se?: Record<'ePoolPeriphery' | 'ePoolHelper', string>;
sa?: {
Expand Down

0 comments on commit 966c608

Please sign in to comment.