import React, {Component} from 'react'; import StatusGasRelayer, {Contracts} from '../status-gas-relayer'; import Button from '@material-ui/core/Button'; import Card from '@material-ui/core/Card'; import CardActions from '@material-ui/core/CardActions'; import CardContent from '@material-ui/core/CardContent'; import CardHeader from '@material-ui/core/CardHeader'; import Grid from '@material-ui/core/Grid'; import MySnackbarContentWrapper from './snackbar'; import PropTypes from 'prop-types'; import SNTController from 'Embark/contracts/SNTController'; import STT from 'Embark/contracts/STT'; import TestContract from 'Embark/contracts/TestContract'; import TextField from '@material-ui/core/TextField'; import config from '../config'; import web3 from 'Embark/web3'; import {withStyles} from '@material-ui/core/styles'; const styles = theme => ({ root: { width: '100%', backgroundColor: theme.palette.background.paper }, card: { marginBottom: theme.spacing.unit * 3 } }); window.TestContract = TestContract; class TransferSNT extends Component { constructor(props){ super(props); this.state = { topic: '0x534e5443', to: '0x0000000000000000000000000000000000000000', amount: 0, gasPrice: 0, signature: '', kid: null, skid: null, msgSent: '', payload: '', message: '', relayer: '', web3js: null, transactionError: '', messagingError: '', submitting: false }; } handleChange = name => event => { this.setState({ [name]: event.target.value }); }; getBalance = (event) => { event.preventDefault(); STT.methods.balanceOf(this.state.to) .call() .then(balance => { console.log("Balance of " + this.state.to + ": " + balance + " STT"); }); } sign = async (event) => { if(event) event.preventDefault(); this.setState({ msgSent: false, transactionError: '' }); try { const accounts = await web3.eth.getAccounts(); const s = new StatusGasRelayer.SNTController(SNTController.options.address, accounts[2]) .transferSNT(this.state.to, this.state.amount) .setGas(this.state.gasPrice); const signature = await s.sign(web3); this.setState({signature}); } catch(error){ this.setState({transactionError: error.message}); } } obtainRelayers = async event => { event.preventDefault(); const {web3, kid, skid} = this.props; this.setState({ messagingError: '', submitting: true }); this.props.clearMessages(); try { const accounts = await web3.eth.getAccounts(); const s = new StatusGasRelayer.AvailableRelayers(Contracts.SNT, SNTController.options.address, accounts[2]) .setRelayersSymKeyID(skid) .setAsymmetricKeyID(kid) .setGas(STT.options.address, this.state.gasPrice); await s.post(web3); console.log("Message sent"); this.setState({submitting: false}); } catch(error){ this.setState({messagingError: error.message, submitting: false}); } } sendTransaction = async event => { event.preventDefault(); const {web3, kid} = this.props; let relayer = this.state.relayer; if(relayer == '' && this.props.relayers.length == 1){ relayer = this.props.relayers[0]; } this.setState({ messagingError: '', submitting: true }); this.props.clearMessages(); try { const accounts = await web3.eth.getAccounts(); const s = new StatusGasRelayer.SNTController(SNTController.options.address, accounts[2]) .transferSNT(this.state.to, this.state.amount) .setGas(this.state.gasPrice) .setRelayer(relayer) .setAsymmetricKeyID(kid); await s.post(this.state.signature, web3); this.setState({submitting: false}); console.log("Message sent"); } catch(error){ this.setState({messagingError: error.message, submitting: false}); } } render(){ const {classes} = this.props; return