import React, { PureComponent } from 'react' import { FaucetResponse } from '../ocean' import Route from '../components/templates/Route' import Button from '../components/atoms/Button' import Spinner from '../components/atoms/Spinner' import { User, Market } from '../context' import Web3message from '../components/organisms/Web3message' import styles from './Faucet.module.scss' import Content from '../components/atoms/Content' import withTracker from '../hoc/withTracker' interface FaucetState { isLoading: boolean success?: string error?: string trxHash?: string } class Faucet extends PureComponent<{}, FaucetState> { public static contextType = User public state = { isLoading: false, success: undefined, error: undefined, trxHash: undefined } private getTokens = async ( requestFromFaucet: () => Promise ) => { this.setState({ isLoading: true }) try { const response = await requestFromFaucet() if (!response.success) { this.setState({ isLoading: false, error: response.message }) return } const { trxHash } = response this.setState({ isLoading: false, success: response.message, trxHash }) } catch (error) { this.setState({ isLoading: false, error: error.message }) } } private reset = () => { this.setState({ error: undefined, success: undefined, isLoading: false }) } private Success = () => { const { network } = this.context const { trxHash } = this.state const submarineLink = `https://submarine${ network === 'Duero' ? '.duero' : network === 'Pacific' ? '.pacific' : '' }.dev-ocean.com/tx/${trxHash}` return (
{this.state.success}

Your Transaction Hash {trxHash}

) } private Error = () => (

{this.state.error}

) private Action = () => ( <>

You can only request Ether once every 24 hours for your address.

) public render() { const { isLogged } = this.context const { isLoading, error, success } = this.state return ( {market => (
{isLoading ? ( ) : error ? ( ) : success ? ( ) : ( isLogged && )}
)}
) } } export default withTracker(Faucet)