Skip to content

Commit

Permalink
fix(unlock-app, lockmsith): adding computation of credit card discoun…
Browse files Browse the repository at this point in the history
…ts (#13355)

adding computation of credit card discounts
  • Loading branch information
julien51 committed Feb 16, 2024
1 parent 6100af3 commit cdc7399
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 48 deletions.
2 changes: 1 addition & 1 deletion locksmith/src/operations/pricingOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ export const getUsdPricingForRecipient = async ({
userAddress,
data,
network,
referrer,
referrer: referrer || networks[network]?.multisig || userAddress,
})

const amount = fromDecimal(purchasePrice, decimals)
Expand Down
6 changes: 3 additions & 3 deletions packages/ui/lib/components/Detail/Detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -77,7 +77,7 @@ export const Detail = ({
className,
}: DetailProps) => {
const SizeMapping: SizeStyleProp = {
tiny: 'sm',
tiny: 'xs',
small: 'sm',
medium: 'md',
large: 'lg',
Expand Down
20 changes: 9 additions & 11 deletions unlock-app/src/components/interface/checkout/Lock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ interface PricingProps {
usdPrice?: string
keyPrice?: string
loading?: boolean
extra?: React.ReactNode
}

export function Pricing({
usdPrice,
keyPrice,
isCardEnabled,
loading = false,
extra = null,
}: PricingProps) {
if (loading) {
return (
Expand All @@ -19,19 +21,15 @@ export function Pricing({
</div>
)
}
if (isCardEnabled && !usdPrice) {
return (
<div className="grid text-right whitespace-nowrap">
<span className="font-semibold">{keyPrice}</span>
</div>
)
}

if (isCardEnabled) {
return (
<div className="grid text-right whitespace-nowrap">
<span className="font-semibold">{usdPrice}</span>
<span className="text-sm text-gray-500">{keyPrice} </span>
</div>
<>
{extra}
<div className="grid text-right whitespace-nowrap">
<span className="font-semibold">{usdPrice}</span>
</div>
</>
)
}
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,21 @@ interface CreditCardPricingBreakdownProps {

export function CreditCardPricingBreakdown({
unlockServiceFee,
total,
creditCardProcessingFee,
gasCosts,
loading,
symbol = 'USD',
unlockFeeChargedToUser = true,
}: CreditCardPricingBreakdownProps) {
return (
<div className="flex flex-col gap-2 pt-4 text-sm">
<div className="flex flex-col gap-2 pt-4 text-xs">
<h3 className="font-medium">
Credit Card Fees{' '}
<a
href="https://unlock-protocol.com/guides/enabling-credit-cards/#faq"
target="_blank"
rel="noopener noreferrer"
className="px-2 py-0.5 rounded-lg gap-2 text-xs hover:bg-gray-100 bg-gray-50 text-gray-500 hover:text-black"
className="px-2 py-0.5 rounded-lg gap-2 hover:bg-gray-100 bg-gray-50 text-gray-500 hover:text-black"
>
<span>Learn more</span> <ExternalLinkIcon className="inline" />
</a>
Expand All @@ -68,7 +67,7 @@ export function CreditCardPricingBreakdown({
{unlockFeeChargedToUser && !loading && (
<Detail
loading={loading}
className="flex justify-between w-full py-2 text-sm border-t border-gray-300"
className="flex justify-between w-full py-2 text-xs border-t border-gray-300"
label="Service Fee"
labelSize="tiny"
valueSize="tiny"
Expand Down Expand Up @@ -107,18 +106,6 @@ export function CreditCardPricingBreakdown({
</div>
</Detail>
)}
<Detail
loading={loading}
className="flex justify-between w-full py-2 text-sm border-t border-gray-300"
label="Total"
labelSize="tiny"
valueSize="tiny"
inline
>
<div className="font-normal">
{formatFiatPriceFromCents(total, symbol)}
</div>
</Detail>
</div>
</div>
)
Expand Down Expand Up @@ -355,23 +342,30 @@ export function ConfirmCard({
}
usdPrice={
usdTotalPricing
? `~${formatNumber(
? `${formatNumber(
usdTotalPricing
).toLocaleString()} ${creditCardCurrencySymbol}`
: ''
}
isCardEnabled={!!creditCardEnabled}
/>
)}
{!isError && pricingData && (
<CreditCardPricingBreakdown
loading={isTotalPricingDataLoading || !isTotalPricingDataFetched}
total={totalPricing?.total ?? 0}
creditCardProcessingFee={totalPricing?.creditCardProcessingFee}
unlockServiceFee={totalPricing?.unlockServiceFee ?? 0}
gasCosts={gasCosts}
symbol={creditCardCurrencySymbol}
unlockFeeChargedToUser={unlockFeeChargedToUser}
extra={
!isError &&
pricingData && (
<CreditCardPricingBreakdown
loading={
isTotalPricingDataLoading || !isTotalPricingDataFetched
}
total={totalPricing?.total ?? 0}
creditCardProcessingFee={
totalPricing?.creditCardProcessingFee
}
unlockServiceFee={totalPricing?.unlockServiceFee ?? 0}
gasCosts={gasCosts}
symbol={creditCardCurrencySymbol}
unlockFeeChargedToUser={unlockFeeChargedToUser}
/>
)
}
/>
)}
</main>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div
Expand All @@ -57,7 +59,7 @@ export function PricingData({ pricingData, lock, payment }: PricingDataProps) {

{/* We hide the unit prices since we don't have them when using swap and pay */}
{!payment.route && (
<div className="font-bold">
<span className="font-bold whitespace-nowrap">
{item.amount <= 0
? 'FREE'
: payment?.route
Expand All @@ -67,7 +69,7 @@ export function PricingData({ pricingData, lock, payment }: PricingDataProps) {
.toFixed()
).toLocaleString()} ${symbol}`
: `${formatNumber(item.amount).toLocaleString()} ${symbol}`}
</div>
</span>
)}
</div>
)
Expand Down

0 comments on commit cdc7399

Please sign in to comment.