From 470f0586d99a75725b1e95b9257f3dc078f9a4b8 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Thu, 3 Oct 2019 16:02:20 -0400 Subject: [PATCH] feat: extend methods --- examples/react-example1/src/App.js | 2 +- src/subspace.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/examples/react-example1/src/App.js b/examples/react-example1/src/App.js index a5cdd8f..f203d27 100644 --- a/examples/react-example1/src/App.js +++ b/examples/react-example1/src/App.js @@ -29,7 +29,7 @@ class App extends React.Component { window.web3 = web3; this.setState({ - title: Product.trackProperty("products", 0).map('title'), + title: Product.methods.products(0).track().map('title'), averageRating: rating$.pipe($average()), minRating: rating$.pipe($min()), maxRating: rating$.pipe($max()), diff --git a/src/subspace.js b/src/subspace.js index faa914d..6b6e3b1 100644 --- a/src/subspace.js +++ b/src/subspace.js @@ -74,6 +74,19 @@ export default class Subspace { return this.trackProperty(SubspaceContract, propName, methodArgs, callArgs); } + Object.keys(SubspaceContract.methods).forEach(methodName => { + const oldFunc = SubspaceContract.methods[methodName]; + + const _this = this; + const newFunc = function(){ + const txObject = oldFunc.apply(null, arguments); + txObject.track = (callArgs) => _this.trackProperty(SubspaceContract, methodName, txObject.arguments, callArgs); + return txObject; + } + + SubspaceContract.methods[methodName] = newFunc; + }); + SubspaceContract.trackBalance = (erc20Address) => { return this.trackBalance(SubspaceContract.options.address, erc20Address); }