The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Fix reward amount calculation for flat rewards
Kiran Kb2640bf87964
diff --git a/apps/web/lib/api/sales/construct-reward-amount.ts b/apps/web/lib/api/sales/construct-reward-amount.tsindex 7d4928d8ea..1486e483da 100644--- a/apps/web/lib/api/sales/construct-reward-amount.ts+++ b/apps/web/lib/api/sales/construct-reward-amount.ts@@ -16,14 +16,16 @@ export const constructRewardAmount = ({if (parsedModifiers.success) {const modifiers = parsedModifiers.data;+ const matchPrimary = modifiers.every((m) => {+ const typeMatches = m.type === undefined || m.type === reward.type;+ const durationMatches =+ m.maxDuration === undefined || m.maxDuration === reward.maxDuration;++ return typeMatches && durationMatches;+ });+// If the type AND maxDuration matches the primary, show a range- if (- modifiers.every(- (modifier) =>- modifier.type === reward.type &&- modifier.maxDuration === reward.maxDuration,- )- ) {+ if (matchPrimary) {const min = Math.min(reward.amount,...modifiers.map((modifier) => modifier.amount),@@ -36,7 +38,7 @@ export const constructRewardAmount = ({return reward.type === "percentage"? `${min}% - ${max}%`- : `${formatCurrency(min)} - ${formatCurrency(max)}`;+ : `${formatCurrency(min / 100)} - ${formatCurrency(max / 100)}`;}}}@@ -46,12 +48,12 @@ export const constructRewardAmount = ({// 2. type AND timelines doesn't match the primary rewardreturn reward.type === "percentage"? `${reward.amount}%`- : formatCurrency(reward.amount);+ : formatCurrency(reward.amount / 100);};const formatCurrency = (amount: number) =>currencyFormatter(- amount / 100,+ amount,amount % 100 === 0? undefined: {diff --git a/apps/web/ui/partners/rewards/add-edit-reward-sheet.tsx b/apps/web/ui/partners/rewards/add-edit-reward-sheet.tsxindex 352843124a..0f2ea3bb93 100644--- a/apps/web/ui/partners/rewards/add-edit-reward-sheet.tsx+++ b/apps/web/ui/partners/rewards/add-edit-reward-sheet.tsx@@ -294,10 +294,9 @@ function RewardSheetContent({amount? constructRewardAmount({reward: {- amount,+ amount: type === "flat" ? amount * 100 : amount,type,maxDuration,- modifiers,},}): "amount"diff --git a/apps/web/ui/partners/rewards/rewards-logic.tsx b/apps/web/ui/partners/rewards/rewards-logic.tsxindex 98b4e5448d..62892170cf 100644--- a/apps/web/ui/partners/rewards/rewards-logic.tsx+++ b/apps/web/ui/partners/rewards/rewards-logic.tsx@@ -566,10 +566,9 @@ function ResultTerms({ modifierIndex }: { modifierIndex: number }) {amount? constructRewardAmount({reward: {- amount,+ amount: displayType === "flat" ? amount * 100 : amount,type: displayType,- maxDuration,- modifiers: undefined,+ maxDuration: displayMaxDuration,},}): "amount"