Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vesting page #133

Merged
merged 10 commits into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
590 changes: 590 additions & 0 deletions contracts/MiniMeToken.json

Large diffs are not rendered by default.

759 changes: 759 additions & 0 deletions contracts/TokenManager.json

Large diffs are not rendered by default.

9,434 changes: 9,434 additions & 0 deletions contracts/Vesting.json

Large diffs are not rendered by default.

31 changes: 16 additions & 15 deletions src/components/ledger/stageActionBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
Textarea,
} from '@cybercongress/gravity';
import { ContainetLedger, Loading, FormatNumber } from '../index';
import { formatNumber } from '../../utils/search/utils';
import { formatNumber } from '../../utils/utils';

import { i18n } from '../../i18n/en';

Expand Down Expand Up @@ -82,7 +82,7 @@ export const Confirmed = ({
txHeight,
onClickBtn,
onClickBtnCloce,
explorer
explorer,
}) => (
<ContainetLedger onClickBtnCloce={onClickBtnCloce}>
<span className="font-size-20 display-inline-block text-align-center">
Expand Down Expand Up @@ -531,6 +531,7 @@ export const Delegate = ({
onChangeInputAmount,
toSend,
disabledBtn,
delegate,
}) => (
<ContainetLedger onClickBtnCloce={onClickBtnCloce}>
<Pane display="flex" flexDirection="column" alignItems="center">
Expand All @@ -543,11 +544,15 @@ export const Delegate = ({
{address}
</Text>
<Text fontSize="30px" lineHeight="40px" color="#fff">
{T.actionBar.delegate.details}
{delegate
? T.actionBar.delegate.details
: T.actionBar.delegate.detailsUnDelegate}
</Text>

<Text fontSize="18px" lineHeight="30px" color="#fff">
{T.actionBar.delegate.wallet}
{delegate
? T.actionBar.delegate.wallet
: T.actionBar.delegate.yourDelegated}
</Text>
<Text
display="flex"
Expand All @@ -558,19 +563,17 @@ export const Delegate = ({
>
<FormatNumber
marginRight={5}
number={formatNumber(
Math.floor((balance / DIVISOR_CYBER_G) * 1000) / 1000,
3
)}
number={formatNumber(balance / DIVISOR_CYBER_G, 6)}
/>
{(DENOM_CYBER_G + DENOM_CYBER).toUpperCase()}
{DENOM_CYBER_G.toUpperCase()}
</Text>

<Pane marginTop={20}>
<Text fontSize="16px" color="#fff">
{T.actionBar.delegate.enterAmount}{' '}
{(DENOM_CYBER_G + DENOM_CYBER).toUpperCase()}{' '}
{T.actionBar.delegate.delegate.toLowerCase()}{' '}
{T.actionBar.delegate.enterAmount} {DENOM_CYBER_G.toUpperCase()}{' '}
{delegate
? T.actionBar.delegate.delegate
: T.actionBar.delegate.unDelegateFrom}{' '}
<Text fontSize="20px" color="#fff" fontWeight={600}>
{moniker}
</Text>
Expand Down Expand Up @@ -694,9 +697,7 @@ export const SendLedgerAtomTot = ({
<p className="text-align-center">{T.actionBar.send.wallet}</p>
<span className="actionBar-text">{availableStake}</span>

<div
style={{ marginBottom: 30, marginTop: 30 }}
>
<div style={{ marginBottom: 30, marginTop: 30 }}>
<div style={{ marginBottom: 10 }}>
<span style={{ marginRight: 10 }}>address to:</span>
<span>{addressTo}</span>
Expand Down
137 changes: 137 additions & 0 deletions src/components/web3/web3Vesting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import React, { PureComponent } from 'react';
import waitForWeb3 from './waitForWeb3';

import Token from '../../../contracts/Token.json';
import Auction from '../../../contracts/Auction.json';
import VestingConstract from '../../../contracts/Vesting.json';
import TokenManager from '../../../contracts/TokenManager.json';

import { Loading } from '../index';
import NotFound from '../../containers/application/notFound';

import { AUCTION } from '../../utils/config';

const injectWeb3Vesting = InnerComponent =>
class extends PureComponent {
constructor(props) {
super(props);
this.state = {
web3: null,
contractVesting: null,
loading: true,
accounts: null,
networkId: null,
buyTransactionSuccess: false,
isCorrectNetwork: true,
contractTokenManager: null,
contractToken: null,
};
this.getWeb3 = this.getWeb3.bind(this);
this.smartVesting = AUCTION.ADDR_VESTING;
}

componentDidMount() {
this.getWeb3().then(() => this.setState({ loading: false }));
// this.checkBuy();
}

async getWeb3() {
await window.ethereum.enable();
try {
const web3 = await waitForWeb3();

const contractVesting = await new web3.eth.Contract(
VestingConstract.abi,
this.smartVesting
);

const tokenManagerAddress = await contractVesting.methods
.tokenManager()
.call();

const contractTokenManager = await new web3.eth.Contract(
TokenManager.abi,
tokenManagerAddress
);

const tokenAddress = await contractTokenManager.methods.token().call();

const contractToken = await new web3.eth.Contract(
Token.abi,
tokenAddress
);
if (web3.givenProvider === null) {
this.setState({
web3,
contractVesting,
contractTokenManager,
contractToken,
accounts: null,
networkId: null,
isCorrectNetwork: true,
});
} else {
const networkContract = Object.keys(Auction.networks);
const networkId = await web3.eth.net.getId();
const accounts = await web3.eth.getAccounts();

this.setState({
web3,
contractVesting,
contractTokenManager,
contractToken,
accounts: accounts[0].toLowerCase(),
networkId,
isCorrectNetwork: networkContract.indexOf(`${networkId}`) !== -1,
});
}
} catch (e) {
this.setState({ loading: false });
}
}

render() {
const {
web3,
loading,
accounts,
isCorrectNetwork,
contractVesting,
contractTokenManager,
contractToken,
} = this.state;
// if (!isCorrectNetwork) {
// return (
// <NotFound text="Please connect to the Ethereum Rinkeby Network" />
// );
// }
if (loading) {
return (
<div
style={{
width: '100%',
height: '50vh',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
}}
>
<Loading />
</div>
);
}

return (
<InnerComponent
web3={web3}
accounts={accounts}
contractVesting={contractVesting}
contractTokenManager={contractTokenManager}
contractToken={contractToken}
{...this.props}
/>
);
}
};

export default injectWeb3Vesting;
3 changes: 2 additions & 1 deletion src/components/web3/withWeb3.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const {
ADDR_SMART_CONTRACT,
ADDR_SMART_CONTRACT_AUCTION_UTILS,
ADDR_TOKEN,
ADDR_TOKEN_MANAGER,
} = AUCTION;

const injectWeb3 = InnerComponent =>
Expand All @@ -35,6 +36,7 @@ const injectWeb3 = InnerComponent =>
this.smart = ADDR_SMART_CONTRACT;
this.smartAuctionUtils = ADDR_SMART_CONTRACT_AUCTION_UTILS;
this.tokenAdrrs = ADDR_TOKEN;
this.tokenManager = ADDR_TOKEN_MANAGER;
}

componentDidMount() {
Expand All @@ -45,7 +47,6 @@ const injectWeb3 = InnerComponent =>
async getWeb3() {
try {
const web3 = await waitForWeb3();
console.log('web3.givenProvider', web3);
const contract = await new web3.eth.Contract(Auction.abi, this.smart);
const contractAuctionUtils = await new web3.eth.Contract(
AuctionUtils.abi,
Expand Down
3 changes: 3 additions & 0 deletions src/containers/Search/ActionBarContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,9 @@ class ActionBarContainer extends Component {
txHeight,
txHash,
} = this.state;

console.log('bandwidth', bandwidth);

const { valueSearchInput } = this.props;

if (stage === STAGE_INIT) {
Expand Down
Loading