-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
01e6516
commit 944334f
Showing
9 changed files
with
11,046 additions
and
2 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters