mirror of
https://github.com/status-im/snt-gas-relay.git
synced 2025-01-26 22:28:56 +00:00
Returning relayer account on availability
This commit is contained in:
parent
4faa540ec2
commit
b13f42e58e
@ -23,6 +23,7 @@ class AvailabilityStrategy extends Strategy {
|
||||
success: true,
|
||||
message: {
|
||||
message: "Available",
|
||||
address: this.config.node.blockchain.account,
|
||||
minPrice: minPrice
|
||||
}
|
||||
};
|
||||
|
@ -58,6 +58,10 @@ class ApproveAndCallGasRelayed extends Component {
|
||||
}
|
||||
|
||||
handleChange = name => event => {
|
||||
if(name == 'relayer'){
|
||||
this.props.updateRelayer(event.target.value);
|
||||
}
|
||||
|
||||
this.setState({
|
||||
[name]: event.target.value
|
||||
});
|
||||
@ -117,8 +121,14 @@ class ApproveAndCallGasRelayed extends Component {
|
||||
const {web3, kid} = this.props;
|
||||
|
||||
let relayer = this.state.relayer;
|
||||
if(relayer == '' && this.props.relayers.length == 1){
|
||||
relayer = this.props.relayers[0];
|
||||
|
||||
let relayers = [];
|
||||
for (var key in this.props.relayers) {
|
||||
if (this.props.relayers.hasOwnProperty(key)) relayers.push(key);
|
||||
}
|
||||
|
||||
if(relayer == '' && relayers.length == 1){
|
||||
relayer = relayers[0];
|
||||
}
|
||||
|
||||
this.setState({
|
||||
@ -159,6 +169,12 @@ class ApproveAndCallGasRelayed extends Component {
|
||||
|
||||
render(){
|
||||
const {classes} = this.props;
|
||||
|
||||
let relayers = [];
|
||||
for (var key in this.props.relayers) {
|
||||
if (this.props.relayers.hasOwnProperty(key)) relayers.push(key);
|
||||
}
|
||||
|
||||
return <div>
|
||||
<Card className={classes.card}>
|
||||
<CardContent>
|
||||
@ -332,12 +348,7 @@ class ApproveAndCallGasRelayed extends Component {
|
||||
native: true
|
||||
}}
|
||||
>
|
||||
{
|
||||
this.props.relayers.length > 0 ?
|
||||
this.props.relayers.map((r, i) => <option key={i} value={r}>Relayer #{i+1}: {r}</option>)
|
||||
:
|
||||
<option></option>
|
||||
}
|
||||
{ relayers.length > 0 ? relayers.map((r, i) => <option key={i} value={r}>Relayer #{i+1}: {r}</option>) : <option></option> }
|
||||
</TextField>
|
||||
<TextField
|
||||
id="signature"
|
||||
@ -369,7 +380,8 @@ ApproveAndCallGasRelayed.propTypes = {
|
||||
kid: PropTypes.string,
|
||||
skid: PropTypes.string,
|
||||
clearMessages: PropTypes.func,
|
||||
relayers: PropTypes.array.isRequired
|
||||
updateRelayer: PropTypes.func,
|
||||
relayers: PropTypes.object.isRequired
|
||||
};
|
||||
|
||||
export default withStyles(styles)(ApproveAndCallGasRelayed);
|
||||
|
@ -29,7 +29,8 @@ class Body extends Component {
|
||||
kid: null,
|
||||
skid: null,
|
||||
message: '',
|
||||
relayers: []
|
||||
relayerAddress: '0x0000000000000000000000000000000000000000',
|
||||
relayers: {}
|
||||
};
|
||||
}
|
||||
|
||||
@ -41,7 +42,15 @@ class Body extends Component {
|
||||
}
|
||||
|
||||
const web3js = new Web3('ws://localhost:8546');
|
||||
|
||||
|
||||
|
||||
// Default for devenv
|
||||
web3js.eth.net.getId().then(netId => {
|
||||
if(netId != 1 && netId != 3){
|
||||
this.setState({relayerAddress: config.relayAccount});
|
||||
}
|
||||
});
|
||||
|
||||
web3js.shh.newKeyPair()
|
||||
.then((kid) => {
|
||||
web3js.shh.addSymKey(config.relaySymKey)
|
||||
@ -57,9 +66,10 @@ class Body extends Component {
|
||||
if(msgObj.message == Messages.available){
|
||||
// found a relayer
|
||||
console.log("Relayer available: " + msgObj.sig);
|
||||
|
||||
let relayers = this.state.relayers;
|
||||
relayers.push(msgObj.sig);
|
||||
relayers = relayers.filter((value, index, self) => self.indexOf(value) === index);
|
||||
relayers[msgObj.sig] = msgObj.address;
|
||||
|
||||
this.setState({relayers});
|
||||
}
|
||||
|
||||
@ -83,6 +93,10 @@ class Body extends Component {
|
||||
this.setState({tab});
|
||||
};
|
||||
|
||||
updateRelayer = (relayer) => {
|
||||
this.setState({relayerAddress: this.state.relayers[relayer]});
|
||||
}
|
||||
|
||||
updateNonce = (newNonce) => {
|
||||
this.setState({nonce: newNonce});
|
||||
}
|
||||
@ -106,13 +120,8 @@ class Body extends Component {
|
||||
});
|
||||
}
|
||||
|
||||
randomizeAddress = () => {
|
||||
// TODO:
|
||||
this.setState({identityAddress: "0xC0F1349e154Be9c2eBcc18088AC65d48Fc9ED0FF"});
|
||||
}
|
||||
|
||||
render(){
|
||||
const {tab, identityAddress, nonce, web3js, message, kid, skid, relayers} = this.state;
|
||||
const {tab, identityAddress, nonce, web3js, message, kid, skid, relayers, relayerAddress} = this.state;
|
||||
|
||||
return <Fragment>
|
||||
<Tabs value={tab} onChange={this.handleChange}>
|
||||
@ -120,12 +129,12 @@ class Body extends Component {
|
||||
<Tab label="Approve and Call" />
|
||||
<Tab label="Deploy" />
|
||||
</Tabs>
|
||||
{tab === 0 && <Container><CallGasRelayed clearMessages={this.clearMessages} web3={web3js} kid={kid} skid={skid} nonce={nonce} identityAddress={identityAddress} relayers={relayers} /></Container>}
|
||||
{tab === 1 && <Container><ApproveAndCallGasRelayed clearMessages={this.clearMessages} web3={web3js} kid={kid} skid={skid} nonce={nonce} identityAddress={identityAddress} relayers={relayers} /></Container>}
|
||||
{tab === 0 && <Container><CallGasRelayed clearMessages={this.clearMessages} web3={web3js} kid={kid} skid={skid} nonce={nonce} identityAddress={identityAddress} relayers={relayers} updateRelayer={this.updateRelayer} /></Container>}
|
||||
{tab === 1 && <Container><ApproveAndCallGasRelayed clearMessages={this.clearMessages} web3={web3js} kid={kid} skid={skid} nonce={nonce} identityAddress={identityAddress} relayers={relayers} updateRelayer={this.updateRelayer} /></Container>}
|
||||
{tab === 2 && <Container>Item Three</Container>}
|
||||
<Divider />
|
||||
<Container>
|
||||
<Status message={message} identityCreationFunction={this.newIdentity} randomizeAddress={this.randomizeAddress} nonceUpdateFunction={this.updateNonce} nonce={nonce} identityAddress={identityAddress} />
|
||||
<Status relayerAddress={relayerAddress} message={message} identityCreationFunction={this.newIdentity} nonceUpdateFunction={this.updateNonce} nonce={nonce} identityAddress={identityAddress} />
|
||||
</Container>
|
||||
</Fragment>;
|
||||
}
|
||||
|
@ -62,6 +62,9 @@ class CallGasRelayed extends Component {
|
||||
}
|
||||
|
||||
handleChange = name => event => {
|
||||
if(name == 'relayer'){
|
||||
this.props.updateRelayer(event.target.value);
|
||||
}
|
||||
this.setState({
|
||||
[name]: event.target.value
|
||||
});
|
||||
@ -122,8 +125,15 @@ class CallGasRelayed extends Component {
|
||||
const {web3, kid} = this.props;
|
||||
|
||||
let relayer = this.state.relayer;
|
||||
if(relayer == '' && this.props.relayers.length == 1){
|
||||
relayer = this.props.relayers[0];
|
||||
|
||||
|
||||
let relayers = [];
|
||||
for (var key in this.props.relayers) {
|
||||
if (this.props.relayers.hasOwnProperty(key)) relayers.push(key);
|
||||
}
|
||||
|
||||
if(relayer == '' && relayers.length == 1){
|
||||
relayer = relayers[0];
|
||||
}
|
||||
|
||||
this.setState({
|
||||
@ -161,6 +171,12 @@ class CallGasRelayed extends Component {
|
||||
|
||||
render(){
|
||||
const {classes} = this.props;
|
||||
|
||||
let relayers = [];
|
||||
for (var key in this.props.relayers) {
|
||||
if (this.props.relayers.hasOwnProperty(key)) relayers.push(key);
|
||||
}
|
||||
|
||||
return <div>
|
||||
<Card className={classes.card}>
|
||||
<CardContent>
|
||||
@ -317,12 +333,7 @@ class CallGasRelayed extends Component {
|
||||
native: true
|
||||
}}
|
||||
>
|
||||
{
|
||||
this.props.relayers.length > 0 ?
|
||||
this.props.relayers.map((r, i) => <option key={i} value={r}>Relayer #{i+1}: {r}</option>)
|
||||
:
|
||||
<option></option>
|
||||
}
|
||||
{ relayers.length > 0 ? relayers.map((r, i) => <option key={i} value={r}>Relayer #{i+1}: {r}</option>) : <option></option> }
|
||||
</TextField>
|
||||
<TextField
|
||||
id="signature"
|
||||
@ -353,7 +364,8 @@ CallGasRelayed.propTypes = {
|
||||
kid: PropTypes.string,
|
||||
skid: PropTypes.string,
|
||||
clearMessages: PropTypes.func,
|
||||
relayers: PropTypes.array.isRequired
|
||||
updateRelayer: PropTypes.func,
|
||||
relayers: PropTypes.object.isRequired
|
||||
};
|
||||
|
||||
export default withStyles(styles)(CallGasRelayed);
|
||||
|
@ -52,10 +52,11 @@ class Status extends Component {
|
||||
|
||||
constructor(props){
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
'isDev': true,
|
||||
'identityEthBalance': 0,
|
||||
'identitySTTBalance': 0,
|
||||
'relayerAddress': null,
|
||||
'relayerEthBalance': 0,
|
||||
'relayerSTTBalance': 0,
|
||||
'block': 0,
|
||||
@ -74,15 +75,17 @@ class Status extends Component {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setState({
|
||||
relayerAddress: config.relayAccount
|
||||
});
|
||||
|
||||
this.getBlock();
|
||||
});
|
||||
}
|
||||
|
||||
getBlock = () => {
|
||||
|
||||
// Default for devenv
|
||||
web3.eth.net.getId().then(netId => {
|
||||
this.setState({isDev: netId != 1 && netId != 3});
|
||||
});
|
||||
|
||||
web3.eth.subscribe('newBlockHeaders')
|
||||
.on('data', (block) => {
|
||||
this.setState({block: block.number});
|
||||
@ -115,12 +118,12 @@ class Status extends Component {
|
||||
});
|
||||
}
|
||||
|
||||
web3.eth.getBalance(this.state.relayerAddress)
|
||||
web3.eth.getBalance(this.props.relayerAddress)
|
||||
.then(relayerEthBalance => {
|
||||
this.setState({relayerEthBalance});
|
||||
});
|
||||
|
||||
STT.methods.balanceOf(this.state.relayerAddress)
|
||||
STT.methods.balanceOf(this.props.relayerAddress)
|
||||
.call()
|
||||
.then(relayerSTTBalance => {
|
||||
this.setState({relayerSTTBalance: web3.utils.fromWei(relayerSTTBalance, 'ether')});
|
||||
@ -162,11 +165,6 @@ class Status extends Component {
|
||||
});
|
||||
}
|
||||
|
||||
randomizeAddress = (event) => {
|
||||
event.preventDefault();
|
||||
this.props.randomizeAddress();
|
||||
}
|
||||
|
||||
sendEther = (event) => {
|
||||
event.preventDefault();
|
||||
|
||||
@ -174,7 +172,7 @@ class Status extends Component {
|
||||
submitState.etherSend = false;
|
||||
this.setState({submitState});
|
||||
|
||||
web3.eth.sendTransaction({from: web3.eth.defaultAccount, to: this.state.relayerAddress, value: web3.utils.toWei('1', "ether")})
|
||||
web3.eth.sendTransaction({from: web3.eth.defaultAccount, to: this.props.relayerAddress, value: web3.utils.toWei('1', "ether")})
|
||||
.then((receipt) => {
|
||||
console.log(receipt);
|
||||
submitState = this.state.submitState;
|
||||
@ -184,8 +182,8 @@ class Status extends Component {
|
||||
}
|
||||
|
||||
render(){
|
||||
const {classes, identityAddress, nonce} = this.props;
|
||||
const {identityEthBalance, relayerAddress, relayerEthBalance, identitySTTBalance, relayerSTTBalance, submitState, block} = this.state;
|
||||
const {classes, identityAddress, nonce, relayerAddress} = this.props;
|
||||
const {identityEthBalance, relayerEthBalance, identitySTTBalance, relayerSTTBalance, submitState, block, isDev} = this.state;
|
||||
|
||||
return <Fragment>
|
||||
<Card className={classes.card}>
|
||||
@ -199,23 +197,20 @@ class Status extends Component {
|
||||
<div className={classes.container}>
|
||||
{ (submitState.createIdentity || submitState.etherSend || submitState.generateSTT) && <LinearProgress /> }
|
||||
|
||||
|
||||
|
||||
<List dense={true}>
|
||||
<ListItem>
|
||||
<Typography variant="display1">
|
||||
Identity
|
||||
</Typography>
|
||||
<Button className={classes.button} color="primary" aria-label="New Identity" onClick={this.createIdentity} disabled={submitState.createIdentity}>
|
||||
|
||||
{ isDev && <Button className={classes.button} color="primary" aria-label="New Identity" onClick={this.createIdentity} disabled={submitState.createIdentity}>
|
||||
<RefreshIcon className={classes.icon} />
|
||||
Create new identity
|
||||
</Button>
|
||||
{
|
||||
<Button className={classes.button} color="primary" aria-label="Generate STT" onClick={this.generateSTT} disabled={submitState.generateSTT}>
|
||||
</Button> }
|
||||
{ isDev && <Button className={classes.button} color="primary" aria-label="Generate STT" onClick={this.generateSTT} disabled={submitState.generateSTT}>
|
||||
<AddIcon className={classes.icon} />
|
||||
Generate 5K STT (only on dev)
|
||||
</Button>
|
||||
}
|
||||
</Button> }
|
||||
</ListItem>
|
||||
<ListItem className={classes.root}>
|
||||
<ListItemIcon>
|
||||
@ -255,10 +250,10 @@ class Status extends Component {
|
||||
<Typography variant="display1">
|
||||
Relayer
|
||||
</Typography>
|
||||
<Button className={classes.button} color="primary" aria-label="Add ether" onClick={this.sendEther} disabled={submitState.etherSend}>
|
||||
{ isDev && <Button className={classes.button} color="primary" aria-label="Add ether" onClick={this.sendEther} disabled={submitState.etherSend}>
|
||||
<AddIcon className={classes.icon} />
|
||||
Send ether
|
||||
</Button>
|
||||
</Button> }
|
||||
</ListItem>
|
||||
<ListItem className={classes.root}>
|
||||
<ListItemIcon>
|
||||
@ -301,8 +296,8 @@ Status.propTypes = {
|
||||
nonce: PropTypes.string.isRequired,
|
||||
identityCreationFunction: PropTypes.func.isRequired,
|
||||
nonceUpdateFunction: PropTypes.func.isRequired,
|
||||
randomizeAddress: PropTypes.func.isRequired,
|
||||
message: PropTypes.string
|
||||
message: PropTypes.string,
|
||||
relayerAddress: PropTypes.string
|
||||
};
|
||||
|
||||
export default withStyles(styles)(Status);
|
||||
|
Loading…
x
Reference in New Issue
Block a user