1
0
mirror of https://github.com/oceanprotocol/commons.git synced 2023-03-15 18:03:00 +01:00

Merge pull request #49 from oceanprotocol/fix/faucet

pass through faucet server response, error feedback
This commit is contained in:
Matthias Kretschmann 2019-04-02 13:06:38 +02:00 committed by GitHub
commit 46b8d1f0bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 10 deletions

View File

@ -53,7 +53,7 @@ class App extends Component<{}, AppState> {
private requestFromFaucet = async () => { private requestFromFaucet = async () => {
if (this.state.account !== '') { if (this.state.account !== '') {
try { try {
await fetch( const response = await fetch(
`${faucetScheme}://${faucetHost}:${faucetPort}/faucet`, `${faucetScheme}://${faucetHost}:${faucetPort}/faucet`,
{ {
method: 'POST', method: 'POST',
@ -67,6 +67,8 @@ class App extends Component<{}, AppState> {
}) })
} }
) )
return response.json()
} catch (error) { } catch (error) {
Logger.log('requestFromFaucet', error) Logger.log('requestFromFaucet', error)
} }

View File

@ -13,3 +13,10 @@
.success { .success {
color: $green; color: $green;
} }
.error {
&,
p {
color: $red;
}
}

View File

@ -21,16 +21,24 @@ export default class Faucet extends PureComponent<{}, FaucetState> {
eth: 'xx' eth: 'xx'
} }
private getTokens = async (requestFromFaucet: () => void) => { private getTokens = async (requestFromFaucet: () => any) => {
this.setState({ isLoading: true }) this.setState({ isLoading: true })
try { try {
await requestFromFaucet() const response = await requestFromFaucet()
if (response.error) {
this.setState({
isLoading: false,
error: response.error
})
return
}
this.setState({ this.setState({
isLoading: false, isLoading: false,
success: `Successfully added ${ success: `Successfully added ETH to your account.`
this.state.eth
} ETH to your account.`
}) })
} catch (error) { } catch (error) {
this.setState({ isLoading: false, error }) this.setState({ isLoading: false, error })
@ -56,10 +64,8 @@ export default class Faucet extends PureComponent<{}, FaucetState> {
<Spinner message="Getting Ether..." /> <Spinner message="Getting Ether..." />
) : this.state.error ? ( ) : this.state.error ? (
<div className={styles.error}> <div className={styles.error}>
{this.state.error}{' '} <p>{this.state.error}</p>
<Button link onClick={this.reset}> <Button onClick={this.reset}>Try again</Button>
Try again
</Button>
</div> </div>
) : this.state.success ? ( ) : this.state.success ? (
<div className={styles.success}>{this.state.success}</div> <div className={styles.success}>{this.state.success}</div>