1
0
mirror of https://github.com/kremalicious/blog.git synced 2025-01-05 03:15:07 +01:00

downgrade to Web3 0.20.7

This commit is contained in:
Matthias Kretschmann 2018-10-11 23:18:03 +02:00
parent 314b7bf855
commit 6ad87ca1d6
Signed by: m
GPG Key ID: 606EEEF3C479A91F
3 changed files with 33 additions and 21 deletions

View File

@ -7,9 +7,7 @@ cache:
- public - public
install: install:
- npm install -g scrypt
- npm i - npm i
- ln -s ./node_modules/scrypt /usr/local/lib/node_modules/scrypt/build
script: script:
- npm test - npm test

View File

@ -72,7 +72,7 @@
"react-time": "^4.3.0", "react-time": "^4.3.0",
"react-transition-group": "^2.5.0", "react-transition-group": "^2.5.0",
"slugify": "^1.3.1", "slugify": "^1.3.1",
"web3": "^1.0.0-beta.36" "web3": "^0.20.7"
}, },
"devDependencies": { "devDependencies": {
"@babel/node": "^7.0.0", "@babel/node": "^7.0.0",

View File

@ -13,7 +13,8 @@ export default class Web3Donation extends PureComponent {
networkId: null, networkId: null,
accounts: [], accounts: [],
selectedAccount: null, selectedAccount: null,
receipt: '', receipt: null,
transactionHash: null,
loading: false, loading: false,
error: null error: null
} }
@ -31,7 +32,8 @@ export default class Web3Donation extends PureComponent {
// no web3 // no web3
this.setState({ web3Connected: false }) this.setState({ web3Connected: false })
} else { } else {
this.web3 = new Web3(Web3.givenProvider || 'ws://localhost:8546') // this.web3 = new Web3(Web3.givenProvider || 'ws://localhost:8546')
this.web3 = new Web3(window.web3.currentProvider)
this.setState({ web3Connected: true }) this.setState({ web3Connected: true })
this.fetchAccounts() this.fetchAccounts()
@ -64,7 +66,8 @@ export default class Web3Donation extends PureComponent {
web3 && web3 &&
web3.eth && web3.eth &&
web3.eth.net.getId((err, netId) => { //web3.eth.net.getId((err, netId) => {
web3.version.getNetwork((err, netId) => {
if (err) { if (err) {
this.setState({ networkError: err }) this.setState({ networkError: err })
} }
@ -100,18 +103,31 @@ export default class Web3Donation extends PureComponent {
this.setState({ loading: true }) this.setState({ loading: true })
web3.eth // web3.eth
.sendTransaction({ // .sendTransaction({
// from: this.state.selectedAccount,
// to: this.props.address,
// value: '10000000000000000'
// })
// .then(receipt => {
// this.setState({ receipt, loading: false })
// })
// .catch(error => {
// this.setState({ error, loading: false })
// })
web3.eth.sendTransaction(
{
from: this.state.selectedAccount, from: this.state.selectedAccount,
to: this.props.address, to: this.props.address,
value: '10000000000000000' value: '10000000000000000'
}) },
.then(receipt => { (error, transactionHash) => {
this.setState({ receipt, loading: false }) if (error) this.setState({ error, loading: false })
}) if (!transactionHash) this.setState({ loading: true })
.catch(error => { this.setState({ transactionHash, loading: false })
this.setState({ error, loading: false }) }
}) )
} }
render() { render() {
@ -129,7 +145,7 @@ export default class Web3Donation extends PureComponent {
className="btn btn-primary" className="btn btn-primary"
onClick={this.handleWeb3Button} onClick={this.handleWeb3Button}
disabled={ disabled={
!(this.state.networkId === 1) || !this.state.selectedAccount !(this.state.networkId === '1') || !this.state.selectedAccount
} }
> >
Make it rain 0.01 Ξ Make it rain 0.01 Ξ
@ -143,7 +159,7 @@ export default class Web3Donation extends PureComponent {
</div> </div>
)} )}
{this.state.networkId !== 1 && ( {this.state.networkId !== '1' && (
<div className={styles.alert}>Please connect to Main network</div> <div className={styles.alert}>Please connect to Main network</div>
)} )}
@ -151,14 +167,12 @@ export default class Web3Donation extends PureComponent {
<div className={styles.alert}>{this.state.error.message}</div> <div className={styles.alert}>{this.state.error.message}</div>
)} )}
{this.state.receipt.status && ( {this.state.transactionHash && (
<div className={styles.success}> <div className={styles.success}>
You are awesome, thanks! You are awesome, thanks!
<br /> <br />
<a <a
href={`https://etherscan.io/tx/${ href={`https://etherscan.io/tx/${this.state.transactionHash}`}
this.state.receipt.transactionHash
}`}
> >
See your transaction on etherscan.io. See your transaction on etherscan.io.
</a> </a>