support using only abi & address; fix default from
This commit is contained in:
parent
4932b9c3bc
commit
45d13547c4
|
@ -4,7 +4,8 @@ import { $average, $max, $min, $latest } from "@status-im/subspace";
|
||||||
import { map } from 'rxjs/operators';
|
import { map } from 'rxjs/operators';
|
||||||
import ProductComponent from "./ProductComponent";
|
import ProductComponent from "./ProductComponent";
|
||||||
import web3 from './web3';
|
import web3 from './web3';
|
||||||
import ProductContract from './MyContract';
|
|
||||||
|
import {abi, address} from './contract.json'
|
||||||
|
|
||||||
let Product;
|
let Product;
|
||||||
|
|
||||||
|
@ -21,12 +22,10 @@ class App extends React.Component {
|
||||||
const subspace = new Subspace(web3.currentProvider);
|
const subspace = new Subspace(web3.currentProvider);
|
||||||
await subspace.init();
|
await subspace.init();
|
||||||
|
|
||||||
Product = await ProductContract.getInstance();
|
// Product = subspace.contract(ContractInstance); // would also work
|
||||||
Product = subspace.contract(Product)
|
Product = subspace.contract({abi, address});
|
||||||
const rating$ = Product.events.Rating.track().map("rating").pipe(map(x => parseInt(x)));
|
|
||||||
|
|
||||||
window.Product = Product;
|
const rating$ = Product.events.Rating.track().map("rating").pipe(map(x => parseInt(x)));
|
||||||
window.web3 = web3;
|
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
title: Product.methods.products(0).track().map('title'),
|
title: Product.methods.products(0).track().map('title'),
|
||||||
|
@ -47,7 +46,8 @@ class App extends React.Component {
|
||||||
};
|
};
|
||||||
|
|
||||||
sendFunds = async () => {
|
sendFunds = async () => {
|
||||||
await web3.eth.sendTransaction({value: this.state.contractFunds, to: Product.options.address});
|
let accounts = await web3.eth.getAccounts();
|
||||||
|
await web3.eth.sendTransaction({value: this.state.contractFunds, to: Product.options.address, from: accounts[0]});
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|
|
@ -61,6 +61,14 @@ export default class Subspace {
|
||||||
|
|
||||||
const SubspaceContract = new this.web3.Contract(abi, {from, gas});
|
const SubspaceContract = new this.web3.Contract(abi, {from, gas});
|
||||||
SubspaceContract.options.address = address;
|
SubspaceContract.options.address = address;
|
||||||
|
SubspaceContract.options.from = from;
|
||||||
|
|
||||||
|
if (!from) {
|
||||||
|
setTimeout(async () => {
|
||||||
|
const accounts = await web3.eth.getAccounts();
|
||||||
|
SubspaceContract.options.from = accounts[0];
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
|
||||||
SubspaceContract.trackEvent = (eventName, filterConditionsOrCb) => {
|
SubspaceContract.trackEvent = (eventName, filterConditionsOrCb) => {
|
||||||
return this.trackEvent(SubspaceContract, eventName, filterConditionsOrCb);
|
return this.trackEvent(SubspaceContract, eventName, filterConditionsOrCb);
|
||||||
|
|
Loading…
Reference in New Issue