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