Skip to content

Commit

Permalink
fix: shows a loader while refreshing native pay btns
Browse files Browse the repository at this point in the history
- prevents jerky layout
  • Loading branch information
mohitb35 committed Jan 16, 2024
1 parent 9050c73 commit 2ab3093
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/Donations/PaymentMethods/PaymentRequestCustomButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from "@stripe/stripe-js/types/stripe-js/payment-request";
import { PaymentMethod } from "@stripe/stripe-js/types/api/payment-methods";
import { Stripe } from "@stripe/stripe-js/types/stripe-js/stripe";
import Skeleton from "@mui/material/Skeleton";

interface PaymentButtonProps {
country: string;
Expand Down Expand Up @@ -50,6 +51,8 @@ export const PaymentRequestCustomButton = ({
const stripe = useStripe();
const [canMakePayment, setCanMakePayment] = useState(false);
const [paymentLoading, setPaymentLoading] = useState(false);
// Tracks if native pay buttons were shown at least once to prevent layout jerks
const [wasNativePayInit, setWasNativePayInit] = useState(false);

Check notice on line 56 in src/Donations/PaymentMethods/PaymentRequestCustomButton.tsx

View check run for this annotation

codefactor.io / CodeFactor

src/Donations/PaymentMethods/PaymentRequestCustomButton.tsx#L35-L56

Complex Method
useEffect(() => {
setPaymentRequest(null);
Expand All @@ -75,6 +78,7 @@ export const PaymentRequestCustomButton = ({
pr.canMakePayment().then((result) => {
if (result) {
setPaymentRequest(pr);
setWasNativePayInit(true);
}
});
}
Expand Down Expand Up @@ -194,8 +198,25 @@ export const PaymentRequestCustomButton = ({
<div className="separator-text mb-10">{t("or")}</div>
)}
</div>
) : null
) : null}
) : (
<></>
)
) : wasNativePayInit ? (
//Loader shown if native pay was initiated at least once to avoid a jerky effect when payment details change
<div className="w-100">
<Skeleton
className="mb-10"
variant="rectangular"
width={"100%"}
height={40}
/>
{!isPaymentPage && (
<div className="separator-text mb-10">{t("or")}</div>
)}
</div>
) : (
<></>
)}

{!isPaymentPage && (
<button
Expand Down

0 comments on commit 2ab3093

Please sign in to comment.