Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
dimakorzhovnik committed Jan 20, 2020
1 parent 01e6516 commit 944334f
Show file tree
Hide file tree
Showing 9 changed files with 11,046 additions and 2 deletions.
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,478 changes: 9,478 additions & 0 deletions contracts/Vesting.json

Large diffs are not rendered by default.

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],
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
72 changes: 72 additions & 0 deletions src/containers/vesting/vesting.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import React, { PureComponent } from 'react';
import { Pane, Text } from '@cybercongress/gravity';
import { fromWei, toBN, toWei } from 'web3-utils';
import injectWeb3Vesting from '../../components/web3/web3Vesting';
import { Loading } from '../../components/index';
import {
run,
formatNumber,
roundNumber,
asyncForEach,
timer,
} from '../../utils/utils';

import { AUCTION } from '../../utils/config';
import VestingConstract from '../../../contracts/Vesting.json';
import TokenManager from '../../../contracts/TokenManager.json';
import Token from '../../../contracts/Token.json';

const {
ADDR_SMART_CONTRACT,
TOKEN_NAME,
TOPICS_SEND,
TOPICS_CLAIM,
ADDR_VESTING,
} = AUCTION;
const ROUND_DURATION = 1 * 60 * 60;

class Vesting extends PureComponent {
constructor(props) {
super(props);
this.state = {
table: [],
accounts: null,
balance: 0,
spendableBalance: 0,
};
}

componentDidMount() {
this.init();
}

init = async () => {
const { accounts, contractTokenManager, contractToken } = this.props;

console.log('accounts', accounts);

const balance = await contractToken.methods.balanceOf(accounts).call();
const spendableBalance = await contractTokenManager.methods
.spendableBalanceOf(accounts)
.call();

this.setState({
balance,
spendableBalance,
});
};

render() {
const { spendableBalance, balance } = this.state;
// console.log(table);
return (
<div>
<div>{spendableBalance}</div>
<div>{spendableBalance - balance}</div>
<div>{balance}</div>
</div>
);
}
}

export default injectWeb3Vesting(Vesting);
2 changes: 2 additions & 0 deletions src/router.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Validators from './containers/Validators/Validators';
import SearchResults from './containers/Search/SearchResults';
import Story from './containers/story/story';
import GOL from './containers/gol/gol';
import Vesting from './containers/vesting/vesting';

export const history = createHashHistory({});

Expand Down Expand Up @@ -58,6 +59,7 @@ class AppRouter extends React.Component {
<Route path="/heroes" component={Validators} />
<Route path="/episode-1" component={Story} />
<Route path="/gol" component={GOL} />
<Route path="/vesting" component={Vesting} />

<Route exact path="*" component={NotFound} />
</Switch>
Expand Down
4 changes: 3 additions & 1 deletion src/utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ const AUCTION = {
ADDR_SMART_CONTRACT: '0xc8a0b9d38d1301391fa593728cfaa2962bc72965',
ADDR_SMART_CONTRACT_AUCTION_UTILS:
'0x5095b56b6607724559d21bb4d2af0d9cdab64149',
ADDR_TOKEN: '0x6b5058b9314c76af2312a6f46ad9a54cf9b48f1c',
ADDR_TOKEN: '0xce09a0c3ff16a4f5d2c66cea9b89e3cc2cf5242b',
ADDR_TOKEN_MANAGER: '0x74a653b35970c16b766a541a3410900b0f5ff024',
ADDR_VESTING: '0x59d8149f1641d839ddd441cb0e4f9047a6c2b6a9',
TOKEN_NAME: 'GOL',
TOPICS_SEND:
'0xe054057d0479c6218d6ec87be73f88230a7e4e1f064cee6e7504e2c4cd9d6150',
Expand Down

0 comments on commit 944334f

Please sign in to comment.