Skip to content

Commit 2a49605

Browse files
committed
add loading spinner
1 parent 7ef916b commit 2a49605

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

client/src/App.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { Component } from 'react';
2-
import { Alert, Button, Container, Col, Form, Row } from "react-bootstrap";
2+
import { Alert, Button, Container, Col, Form, Row, Spinner } from "react-bootstrap";
33

44
import './App.css';
55

@@ -23,9 +23,11 @@ class App extends Component {
2323
const params = { address: inputEthAddress };
2424
Object.keys(params).forEach(key => url.searchParams.append(key, params[key]));
2525

26+
this.setState({ isLoading: true });
2627
const response = await fetch(url, {
2728
method: 'GET',
2829
});
30+
this.setState({ isLoading: false });
2931
if (response.status !== 200) {
3032
this.setState({
3133
responseMsg: response.statusText,
@@ -51,9 +53,11 @@ class App extends Component {
5153
const params = { address: inputEthAddress };
5254
Object.keys(params).forEach(key => url.searchParams.append(key, params[key]));
5355

56+
this.setState({ isLoading: true });
5457
const response = await fetch(url, {
5558
method: 'GET',
5659
});
60+
this.setState({ isLoading: false });
5761
if (response.status !== 200) {
5862
this.setState({
5963
responseMsg: response.statusText,
@@ -79,9 +83,11 @@ class App extends Component {
7983
const params = { address: inputDhxAddress };
8084
Object.keys(params).forEach(key => url.searchParams.append(key, params[key]));
8185

86+
this.setState({ isLoading: true });
8287
const response = await fetch(url, {
8388
method: 'GET',
8489
});
90+
this.setState({ isLoading: false });
8591
if (response.status !== 200) {
8692
this.setState({
8793
responseMsg: response.statusText,
@@ -97,7 +103,7 @@ class App extends Component {
97103
};
98104

99105
render() {
100-
const { responseMsg, responseTx } = this.state;
106+
const { isLoading, responseMsg, responseTx } = this.state;
101107
return (
102108
<Container fluid className="App">
103109
<Row className="justify-content-md-center">
@@ -131,6 +137,11 @@ class App extends Component {
131137
</Row>
132138
) : null
133139
}
140+
{
141+
isLoading && (!responseMsg || !responseTx) ? (
142+
<Spinner animation="border" variant="primary" />
143+
) : null
144+
}
134145
<hr className="mb-4" />
135146
<Form onSubmit={this.handleSubmitRequestEth}>
136147
<Form.Group controlId="formRequestEth">

0 commit comments

Comments
 (0)