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

Commit

Permalink
small data fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
harshasomisetty committed Aug 13, 2023
1 parent a460a68 commit f6cd5ab
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 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 @@ -6,7 +6,6 @@ import { MerchantService } from '../../services/database/merchant-service.databa
import { fetchBalance } from '../../services/helius.service.js';
import { getConnection } from '../connection.utility.js';
import { ProductDetail, createProductsNftResponse } from './create-products-response.utility.js';

export interface CustomerResponse {
amountSpent: number;
tier: Tier | null;
Expand Down Expand Up @@ -125,10 +124,14 @@ export const createCustomerResponse = async (
let customerOwns =
currentTier && currentTier.mint ? await customerOwnsTier(customerWallet, currentTier.mint) : false;

// console.log('tier status', currentTier, nextPossibleTier, isFirstTier, customerOwns);
let customerNfts = (await createProductsNftResponse(merchant)).customerView[customerWallet];
let customerNfts: ProductDetail[] = [];

try {
customerNfts = (await createProductsNftResponse(merchant)).customerView[customerWallet];
} catch (err) {
console.log('error getting customer nfts', err);
}

// console.log('customer nfts', customerNfts);
return {
amountSpent: customer.amountSpent,
tier: currentTier,
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
29 changes: 14 additions & 15 deletions apps/payment-ui/src/components/PayToLabel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,24 @@ 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) {
let cartValue = Number(paymentDetails.usdcSize);

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

function calculateFinalAmount(): number {
if (!loyaltyDetails || !customer || !paymentDetails || !customerTier) {
return 0;
if (!paymentDetails) {
return -1;
}
if (!loyaltyDetails || !customer || !customerTier) {
return paymentDetails.usdcSize;
}

if (loyaltyDetails?.loyaltyProgram === 'tiers' && customer.customerOwns) {
Expand Down Expand Up @@ -73,7 +72,7 @@ export const PayToLabel = () => {
<div className="divider" />
</div>
<CartAmountLoading />
<DiscountAmountLoading />
{showTierDiscount && <DiscountAmountLoading />}
<FeePriceDisplayLoading />
</div>
);
Expand Down

3 comments on commit f6cd5ab

@vercel
Copy link

@vercel vercel bot commented on f6cd5ab Aug 13, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on f6cd5ab Aug 13, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on f6cd5ab 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.