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:
commit
46b8d1f0bb
@ -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)
|
||||||
}
|
}
|
||||||
|
@ -13,3 +13,10 @@
|
|||||||
.success {
|
.success {
|
||||||
color: $green;
|
color: $green;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
&,
|
||||||
|
p {
|
||||||
|
color: $red;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -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({
|
this.setState({
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
success: `Successfully added ${
|
error: response.error
|
||||||
this.state.eth
|
})
|
||||||
} ETH to your account.`
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
isLoading: false,
|
||||||
|
success: `Successfully added 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>
|
||||||
|
Loading…
Reference in New Issue
Block a user