-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add lerna and update react example
- Loading branch information
1 parent
50c125f
commit 97019ee
Showing
48 changed files
with
8,185 additions
and
4,456 deletions.
There are no files selected for viewing
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 @@ | ||
SKIP_PREFLIGHT_CHECK=true |
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,12 @@ | ||
const { | ||
override, | ||
addWebpackAlias, | ||
} = require("customize-cra"); | ||
|
||
const path = require('path'); | ||
|
||
module.exports = override( | ||
addWebpackAlias({ | ||
react: path.resolve('./node_modules/react') | ||
}) | ||
) |
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 |
---|---|---|
@@ -1,47 +1,54 @@ | ||
import React from "react"; | ||
import Subspace from "@embarklabs/subspace"; | ||
import { scan } from 'rxjs/operators'; | ||
import React, {useState, useEffect} from "react"; | ||
import Web3 from "web3"; | ||
import { SubspaceProvider, useSubspace } from "@embarklabs/subspace-react"; | ||
import MyComponentObserver from "./MyComponentObserver"; | ||
import web3 from './web3'; | ||
import MyContract from './MyContract'; | ||
import getInstance from "./ContractDeployer"; | ||
|
||
let MyContractInstance; | ||
const Form = () => { | ||
const subspace = useSubspace(); | ||
const [MyContractInstance, setContractInstance] = useState(); | ||
const [myObservable$, setObservable] = useState(); | ||
|
||
class App extends React.Component { | ||
state = { | ||
myEventObservable$: null | ||
}; | ||
|
||
async componentDidMount() { | ||
MyContractInstance = await MyContract.getInstance(); // | ||
useEffect(() => { | ||
getInstance(subspace.web3).then(instance => { | ||
setContractInstance(subspace.contract(instance)); | ||
}); | ||
}, [subspace]); | ||
|
||
const subspace = new Subspace(web3.currentProvider); | ||
await subspace.init(); | ||
|
||
const myEventObservable$ = subspace.trackEvent(MyContractInstance, "MyEvent", {filter: {}, fromBlock: 1 }); | ||
useEffect(() => { | ||
if (!MyContractInstance) return; | ||
const observable = MyContractInstance.events.MyEvent.track({filter: {}, fromBlock: 1}); | ||
|
||
// If you want to return all the events in an array, you can pipe the scan operator to the observable | ||
// const myEventObservable$ = subspace.trackEvent(MyContractInstance, "MyEvent", {filter: {}, fromBlock: 1 }) | ||
// .pipe(scan((accum, val) => [...accum, val], [])); | ||
// const observable = MyContractInstance.events.MyEvent.track({filter: {}, fromBlock: 1}) | ||
// .pipe(scan((accum, val) => [...accum, val], [])); | ||
// | ||
// Your observable component would receive the eventData as an array instead of an object | ||
|
||
this.setState({ myEventObservable$ }); | ||
} | ||
setObservable(observable); | ||
}, [subspace, MyContractInstance]); | ||
|
||
createTrx = () => { | ||
MyContractInstance.methods | ||
.myFunction() | ||
.send({ from: web3.eth.defaultAccount }); | ||
const createTrx = () => { | ||
if(!MyContractInstance) return; | ||
MyContractInstance.methods.myFunction().send({from: subspace.web3.eth.defaultAccount}); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<button onClick={this.createTrx}>Create a Transaction</button> | ||
<MyComponentObserver eventData={this.state.myEventObservable$} /> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div> | ||
<button onClick={createTrx} disabled={!MyContractInstance}>Create a Transaction</button> | ||
<MyComponentObserver eventData={myObservable$} /> | ||
</div> | ||
); | ||
} | ||
|
||
|
||
const App = () => { | ||
const web3 = new Web3("ws://localhost:8545"); | ||
return ( | ||
<SubspaceProvider web3={web3}> | ||
<Form /> | ||
</SubspaceProvider> | ||
); | ||
}; | ||
|
||
export default App; |
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
Oops, something went wrong.