From cdc73997d77f2b62344d966e33919eeee42507fb Mon Sep 17 00:00:00 2001 From: Julien Genestoux Date: Fri, 16 Feb 2024 09:56:25 -0500 Subject: [PATCH] fix(unlock-app, lockmsith): adding computation of credit card discounts (#13355) adding computation of credit card discounts --- locksmith/src/operations/pricingOperations.ts | 2 +- packages/ui/lib/components/Detail/Detail.tsx | 6 +-- .../components/interface/checkout/Lock.tsx | 20 ++++---- .../checkout/main/Confirm/ConfirmCard.tsx | 50 ++++++++----------- .../checkout/main/Confirm/PricingData.tsx | 12 +++-- 5 files changed, 42 insertions(+), 48 deletions(-) diff --git a/locksmith/src/operations/pricingOperations.ts b/locksmith/src/operations/pricingOperations.ts index 2ad9c058a06..344bb6a89d4 100644 --- a/locksmith/src/operations/pricingOperations.ts +++ b/locksmith/src/operations/pricingOperations.ts @@ -374,7 +374,7 @@ export const getUsdPricingForRecipient = async ({ userAddress, data, network, - referrer, + referrer: referrer || networks[network]?.multisig || userAddress, }) const amount = fromDecimal(purchasePrice, decimals) diff --git a/packages/ui/lib/components/Detail/Detail.tsx b/packages/ui/lib/components/Detail/Detail.tsx index a5f421c230e..370b632766d 100644 --- a/packages/ui/lib/components/Detail/Detail.tsx +++ b/packages/ui/lib/components/Detail/Detail.tsx @@ -36,7 +36,7 @@ const Wrapper = classed.div('flex gap-1', { const Label = classed.span('relative text-gray-700', { variants: { size: { - tiny: 'text-sm', + tiny: 'text-xs', small: 'text-base', medium: 'text-lg', large: 'text-2xl', @@ -50,7 +50,7 @@ const Label = classed.span('relative text-gray-700', { const Value = classed.span(`relative font-bold text-black`, { variants: { size: { - tiny: 'text-sm', + tiny: 'text-xs', small: 'text-base', medium: 'text-lg', large: 'text-2xl md:text-4xl', @@ -77,7 +77,7 @@ export const Detail = ({ className, }: DetailProps) => { const SizeMapping: SizeStyleProp = { - tiny: 'sm', + tiny: 'xs', small: 'sm', medium: 'md', large: 'lg', diff --git a/unlock-app/src/components/interface/checkout/Lock.tsx b/unlock-app/src/components/interface/checkout/Lock.tsx index 79894742c31..2d38a9c7f79 100644 --- a/unlock-app/src/components/interface/checkout/Lock.tsx +++ b/unlock-app/src/components/interface/checkout/Lock.tsx @@ -3,6 +3,7 @@ interface PricingProps { usdPrice?: string keyPrice?: string loading?: boolean + extra?: React.ReactNode } export function Pricing({ @@ -10,6 +11,7 @@ export function Pricing({ keyPrice, isCardEnabled, loading = false, + extra = null, }: PricingProps) { if (loading) { return ( @@ -19,19 +21,15 @@ export function Pricing({ ) } - if (isCardEnabled && !usdPrice) { - return ( -
- {keyPrice} -
- ) - } + if (isCardEnabled) { return ( -
- {usdPrice} - {keyPrice} -
+ <> + {extra} +
+ {usdPrice} +
+ ) } return ( diff --git a/unlock-app/src/components/interface/checkout/main/Confirm/ConfirmCard.tsx b/unlock-app/src/components/interface/checkout/main/Confirm/ConfirmCard.tsx index d147665c62f..1f32ab6161a 100644 --- a/unlock-app/src/components/interface/checkout/main/Confirm/ConfirmCard.tsx +++ b/unlock-app/src/components/interface/checkout/main/Confirm/ConfirmCard.tsx @@ -44,7 +44,6 @@ interface CreditCardPricingBreakdownProps { export function CreditCardPricingBreakdown({ unlockServiceFee, - total, creditCardProcessingFee, gasCosts, loading, @@ -52,14 +51,14 @@ export function CreditCardPricingBreakdown({ unlockFeeChargedToUser = true, }: CreditCardPricingBreakdownProps) { return ( -
+

Credit Card Fees{' '} Learn more @@ -68,7 +67,7 @@ export function CreditCardPricingBreakdown({ {unlockFeeChargedToUser && !loading && ( )} - -
- {formatFiatPriceFromCents(total, symbol)} -
-

) @@ -355,23 +342,30 @@ export function ConfirmCard({ } usdPrice={ usdTotalPricing - ? `~${formatNumber( + ? `${formatNumber( usdTotalPricing ).toLocaleString()} ${creditCardCurrencySymbol}` : '' } isCardEnabled={!!creditCardEnabled} - /> - )} - {!isError && pricingData && ( - + ) + } /> )} diff --git a/unlock-app/src/components/interface/checkout/main/Confirm/PricingData.tsx b/unlock-app/src/components/interface/checkout/main/Confirm/PricingData.tsx index ed6de87bf97..7cf6a933aed 100644 --- a/unlock-app/src/components/interface/checkout/main/Confirm/PricingData.tsx +++ b/unlock-app/src/components/interface/checkout/main/Confirm/PricingData.tsx @@ -32,9 +32,11 @@ export function PricingData({ pricingData, lock, payment }: PricingDataProps) { Number(lock!.keyPrice) : 0 - const symbol = payment?.route?.trade - ? payment.route.trade.inputAmount.currency.symbol - : item.symbol + const symbol = ( + payment?.route?.trade + ? payment.route.trade.inputAmount.currency.symbol + : item.symbol + ).toUpperCase() return (
+ {item.amount <= 0 ? 'FREE' : payment?.route @@ -67,7 +69,7 @@ export function PricingData({ pricingData, lock, payment }: PricingDataProps) { .toFixed() ).toLocaleString()} ${symbol}` : `${formatNumber(item.amount).toLocaleString()} ${symbol}`} -
+ )} )