Skip to content

Commit

Permalink
feat(unlock-app, locksmith) not charging les than 50 cts (#14474)
Browse files Browse the repository at this point in the history
* not charging les than 50 cts

* linting
  • Loading branch information
julien51 authored Aug 28, 2024
1 parent 717ee04 commit 907f119
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
8 changes: 7 additions & 1 deletion locksmith/src/utils/pricing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,17 @@ export const getFees = async (
)

const feePaidByUser = unlockFeeChargedToUser ? unlockServiceFee : 0
let total = feePaidByUser + creditCardProcessingFee + subtotal + gasCost

if (total < MIN_PAYMENT_STRIPE_CREDIT_CARD) {
total = MIN_PAYMENT_STRIPE_CREDIT_CARD
}

return {
unlockServiceFee,
creditCardProcessingFee,
gasCost,
total: feePaidByUser + creditCardProcessingFee + subtotal + gasCost,
total,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export function CreditCardPricingBreakdown({
loading,
symbol = 'USD',
unlockFeeChargedToUser = true,
total,
}: CreditCardPricingBreakdownProps) {
return (
<div className="flex flex-col gap-2 pt-4 text-xs">
Expand All @@ -65,11 +66,11 @@ export function CreditCardPricingBreakdown({
<span>Learn more</span> <ExternalLinkIcon className="inline" />
</a>
</h3>
<div className="divide-y">
<div className="border-b">
{unlockFeeChargedToUser && !loading && (
<Detail
loading={loading}
className="flex justify-between w-full py-2 text-xs border-t border-gray-300"
className="flex justify-between w-full py-1 text-xs border-t border-gray-300"
label="Service Fee"
labelSize="tiny"
valueSize="tiny"
Expand All @@ -83,7 +84,7 @@ export function CreditCardPricingBreakdown({
{!!creditCardProcessingFee && (
<Detail
loading={loading}
className="flex justify-between w-full py-2 text-sm"
className="flex justify-between w-full py-1 text-sm"
label="Payment Processor"
labelSize="tiny"
valueSize="tiny"
Expand All @@ -97,7 +98,7 @@ export function CreditCardPricingBreakdown({
{!!gasCosts && (
<Detail
loading={loading}
className="flex justify-between w-full py-2 text-sm"
className="flex justify-between w-full py-1 text-sm"
label="Minting (gas) cost"
labelSize="tiny"
valueSize="tiny"
Expand All @@ -108,6 +109,16 @@ export function CreditCardPricingBreakdown({
</div>
</Detail>
)}
{total == 50 && (
<Detail
loading={loading}
className="flex justify-between w-full py-1"
label="(The minimum charge is $0.50)"
labelSize="tiny"
valueSize="tiny"
inline
/>
)}
</div>
</div>
)
Expand Down Expand Up @@ -164,11 +175,10 @@ export function ConfirmCard({ checkoutService, onConfirmed, onError }: Props) {
config.networks[lock!.network].nativeCurrency.symbol
),
})
const { data: { creditCardPrice, unlockFeeChargedToUser } = {} } =
useGetLockSettings({
network: lock!.network,
lockAddress: lock!.address,
})
const { data: { unlockFeeChargedToUser } = {} } = useGetLockSettings({
network: lock!.network,
lockAddress: lock!.address,
})

const isPricingDataAvailable =
!isPricingDataLoading && !isPricingDataError && !!pricingData
Expand All @@ -191,9 +201,6 @@ export function ConfirmCard({ checkoutService, onConfirmed, onError }: Props) {
purchaseData: purchaseData || [],
})

// show gas cost only when custom credit card price is present
const gasCosts = creditCardPrice ? totalPricing?.gasCost : undefined

const { mutateAsync: capturePayment } = useCapturePayment({
network: lock!.network,
lockAddress: lock!.address,
Expand Down Expand Up @@ -349,7 +356,7 @@ export function ConfirmCard({ checkoutService, onConfirmed, onError }: Props) {
totalPricing?.creditCardProcessingFee
}
unlockServiceFee={totalPricing?.unlockServiceFee ?? 0}
gasCosts={gasCosts}
gasCosts={totalPricing?.gasCost}
symbol={creditCardCurrencySymbol}
unlockFeeChargedToUser={unlockFeeChargedToUser}
/>
Expand Down

0 comments on commit 907f119

Please sign in to comment.