Skip to content
This repository has been archived by the owner on Jan 7, 2025. It is now read-only.

Commit

Permalink
speed updates
Browse files Browse the repository at this point in the history
  • Loading branch information
harshasomisetty committed Aug 13, 2023
1 parent a460a68 commit ebc071c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const processTransaction = async (

// TODO: If we're gonna time out, we should requeue this
while (rpcTransaction == null) {
await delay(1000);
await delay(500);
rpcTransaction = await fetchTransaction(signature);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const withAuth = (cookies: string[] | undefined): MerchantAuthToken => {
throw new UnauthorizedRequestError('Token has expired');
}
} else {
if (useAuthMock !== null && useAuthMock !== undefined) {
if (useAuthMock) {
const payload = {
id: useAuthMock,
iat: Math.floor(Date.now() / 1000),
Expand Down
36 changes: 21 additions & 15 deletions apps/payment-ui/src/components/PayToLabel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,36 @@ export const PayToLabel = () => {
const [cart, setCart] = useState<number>(0);
const [isLoading, setIsLoading] = useState(true);

const calculateDiscount = (cart: number, discountRate: number) => (discountRate * cart) / 100;

useEffect(() => {
if (paymentDetails !== null) {
let cart = Number(paymentDetails.usdcSize);
setCart(cart);
setIsLoading(false);
}
}, [paymentDetails]);
if (paymentDetails) {
console.log('in effect', paymentDetails, customerTier);
let cartValue = Number(paymentDetails.usdcSize);

useEffect(() => {
if (customerTier !== null && cart > 0) {
setDiscount(calculateDiscount(cart, customerTier.discount));
console.log('cart value', cartValue);
setCart(cartValue);
if (customerTier && cartValue > 0) {
setDiscount((cartValue * customerTier.discount) / 100);
console.log('discoutn', cartValue * customerTier.discount);
}
setIsLoading(false);
}
}, [customerTier, cart]);
}, [paymentDetails, customerTier]);

function calculateFinalAmount(): number {
if (!loyaltyDetails || !customer || !paymentDetails || !customerTier) {
return 0;
if (!paymentDetails) {
return -1;
}
console.log('final stats', loyaltyDetails, customer, paymentDetails, customerTier);
if (!loyaltyDetails || !customer || !customerTier) {
console.log('no loyalty details', paymentDetails.usdcSize);
return paymentDetails.usdcSize;
}

if (loyaltyDetails?.loyaltyProgram === 'tiers' && customer.customerOwns) {
console.log('cart - disc f, ', cart, discount);
return cart - discount;
} else {
console.log('else', paymentDetails.usdcSize);
return paymentDetails.usdcSize;
}
}
Expand All @@ -73,7 +79,7 @@ export const PayToLabel = () => {
<div className="divider" />
</div>
<CartAmountLoading />
<DiscountAmountLoading />
{showTierDiscount && <DiscountAmountLoading />}
<FeePriceDisplayLoading />
</div>
);
Expand Down

1 comment on commit ebc071c

@vercel
Copy link

@vercel vercel bot commented on ebc071c Aug 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.