/** * Copyright (c) 2018 - present Zilliqa Research Pte. Ltd. * * This program is free software: you can redistribute it and/or modify it under the * terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ import React, { useState } from 'react'; import { Card, FormGroup, Label, Input, FormFeedback, Row, Col, Form } from 'reactstrap'; import Layout from '../../components/layout'; import FaucetRequest from '../../components/faucet-request'; import { getInputValidationState } from '../../utils'; import { validation } from '@zilliqa-js/util'; const { isAddress, isBech32 } = validation; const FaucetContainer = ({ zilContext }) => { const { faucet } = zilContext; const urlSearchParams = new URLSearchParams(window.location.search); const params = Object.fromEntries(urlSearchParams.entries()); const initialAddress = params['address']; let isInitialAddressValid = false; if (initialAddress !== undefined) { isInitialAddressValid = isBech32(initialAddress) || isAddress(initialAddress); } const [toAddress, setToAddress] = useState(initialAddress); const [toAddressValid, setToAddressValid] = useState(isInitialAddressValid); const [toAddressInvalid, setToAddressInvalid] = useState( initialAddress !== undefined && !isInitialAddressValid ); const changeToAddress = (e: React.ChangeEvent): void => { e.preventDefault(); const value = e.target.value; const key = 'toAddress'; const validate = (value) => isBech32(value) || isAddress(value); const validationResult: any = getInputValidationState(key, value, validate(value)); setToAddress(value); setToAddressValid(validationResult.toAddressValid); setToAddressInvalid(validationResult.toAddressInvalid); }; const reset = () => { setToAddress(''); setToAddressValid(false); setToAddressInvalid(false); }; return (

{'ZIL Faucet'}

{'Please run the faucet to receive a small amount of Zil for testing.'}

{'invalid address'} {'valid address'}
{toAddressValid ? ( ) : null}
); }; export default FaucetContainer;