Skip to content

Commit

Permalink
refactor: use shared const PE-5161
Browse files Browse the repository at this point in the history
  • Loading branch information
fedellen committed Dec 7, 2023
1 parent ae781d5 commit cbeb926
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/GiftForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function GiftForm({ errorCallback }: GiftFormProps) {
const [isTermsAccepted, setTermsAccepted] = useState<boolean>(false);

const handleUSDChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const amount = Number(e.target.value);
const amount = +e.target.value;
if (amount > maxUSDAmount) {
setUsdAmount(maxUSDAmount);
return;
Expand All @@ -32,11 +32,11 @@ export function GiftForm({ errorCallback }: GiftFormProps) {
setUsdAmount(minUSDAmount);
return;
}
setUsdAmount(Number(Number(e.target.value).toFixed(2)));
setUsdAmount(+amount.toFixed(2));
};

const wincForOneGiB = useWincForOneGiB();
const debouncedUsdAmount = useDebounce(usdAmount, 500);
const debouncedUsdAmount = useDebounce(usdAmount);
const [credits, usdWhenCreditsWereLastUpdatedRef] = useCreditsForFiat(
debouncedUsdAmount,
errorCallback,
Expand Down Expand Up @@ -177,7 +177,7 @@ export function GiftForm({ errorCallback }: GiftFormProps) {
/>
<span>
I Agree to the
<a href={termsOfServiceUrl}>Terms of Service and Privacy Policy</a>.
<a href={termsOfServiceUrl}> Terms of Service and Privacy Policy</a>.
</span>
</div>

Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export const turboConfig = {
paymentServiceConfig: { url: paymentServiceUrl },
};
export const wincPerCredit = 1_000_000_000_000;
export const defaultDebounceMs = 500;
6 changes: 5 additions & 1 deletion src/hooks/useDebounce.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { useEffect, useState } from "react";
import { defaultDebounceMs } from "../constants";

export function useDebounce<T>(value: T, delay?: number): T {
const [debouncedValue, setDebouncedValue] = useState<T>(value);

useEffect(() => {
const timer = setTimeout(() => setDebouncedValue(value), delay || 500);
const timer = setTimeout(
() => setDebouncedValue(value),
delay || defaultDebounceMs,
);

return () => {
clearTimeout(timer);
Expand Down

0 comments on commit cbeb926

Please sign in to comment.