Skip to content

Commit

Permalink
feat: only update estimate when credits update PE-5161
Browse files Browse the repository at this point in the history
  • Loading branch information
fedellen committed Dec 6, 2023
1 parent 22279b0 commit f195cad
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/GiftForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export function GiftForm({ errorCallback }: GiftFormProps) {

const [credits, setCredits] = useState<string | undefined>(undefined);

const usdWhenCreditsWereLastUpdatedRef = useRef<number | undefined>(
undefined,
);

const [wincForOneGiB, setWincForOneGiB] = useState<string | undefined>(
undefined,
);
Expand Down Expand Up @@ -78,7 +82,7 @@ export function GiftForm({ errorCallback }: GiftFormProps) {
console.error(err);
errorCallback(`Error getting credits for USD amount: ${err.message}`);
});
TurboFactory;
usdWhenCreditsWereLastUpdatedRef.current = debouncedUsdAmount;
}, [debouncedUsdAmount, errorCallback]);

const canSubmitForm =
Expand Down Expand Up @@ -124,7 +128,11 @@ export function GiftForm({ errorCallback }: GiftFormProps) {
<div>
{wincForOneGiB && (
<div id="conversions">
$<span className="conversion-amount">{usdAmount}</span>{" "}
$
<span className="conversion-amount">
{usdWhenCreditsWereLastUpdatedRef.current}
</span>{" "}
{" "}
<span className="conversion-amount">
{(Number(credits) / 1_000_000_000_000).toFixed(4)}
</span>
Expand Down

0 comments on commit f195cad

Please sign in to comment.