diff --git a/contracts/YourContract/YourContract.sol b/contracts/YourContract/YourContract.sol new file mode 100644 index 000000000..c0fab3cea --- /dev/null +++ b/contracts/YourContract/YourContract.sol @@ -0,0 +1,27 @@ +pragma solidity ^0.4.24; + +contract YourContract { + + string public YourVar = "HELLO WORLD"; + address public owner; + mapping (uint256 => string) public chat; + uint256 public messageCount; + + constructor() public { + owner = msg.sender; + messageCount = 0; + } + + function updateVar(string newVal) public returns (bool) { + require(msg.sender==owner,"YourContract::updateVar not owner"); + YourVar=newVal; + return true; + } + + function sendMessage(string message) public returns (bool) { + chat[messageCount] = message; + messageCount = messageCount + 1; + return true; + } + +} diff --git a/src/App.js b/src/App.js index 55965f262..c7fc85f1e 100644 --- a/src/App.js +++ b/src/App.js @@ -1344,7 +1344,7 @@ render() { return (
- +
diff --git a/src/components/YourModule.js b/src/components/YourModule.js index d23d56e54..ebfc668bd 100644 --- a/src/components/YourModule.js +++ b/src/components/YourModule.js @@ -3,6 +3,7 @@ import { Events, Blockie, Scaler } from "dapparatus"; import Web3 from 'web3'; import Ruler from "./Ruler"; import axios from "axios" +const QRCode = require('qrcode.react'); export default class YourModule extends React.Component { @@ -14,6 +15,10 @@ export default class YourModule extends React.Component { YourContract: false, yourContractBalance: 0, toAddress: (props.scannerState ? props.scannerState.toAddress : ""), + message: "", + messageCount: 0, + chat: [], + yourContractAddress: false, } } @@ -33,21 +38,29 @@ export default class YourModule extends React.Component { console.log("YOURCONTRACT IS LOADED:",this.state.YourContract) }) - setInterval(this.pollInterval.bind(this),2500) + setInterval(this.pollInterval.bind(this),10000) setTimeout(this.pollInterval.bind(this),30) - } - +} async pollInterval(){ console.log("POLL") - if(this.state && this.state.YourContract){ - let yourVar = await this.state.YourContract.YourVar().call() + if(this.state && this.state.YourContract) { + console.log("polling...") + //let yourVar = await this.state.YourContract.YourVar().call() + let yourVar = "nada" let yourContractBalance = await this.props.web3.eth.getBalance(this.state.YourContract._address) //let ensName = await this.props.ensLookup("austingriffith.eth") let mainnetBlockNumber = await this.props.mainnetweb3.eth.getBlockNumber() let xdaiBlockNumber = await this.props.xdaiweb3.eth.getBlockNumber() yourContractBalance = this.props.web3.utils.fromWei(yourContractBalance,'ether') + let count = await this.state.YourContract.messageCount().call(); this.setState({yourVar,yourContractBalance,mainnetBlockNumber,xdaiBlockNumber}) - + this.setState({messageCount: count}) + let messages = [] + for (var i = 0; i < this.state.messageCount; i++) { + let message = await this.state.YourContract.chat(i).call(); + messages.push(message); + } + this.setState({chat: messages}); } } @@ -56,6 +69,11 @@ export default class YourModule extends React.Component { /* Time to make a transaction with YourContract! */ + if (name == "chat") { + this.props.tx(this.state.YourContract.sendMessage(this.state.message), 120000, 0, 0, (result) => { + console.log(result) + }); + } this.props.tx(this.state.YourContract.updateVar(name),120000,0,0,(result)=>{ console.log(result) }) @@ -88,7 +106,7 @@ export default class YourModule extends React.Component {
- YOURMODULE DISPLAY HERE + Burner Chat
The logged in user is @@ -97,172 +115,63 @@ export default class YourModule extends React.Component { config={{size:6}} /> {this.props.address.substring(0,8)} -
- {this.props.dollarDisplay(this.props.balance)} -
-
- {this.props.dollarDisplay(this.props.daiBalance)} -
-
- {this.props.dollarDisplay(this.props.ethBalance*this.props.ethprice)} -
-
- - - -
- Network {this.props.network} is selected and on block #{this.props.block}. -
-
- Gas price on {this.props.network} is {this.props.gwei} gwei. -
-
- mainnetweb3 is on block {this.state.mainnetBlockNumber} and version {this.props.mainnetweb3.version} -
-
- xdaiweb3 is on block {this.state.xdaiBlockNumber} and version {this.props.xdaiweb3.version} -
+
+ +
- The current price of ETH is {this.props.dollarDisplay(this.props.ethprice)}. +
    + {this.state.chat.map((item, index) => ( +
  1. {item}
  2. + ))} +
- - - - - -
- { - console.log("EVENT DATA:",eventData) - this.setState({signEvents:allEvents}) - }} - /> - +
+ +
+ { this.messageInput = input; }} + onChange={event => {this.setState({message: event.target.value})}} + /> +
+
- + +
-
- -
+ +
- Your contract is + + Your Chat Room Address is: {this.state.YourContract._address} - {this.state.YourContract._address.substring(0,8)} - -
- it has {this.props.dollarDisplay(this.state.yourContractBalance)} -
- -
- with yourVar: -
- "{this.state.yourVar}" -
-
- -
-
-
- -
-
- -
-
- -
-
-
-
-
- +
- { this.addressInput = input; }} - onChange={event => this.updateState('toAddress', event.target.value)} + onChange={event => this.setState({yourContractAddress: event.target.value})} />
{ this.props.openScanner({view:"yourmodule"}) @@ -274,32 +183,20 @@ export default class YourModule extends React.Component {
-
-
- -
-
- -
-
- +
+ -
) diff --git a/src/contracts/YourContract.abi.js b/src/contracts/YourContract.abi.js index f90a28a9e..19cc0af8d 100644 --- a/src/contracts/YourContract.abi.js +++ b/src/contracts/YourContract.abi.js @@ -1 +1,2 @@ -module.exports = [{"constant":false,"inputs":[{"name":"amount","type":"uint256"}],"name":"withdraw","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"hashSigned","type":"bytes32"},{"name":"signature","type":"bytes"}],"name":"sign","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":true,"inputs":[],"name":"YourVar","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"newVal","type":"string"}],"name":"updateVar","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"deposit","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"anonymous":false,"inputs":[{"indexed":true,"name":"depositor","type":"address"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"withdrawer","type":"address"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"Withdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"sender","type":"address"},{"indexed":false,"name":"hashSigned","type":"bytes32"},{"indexed":true,"name":"signer","type":"address"}],"name":"Sign","type":"event"}] \ No newline at end of file +module.exports = +[{"constant":true,"inputs":[],"name":"YourVar","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"messageCount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"chat","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"message","type":"string"}],"name":"sendMessage","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"newVal","type":"string"}],"name":"updateVar","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"}] diff --git a/src/contracts/YourContract.address.js b/src/contracts/YourContract.address.js index 5b3d535be..71e101ce9 100644 --- a/src/contracts/YourContract.address.js +++ b/src/contracts/YourContract.address.js @@ -1 +1 @@ -module.exports = "0x9c896AFba867592B496c88192EC02A11aa2b4F86" \ No newline at end of file +module.exports = "0x8f4c5f7E15bA3c4003827909F189a671D3a7151e" diff --git a/src/contracts/YourContract.bytecode.js b/src/contracts/YourContract.bytecode.js index 4f2a95b74..89558e5a5 100644 --- a/src/contracts/YourContract.bytecode.js +++ b/src/contracts/YourContract.bytecode.js @@ -1 +1 @@ -module.exports = "60c0604052600b60808190527f48454c4c4f20574f524c4400000000000000000000000000000000000000000060a090815261003e9160009190610063565b5034801561004b57600080fd5b5060018054600160a060020a031916331790556100fe565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100a457805160ff19168380011785556100d1565b828001600101855582156100d1579182015b828111156100d15782518255916020019190600101906100b6565b506100dd9291506100e1565b5090565b6100fb91905b808211156100dd57600081556001016100e7565b90565b61060f8061010d6000396000f30060806040526004361061006c5763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632e1a7d4d8114610076578063365e250b1461008e5780633daf24a7146100df57806368ba52f5146101695780638da5cb5b146101d6575b610074610214565b005b34801561008257600080fd5b5061007460043561024c565b60408051602060046024803582810135601f81018590048502860185019096528585526100749583359536956044949193909101919081908401838280828437509497506102b39650505050505050565b3480156100eb57600080fd5b506100f4610311565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561012e578181015183820152602001610116565b50505050905090810190601f16801561015b5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561017557600080fd5b506040805160206004803580820135601f81018490048402850184019095528484526101c294369492936024939284019190819084018382808284375094975061039f9650505050505050565b604080519115158252519081900360200190f35b3480156101e257600080fd5b506101eb6103bd565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b60408051348152905133917fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c919081900360200190a2565b604051339082156108fc029083906000818181858888f19350505050158015610279573d6000803e3d6000fd5b5060408051828152905133917f884edad9ce6fa2440d8a54cc123490eb96d2768479d49ff9c7366125a9424364919081900360200190a250565b6102bd82826103d9565b60408051848152905173ffffffffffffffffffffffffffffffffffffffff929092169133917f0ebeda490dbddd9f5cc0b30c0967c4926a9ea6f60e4b441a39ef788db4d42818919081900360200190a35050565b6000805460408051602060026001851615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156103975780601f1061036c57610100808354040283529160200191610397565b820191906000526020600020905b81548152906001019060200180831161037a57829003601f168201915b505050505081565b80516000906103b49082906020850190610548565b50600192915050565b60015473ffffffffffffffffffffffffffffffffffffffff1681565b600080600080845160411415156103f3576000935061053f565b50505060208201516040830151606084015160001a601b60ff8216101561041857601b015b8060ff16601b1415801561043057508060ff16601c14155b1561043e576000935061053f565b604080517f19457468657265756d205369676e6564204d6573736167653a0a333200000000602080830191909152603c8083018a905283518084039091018152605c909201928390528151600193918291908401908083835b602083106104b65780518252601f199092019160209182019101610497565b51815160209384036101000a60001901801990921691161790526040805192909401829003822060008084528383018087529190915260ff891683860152606083018b9052608083018a9052935160a08084019750919550601f1981019492819003909101925090865af1158015610532573d6000803e3d6000fd5b5050506020604051035193505b50505092915050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061058957805160ff19168380011785556105b6565b828001600101855582156105b6579182015b828111156105b657825182559160200191906001019061059b565b506105c29291506105c6565b5090565b6105e091905b808211156105c257600081556001016105cc565b905600a165627a7a72305820a35ec5dd426591739b83416787d65a09641d473176a0e5c503e8ca8bdbdc5e400029" \ No newline at end of file +module.exports = "60c0604052600b60808190527f48454c4c4f20574f524c4400000000000000000000000000000000000000000060a090815261003e9160009190610068565b5034801561004b57600080fd5b5060018054600160a060020a031916331790556000600355610103565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100a957805160ff19168380011785556100d6565b828001600101855582156100d6579182015b828111156100d65782518255916020019190600101906100bb565b506100e29291506100e6565b5090565b61010091905b808211156100e257600081556001016100ec565b90565b610525806101126000396000f3006080604052600436106100775763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416633daf24a7811461007c5780633dbcc8d1146101065780634410728e1461012d578063469c81101461014557806368ba52f5146101b25780638da5cb5b1461020b575b600080fd5b34801561008857600080fd5b50610091610249565b6040805160208082528351818301528351919283929083019185019080838360005b838110156100cb5781810151838201526020016100b3565b50505050905090810190601f1680156100f85780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561011257600080fd5b5061011b6102d7565b60408051918252519081900360200190f35b34801561013957600080fd5b506100916004356102dd565b34801561015157600080fd5b506040805160206004803580820135601f810184900484028501840190955284845261019e9436949293602493928401919081908401838280828437509497506103439650505050505050565b604080519115158252519081900360200190f35b3480156101be57600080fd5b506040805160206004803580820135601f810184900484028501840190955284845261019e9436949293602493928401919081908401838280828437509497506103779650505050505050565b34801561021757600080fd5b50610220610442565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b6000805460408051602060026001851615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156102cf5780601f106102a4576101008083540402835291602001916102cf565b820191906000526020600020905b8154815290600101906020018083116102b257829003601f168201915b505050505081565b60035481565b600260208181526000928352604092839020805484516001821615610100026000190190911693909304601f81018390048302840183019094528383529192908301828280156102cf5780601f106102a4576101008083540402835291602001916102cf565b6003546000908152600260209081526040822083516103649285019061045e565b5050600380546001908101909155919050565b60015460009073ffffffffffffffffffffffffffffffffffffffff16331461042657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602160248201527f596f7572436f6e74726163743a3a757064617465566172206e6f74206f776e6560448201527f7200000000000000000000000000000000000000000000000000000000000000606482015290519081900360840190fd5b815161043990600090602085019061045e565b50600192915050565b60015473ffffffffffffffffffffffffffffffffffffffff1681565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061049f57805160ff19168380011785556104cc565b828001600101855582156104cc579182015b828111156104cc5782518255916020019190600101906104b1565b506104d89291506104dc565b5090565b6104f691905b808211156104d857600081556001016104e2565b905600a165627a7a723058206b4801e4dd8b928298c17fcfdaf261d0a139865b6d451db463145b512e50ce400029" diff --git a/src/contracts/YourContract.sol b/src/contracts/YourContract.sol index 5e3a5699a..c0fab3cea 100644 --- a/src/contracts/YourContract.sol +++ b/src/contracts/YourContract.sol @@ -4,9 +4,12 @@ contract YourContract { string public YourVar = "HELLO WORLD"; address public owner; + mapping (uint256 => string) public chat; + uint256 public messageCount; constructor() public { owner = msg.sender; + messageCount = 0; } function updateVar(string newVal) public returns (bool) { @@ -15,4 +18,10 @@ contract YourContract { return true; } + function sendMessage(string message) public returns (bool) { + chat[messageCount] = message; + messageCount = messageCount + 1; + return true; + } + }