Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI Updates #20

Merged
merged 4 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 54 additions & 24 deletions src/components/Faucet/FaucetRequestButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default function FaucetRequestButton({
status: StatusContext
}) {
const [amount, setAmount] = useState<number>(minTez)
const formattedAmount = amount.toLocaleString()
const [isLocalLoading, setLocalLoading] = useState<boolean>(false)
const recaptchaRef: RefObject<ReCAPTCHA> = useRef(null)

Expand Down Expand Up @@ -216,6 +217,29 @@ export default function FaucetRequestButton({
return {}
}

const computeStep = () => {
const magnitude = Math.floor(Math.log10(maxTez))

switch (magnitude) {
case 1:
case 2:
return 1
case 3:
return 10
case 4:
return 100
case 5:
return 1_000
case 6:
return 10_000
default:
return 100_000
}
}

const currentStep = computeStep()
const adjustedMin = Math.ceil(minTez / currentStep) * currentStep

return (
<>
<ReCAPTCHA
Expand All @@ -226,46 +250,52 @@ export default function FaucetRequestButton({
/>

<Form.Group controlId="tezosRange" className="mt-4">
<Row className="d-flex align-items-end">
<Col md={8}>
<Form.Label>Select Tez Amount</Form.Label>
<Row>
<Col xs="auto" className="pe-0">
<Form.Label className="fw-bold">{minTez}</Form.Label>
</Col>

<Col>
<Form.Range
min={minTez}
max={maxTez}
value={amount}
disabled={disabled}
onChange={updateAmount}
/>
</Col>
<Form.Label>Select Tez Amount</Form.Label>
<Row className="mb-2">
<Col xs="auto" className="pe-0">
<Form.Label className="fw-bold">
{minTez.toLocaleString()}
</Form.Label>
</Col>

<Col>
<Form.Range
min={adjustedMin}
max={maxTez}
step={currentStep}
value={amount}
disabled={disabled}
onChange={updateAmount}
/>
</Col>

<Col xs="auto" className="ps-0">
<Form.Label className="fw-bold">{maxTez}</Form.Label>
</Col>
</Row>
<Col xs="auto" className="ps-0">
<Form.Label className="fw-bold">
{maxTez.toLocaleString()}
</Form.Label>
</Col>
</Row>

<Col xs={6} md={4}>
<Row className="d-flex align-items-end gy-3">
<Col xs={12} sm={6}>
<Form.Control
type="number"
min={minTez}
max={maxTez}
value={amount}
disabled={disabled}
onChange={updateAmount}
onFocus={(e) => e.target.select()}
/>
</Col>

<Col xs={6}>
<Col xs={12} sm={6} className="d-flex justify-content-sm-end">
<Button variant="primary" disabled={disabled} onClick={getTez}>
<DropletFill />
&nbsp;
{isLocalLoading ? `Requested ${amount} ꜩ` : `Request ${amount} ꜩ`}
{isLocalLoading
? `Requested ${formattedAmount} ꜩ`
: `Request ${formattedAmount} ꜩ`}
&nbsp;{" "}
{isLocalLoading ? (
<Spinner
Expand Down
3 changes: 2 additions & 1 deletion src/components/Faucet/FaucetToInputRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ export default function FaucetToInputRequest({
type="text"
placeholder="tz1..."
id={inputId}
onChange={handleInput}
className={inputClass}
disabled={status.isLoading}
onChange={handleInput}
onFocus={(e) => e.target.select()}
/>
<Form.Control.Feedback type="invalid" className="position-absolute">
Invalid address
Expand Down
Loading