Skip to content
Snippets Groups Projects
Unverified Commit cd341c70 authored by Luca Moser's avatar Luca Moser Committed by GitHub
Browse files

auto. redirects to addr when requesting from faucet (#569)

parent 43970a0c
Branches
No related tags found
No related merge requests found
...@@ -8,7 +8,6 @@ import Row from "react-bootstrap/Row"; ...@@ -8,7 +8,6 @@ import Row from "react-bootstrap/Row";
import Col from "react-bootstrap/Col"; import Col from "react-bootstrap/Col";
import Button from 'react-bootstrap/Button' import Button from 'react-bootstrap/Button'
import InputGroup from "react-bootstrap/InputGroup"; import InputGroup from "react-bootstrap/InputGroup";
import {Link} from 'react-router-dom';
interface Props { interface Props {
nodeStore?: NodeStore; nodeStore?: NodeStore;
...@@ -20,6 +19,10 @@ interface Props { ...@@ -20,6 +19,10 @@ interface Props {
@observer @observer
export class FaucetAddressInput extends React.Component<Props, any> { export class FaucetAddressInput extends React.Component<Props, any> {
componentWillUnmount() {
this.props.faucetStore.reset();
}
updateSend = (e) => { updateSend = (e) => {
this.props.faucetStore.updateSend(e.target.value); this.props.faucetStore.updateSend(e.target.value);
}; };
...@@ -34,7 +37,7 @@ export class FaucetAddressInput extends React.Component<Props, any> { ...@@ -34,7 +37,7 @@ export class FaucetAddressInput extends React.Component<Props, any> {
}; };
render() { render() {
let {send_addr, sending} = this.props.faucetStore; let {send_addr, query_error, sending} = this.props.faucetStore;
return ( return (
<React.Fragment> <React.Fragment>
...@@ -64,14 +67,14 @@ export class FaucetAddressInput extends React.Component<Props, any> { ...@@ -64,14 +67,14 @@ export class FaucetAddressInput extends React.Component<Props, any> {
</Button> </Button>
</Col> </Col>
</Row> </Row>
<Row className={"mb-3"}> {
<Col> query_error !== "" &&
<small> <Row className={"mb-3"}>
Check your funds on the explorer: <Link <Col>
to={`/explorer/address/${send_addr}`}>{send_addr}</Link> Couldn't request funds: {query_error}
</small> </Col>
</Col> </Row>
</Row> }
</React.Fragment> </React.Fragment>
); );
} }
......
import {action, observable} from 'mobx'; import {action, observable} from 'mobx';
import {RouterStore} from "mobx-react-router";
class SendResult { class SendResult {
MsgId: string; MsgId: string;
...@@ -13,8 +14,12 @@ export class FaucetStore { ...@@ -13,8 +14,12 @@ export class FaucetStore {
@observable send_addr: string = ""; @observable send_addr: string = "";
@observable sending: boolean = false; @observable sending: boolean = false;
@observable sendResult: SendResult = null; @observable sendResult: SendResult = null;
@observable query_error: string = "";
constructor() { routerStore: RouterStore;
constructor(routerStore: RouterStore) {
this.routerStore = routerStore;
} }
sendReq = async () => { sendReq = async () => {
...@@ -27,7 +32,9 @@ export class FaucetStore { ...@@ -27,7 +32,9 @@ export class FaucetStore {
return; return;
} }
let result: SendResult = await res.json(); let result: SendResult = await res.json();
this.updateSendResult(result); setTimeout(() => {
this.updateSendResult(result);
}, 2000);
} catch (err) { } catch (err) {
this.updateQueryError(err); this.updateQueryError(err);
} }
...@@ -37,11 +44,7 @@ export class FaucetStore { ...@@ -37,11 +44,7 @@ export class FaucetStore {
updateSendResult = (result: SendResult) => { updateSendResult = (result: SendResult) => {
this.sending = false; this.sending = false;
this.sendResult = result; this.sendResult = result;
}; this.routerStore.history.push(`/explorer/address/${this.send_addr}`);
@action
resetSend = () => {
this.sending = false;
}; };
@action @action
...@@ -50,16 +53,22 @@ export class FaucetStore { ...@@ -50,16 +53,22 @@ export class FaucetStore {
}; };
@action @action
updateSending = (sending: boolean) => this.sending = sending; updateSending = (sending: boolean) => {
this.sending = sending;
this.query_error = "";
};
@action @action
reset = () => { reset = () => {
this.send_addr = null; this.send_addr = null;
this.sending = false;
this.query_error = "";
}; };
@action @action
updateQueryError = (err: any) => { updateQueryError = (err: any) => {
this.sending = false; this.sending = false;
this.query_error = err;
}; };
} }
......
...@@ -17,7 +17,7 @@ const routerStore = new RouterStore(); ...@@ -17,7 +17,7 @@ const routerStore = new RouterStore();
const nodeStore = new NodeStore(); const nodeStore = new NodeStore();
const explorerStore = new ExplorerStore(routerStore); const explorerStore = new ExplorerStore(routerStore);
const drngStore = new DrngStore(routerStore); const drngStore = new DrngStore(routerStore);
const faucetStore = new FaucetStore(); const faucetStore = new FaucetStore(routerStore);
const visualizerStore = new VisualizerStore(routerStore); const visualizerStore = new VisualizerStore(routerStore);
const stores = { const stores = {
"routerStore": routerStore, "routerStore": routerStore,
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment