Removing old frontend code related to truffle box
This commit is contained in:
parent
b30d2b40e4
commit
d24370b877
137
src/App.js
137
src/App.js
|
@ -1,8 +1,7 @@
|
||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import { Form, Field } from 'react-final-form'
|
import { Form } from 'react-final-form'
|
||||||
import Safe from '../gnosis-safe-contracts/build/contracts/GnosisSafe.json'
|
import Safe from '../gnosis-safe-contracts/build/contracts/GnosisSafe.json'
|
||||||
import SimpleStorageContract from '../build/contracts/SimpleStorage.json'
|
import getWeb3, { promisify } from './utils/getWeb3'
|
||||||
import getWeb3 from './utils/getWeb3'
|
|
||||||
import contract from 'truffle-contract'
|
import contract from 'truffle-contract'
|
||||||
import './css/oswald.css'
|
import './css/oswald.css'
|
||||||
import './css/open-sans.css'
|
import './css/open-sans.css'
|
||||||
|
@ -22,113 +21,43 @@ class App extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
// Get network provider and web3 instance.
|
getWeb3.then(results => {
|
||||||
// See utils/getWeb3 for more info.
|
const web3 = results.web3
|
||||||
|
this.safe.setProvider(web3.currentProvider)
|
||||||
getWeb3
|
this.setState({web3})
|
||||||
.then(results => {
|
|
||||||
this.setState({
|
|
||||||
web3: results.web3
|
|
||||||
})
|
|
||||||
|
|
||||||
// Instantiate contract once web3 provided.
|
|
||||||
//this.instantiateContract()
|
|
||||||
this.createSafe()
|
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
console.log('Error finding web3.')
|
console.log('Error finding web3.')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
createSafe() {
|
onCallSafeContractSubmit = async () => {
|
||||||
this.safe.setProvider(this.state.web3.currentProvider)
|
try {
|
||||||
|
const web3 = this.state.web3
|
||||||
/*let safeInstance
|
const accounts = await promisify(cb => web3.eth.getAccounts(cb))
|
||||||
|
const safeInstance = await this.safe.new([accounts[0]], 1, 0, 0, { from: accounts[0], gas: '5000000' })
|
||||||
// Get accounts.
|
const transactionHash = safeInstance.transactionHash
|
||||||
this.state.web3.eth.getAccounts((error, accounts) => {
|
// const transaction = await promisify(cb => web3.eth.getTransaction(transactionHash, cb))
|
||||||
safe.deployed().then((instance) => {
|
// console.log("Transaction" + JSON.stringify(transaction, 2, 0))
|
||||||
safeInstance = instance
|
const transactionReceipt = await promisify(cb => web3.eth.getTransactionReceipt(transactionHash, cb))
|
||||||
debugger
|
console.log("Transaction Receipt" + JSON.stringify(transactionReceipt, 2, 0))
|
||||||
// Stores a given value, 5 by default.
|
} catch (error) {
|
||||||
//return simpleStorageInstance.set(5, {from: accounts[0]})
|
console.log("Error while creating the Safe")
|
||||||
})/*.then((result) => {
|
}
|
||||||
// Get the value from the contract to prove it worked.
|
|
||||||
return simpleStorageInstance.get.call(accounts[0])
|
|
||||||
}).then((result) => {
|
|
||||||
// Update state with the result.
|
|
||||||
return this.setState({ storageValue: result.c[0] })
|
|
||||||
})
|
|
||||||
})*/
|
|
||||||
}
|
|
||||||
|
|
||||||
instantiateContract() {
|
|
||||||
/*
|
|
||||||
* SMART CONTRACT EXAMPLE
|
|
||||||
*
|
|
||||||
* Normally these functions would be called in the context of a
|
|
||||||
* state management library, but for convenience I've placed them here.
|
|
||||||
*/
|
|
||||||
|
|
||||||
//const contract = require('truffle-contract')
|
|
||||||
const simpleStorage = contract(SimpleStorageContract)
|
|
||||||
simpleStorage.setProvider(this.state.web3.currentProvider)
|
|
||||||
|
|
||||||
// Declaring this for later so we can chain functions on SimpleStorage.
|
|
||||||
var simpleStorageInstance
|
|
||||||
|
|
||||||
// Get accounts.
|
|
||||||
this.state.web3.eth.getAccounts((error, accounts) => {
|
|
||||||
simpleStorage.deployed().then((instance) => {
|
|
||||||
simpleStorageInstance = instance
|
|
||||||
|
|
||||||
// Stores a given value, 5 by default.
|
|
||||||
return simpleStorageInstance.set(5, {from: accounts[0]})
|
|
||||||
}).then((result) => {
|
|
||||||
// Get the value from the contract to prove it worked.
|
|
||||||
return simpleStorageInstance.get.call(accounts[0])
|
|
||||||
}).then((result) => {
|
|
||||||
// Update state with the result.
|
|
||||||
return this.setState({ storageValue: result.c[0] })
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
|
|
||||||
|
|
||||||
onCallSafeContractSubmit = () => {
|
|
||||||
|
|
||||||
this.state.web3.eth.getAccounts((error, accounts) => {
|
|
||||||
debugger
|
|
||||||
this.safe.new([accounts[0]], 1, 0, 0, { from: accounts[0], gas: '5000000' })
|
|
||||||
.then( async (instance) => {
|
|
||||||
console.log("transactionHash -> " + instance.transactionHash)
|
|
||||||
console.log("adress -> " + instance.address)
|
|
||||||
this.state.web3.eth.getTransaction(instance.transactionHash, (err, result) => {
|
|
||||||
console.log(result);
|
|
||||||
})
|
|
||||||
console.log("")
|
|
||||||
});
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
onCreateBoxSubmit = async values => {
|
|
||||||
await this.sleep(300)
|
|
||||||
window.alert("Creating a new box " + JSON.stringify(values, 2, 0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div className="App">
|
<div className="App">
|
||||||
<nav className="navbar pure-menu pure-menu-horizontal">
|
<nav className="navbar pure-menu pure-menu-horizontal">
|
||||||
<a href="#" className="pure-menu-heading pure-menu-link">Truffle Box</a>
|
<a href="#" className="pure-menu-heading pure-menu-link">Gnosis Multisig 2.0</a>
|
||||||
</nav>
|
</nav>
|
||||||
<main className="container">
|
<main className="container">
|
||||||
<Form
|
<Form
|
||||||
onSubmit={this.onCallSafeContractSubmit}
|
onSubmit={this.onCallSafeContractSubmit}
|
||||||
render={({ handleSubmit, pristine, invalid }) => (
|
render={({ handleSubmit, pristine, invalid }) => (
|
||||||
<form onSubmit={handleSubmit}>
|
<form onSubmit={handleSubmit}>
|
||||||
<h2>Create a new instance for testing purposes</h2>
|
<h2>Create a new Safe instance for testing purposes</h2>
|
||||||
<div>
|
<div>
|
||||||
<button style={{ marginLeft: '10px', border: '1px solid #ccc' }} type="submit">
|
<button style={{ marginLeft: '10px', border: '1px solid #ccc' }} type="submit">
|
||||||
Submit
|
Submit
|
||||||
|
@ -136,30 +65,6 @@ class App extends Component {
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
)} />
|
)} />
|
||||||
<Form
|
|
||||||
onSubmit={this.onCreateBoxSubmit}
|
|
||||||
render={({ handleSubmit, pristine, invalid }) => (
|
|
||||||
<form onSubmit={handleSubmit}>
|
|
||||||
<h2>Create your instance of a Safe Box</h2>
|
|
||||||
<div>
|
|
||||||
<label style={ { marginRight: '10px' }}>Owner Address</label>
|
|
||||||
<Field name="owner" component="input" placeholder="Safe owner address" />
|
|
||||||
<button style={{ marginLeft: '10px', border: '1px solid #ccc' }} type="submit" disabled={pristine || invalid}>
|
|
||||||
Submit
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
)} />
|
|
||||||
<div className="pure-g">
|
|
||||||
<div className="pure-u-1-1">
|
|
||||||
<h1>Good to Go!</h1>
|
|
||||||
<p>Your Truffle Box is installed and ready.</p>
|
|
||||||
<h2>Smart Contract Example</h2>
|
|
||||||
<p>If your contracts compiled and migrated successfully, below will show a stored value of 5 (by default).</p>
|
|
||||||
<p>Try changing the value stored on <strong>line 59</strong> of App.js.</p>
|
|
||||||
<p>The stored value is: {this.state.storageValue}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -36,4 +36,15 @@ let getWeb3 = new Promise(function(resolve, reject) {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const promisify = (inner) =>
|
||||||
|
new Promise((resolve, reject) =>
|
||||||
|
inner((err, res) => {
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
} else {
|
||||||
|
resolve(res);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
export default getWeb3
|
export default getWeb3
|
||||||
|
|
Loading…
Reference in New Issue