Skip to content

Commit 6fa6703

Browse files
committed
refactor(billing): bind comparison columns to credit tiers by name
Look up Pro/Max tiers by name instead of array position so the comparison table can't silently bind to the wrong tier if CREDIT_TIERS is reordered or a tier is inserted (addresses Greptile P2). Values unchanged.
1 parent ffd27c0 commit 6fa6703

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

  • apps/sim/app/workspace/[workspaceId]/upgrade/components/comparison-table

apps/sim/app/workspace/[workspaceId]/upgrade/components/comparison-table/comparison-data.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,18 @@ import {
55
DEFAULT_FREE_CREDITS,
66
} from '@/lib/billing/constants'
77

8-
const [PRO_TIER, MAX_TIER] = CREDIT_TIERS
8+
/**
9+
* Looks up a credit tier by name, so a column binds to the right tier even if
10+
* {@link CREDIT_TIERS} is reordered or a tier is inserted.
11+
*/
12+
function tierByName(name: (typeof CREDIT_TIERS)[number]['name']) {
13+
const tier = CREDIT_TIERS.find((t) => t.name === name)
14+
if (!tier) throw new Error(`comparison-data: no credit tier named "${name}"`)
15+
return tier
16+
}
17+
18+
const PRO_TIER = tierByName('Pro')
19+
const MAX_TIER = tierByName('Max')
920

1021
/** Formats a credit count with thousands separators (e.g. 25000 → "25,000"). */
1122
const formatCredits = (credits: number): string => credits.toLocaleString('en-US')

0 commit comments

Comments
 (0)