-
Notifications
You must be signed in to change notification settings - Fork 8
Dynamic payouts #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Dynamic payouts #27
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -235,9 +235,18 @@ export const PATCH = withParams(PERMS.certs_edit)(async ({ user, req, params, ip | |
| } | ||
|
|
||
| if (verdict.toLowerCase() === 'approved' || verdict.toLowerCase() === 'rejected') { | ||
| const payout = await calc(user.id, cert.projectType, cert.customBounty) | ||
| const payout = await calc({ | ||
| userId: user.id, | ||
| projectType: cert.projectType, | ||
| verdict: verdict.toLowerCase() as 'approved' | 'rejected', | ||
| certCreatedAt: cert.createdAt, | ||
| customBounty: cert.customBounty, | ||
|
Comment on lines
236
to
+243
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: A race condition exists where concurrent review certifications can both receive the same daily bonus multiplier, as the payout is calculated before the review completion is saved to the database. Suggested FixWrap the critical section of the PATCH endpoint, from reading the review count with Prompt for AI Agent |
||
| }) | ||
| updateData.cookiesEarned = payout.cookies | ||
| updateData.payoutMulti = payout.multi | ||
|
|
||
| const effectiveMulti = | ||
| payout.base > 0 ? (payout.cookies - (payout.customBounty || 0)) / payout.base : 0 | ||
| updateData.payoutMulti = Number(effectiveMulti.toFixed(2)) | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,128 +1,128 @@ | ||
| 'use client' | ||
|
|
||
| import { | ||
| LineChart, | ||
| Line, | ||
| BarChart, | ||
| Bar, | ||
| XAxis, | ||
| YAxis, | ||
| Tooltip, | ||
| ResponsiveContainer, | ||
| CartesianGrid, | ||
| LineChart, | ||
| Line, | ||
| BarChart, | ||
| Bar, | ||
| XAxis, | ||
| YAxis, | ||
| Tooltip, | ||
| ResponsiveContainer, | ||
| CartesianGrid, | ||
| } from 'recharts' | ||
|
|
||
| interface Props { | ||
| data: Array<{ date?: string; label?: string; value: number;[key: string]: any }> | ||
| type?: 'line' | 'bar' | ||
| dataKey?: string | ||
| xKey?: string | ||
| yLabel?: string | ||
| xLabel?: string | ||
| valueLabel?: string | ||
| color?: string | ||
| data: Array<{ date?: string; label?: string; value: number; [key: string]: any }> | ||
| type?: 'line' | 'bar' | ||
| dataKey?: string | ||
| xKey?: string | ||
| yLabel?: string | ||
| xLabel?: string | ||
| valueLabel?: string | ||
| color?: string | ||
| } | ||
|
|
||
| export function Chart({ | ||
| data, | ||
| type = 'line', | ||
| dataKey = 'value', | ||
| xKey = 'date', | ||
| yLabel = 'Value', | ||
| xLabel = 'Date', | ||
| valueLabel = 'Value', | ||
| color = '#f59e0b', | ||
| data, | ||
| type = 'line', | ||
| dataKey = 'value', | ||
| xKey = 'date', | ||
| yLabel = 'Value', | ||
| xLabel = 'Date', | ||
| valueLabel = 'Value', | ||
| color = '#f59e0b', | ||
| }: Props) { | ||
| const formatDate = (dateStr: string) => { | ||
| const date = new Date(dateStr) | ||
| const month = date.toLocaleString('en-US', { month: 'short' }) | ||
| const day = date.getDate() | ||
| return `${month} ${day}` | ||
| } | ||
| const formatDate = (dateStr: string) => { | ||
| const date = new Date(dateStr) | ||
| const month = date.toLocaleString('en-US', { month: 'short' }) | ||
| const day = date.getDate() | ||
| return `${month} ${day}` | ||
| } | ||
|
|
||
| const CustomTooltip = ({ active, payload }: any) => { | ||
| if (!active || !payload || !payload.length) return null | ||
| const CustomTooltip = ({ active, payload }: any) => { | ||
| if (!active || !payload || !payload.length) return null | ||
|
|
||
| const date = payload[0].payload[xKey] | ||
| const value = payload[0].value | ||
| const date = payload[0].payload[xKey] | ||
| const value = payload[0].value | ||
|
|
||
| return ( | ||
| <div className="bg-zinc-900 border-2 border-amber-600 rounded px-3 py-2 shadow-xl"> | ||
| <p className="text-amber-400 text-xs font-mono mb-1 font-bold"> | ||
| {date ? formatDate(date) : ''} | ||
| </p> | ||
| <p className="text-amber-100 text-base font-mono font-bold"> | ||
| {valueLabel}: {value} | ||
| </p> | ||
| </div> | ||
| ) | ||
| } | ||
| return ( | ||
| <div className="bg-zinc-900 border-2 border-amber-600 rounded px-3 py-2 shadow-xl"> | ||
| <p className="text-amber-400 text-xs font-mono mb-1 font-bold"> | ||
| {date ? formatDate(date) : ''} | ||
| </p> | ||
| <p className="text-amber-100 text-base font-mono font-bold"> | ||
| {valueLabel}: {value} | ||
| </p> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| const formatXAxis = (value: string) => { | ||
| return formatDate(value) | ||
| } | ||
| const formatXAxis = (value: string) => { | ||
| return formatDate(value) | ||
| } | ||
|
|
||
| return ( | ||
| <ResponsiveContainer width="100%" height={300}> | ||
| {type === 'line' ? ( | ||
| <LineChart data={data} margin={{ top: 10, right: 20, bottom: 60, left: 20 }}> | ||
| <CartesianGrid strokeDasharray="3 3" stroke="#78716c20" /> | ||
| <XAxis | ||
| dataKey={xKey} | ||
| stroke="#78716c" | ||
| style={{ fontSize: '10px' }} | ||
| tickFormatter={formatXAxis} | ||
| interval={0} | ||
| angle={-45} | ||
| textAnchor="end" | ||
| height={60} | ||
| /> | ||
| <YAxis | ||
| stroke="#78716c" | ||
| style={{ fontSize: '11px' }} | ||
| label={{ | ||
| value: yLabel, | ||
| angle: -90, | ||
| position: 'insideLeft', | ||
| fill: '#78716c', | ||
| fontSize: 12, | ||
| }} | ||
| /> | ||
| <Tooltip content={<CustomTooltip />} cursor={false} /> | ||
| return ( | ||
| <ResponsiveContainer width="100%" height={300}> | ||
| {type === 'line' ? ( | ||
| <LineChart data={data} margin={{ top: 10, right: 20, bottom: 60, left: 20 }}> | ||
| <CartesianGrid strokeDasharray="3 3" stroke="#78716c20" /> | ||
| <XAxis | ||
| dataKey={xKey} | ||
| stroke="#78716c" | ||
| style={{ fontSize: '10px' }} | ||
| tickFormatter={formatXAxis} | ||
| interval={0} | ||
| angle={-45} | ||
| textAnchor="end" | ||
| height={60} | ||
| /> | ||
| <YAxis | ||
| stroke="#78716c" | ||
| style={{ fontSize: '11px' }} | ||
| label={{ | ||
| value: yLabel, | ||
| angle: -90, | ||
| position: 'insideLeft', | ||
| fill: '#78716c', | ||
| fontSize: 12, | ||
| }} | ||
| /> | ||
| <Tooltip content={<CustomTooltip />} cursor={false} /> | ||
| <Line type="monotone" dataKey={dataKey} stroke={color} strokeWidth={2} dot={false} /> | ||
| </LineChart> | ||
| ) : ( | ||
| <BarChart data={data} margin={{ top: 10, right: 20, bottom: 60, left: 20 }}> | ||
| <CartesianGrid strokeDasharray="3 3" stroke="#78716c20" /> | ||
| <XAxis | ||
| dataKey={xKey} | ||
| stroke="#78716c" | ||
| style={{ fontSize: '10px' }} | ||
| tickFormatter={formatXAxis} | ||
| interval={0} | ||
| angle={-45} | ||
| textAnchor="end" | ||
| height={60} | ||
| /> | ||
| <YAxis | ||
| stroke="#78716c" | ||
| style={{ fontSize: '11px' }} | ||
| label={{ | ||
| value: yLabel, | ||
| angle: -90, | ||
| position: 'insideLeft', | ||
| fill: '#78716c', | ||
| fontSize: 12, | ||
| }} | ||
| /> | ||
| <Tooltip content={<CustomTooltip />} cursor={false} /> | ||
| <Bar | ||
| dataKey={dataKey} | ||
| fill={color} | ||
| activeBar={{ fill: color, opacity: 0.8, strokeWidth: 2, stroke: color }} | ||
| /> | ||
| </BarChart> | ||
| )} | ||
| </ResponsiveContainer> | ||
| ) | ||
| </LineChart> | ||
| ) : ( | ||
| <BarChart data={data} margin={{ top: 10, right: 20, bottom: 60, left: 20 }}> | ||
| <CartesianGrid strokeDasharray="3 3" stroke="#78716c20" /> | ||
| <XAxis | ||
| dataKey={xKey} | ||
| stroke="#78716c" | ||
| style={{ fontSize: '10px' }} | ||
| tickFormatter={formatXAxis} | ||
| interval={0} | ||
| angle={-45} | ||
| textAnchor="end" | ||
| height={60} | ||
| /> | ||
| <YAxis | ||
| stroke="#78716c" | ||
| style={{ fontSize: '11px' }} | ||
| label={{ | ||
| value: yLabel, | ||
| angle: -90, | ||
| position: 'insideLeft', | ||
| fill: '#78716c', | ||
| fontSize: 12, | ||
| }} | ||
| /> | ||
| <Tooltip content={<CustomTooltip />} cursor={false} /> | ||
| <Bar | ||
| dataKey={dataKey} | ||
| fill={color} | ||
| activeBar={{ fill: color, opacity: 0.8, strokeWidth: 2, stroke: color }} | ||
| /> | ||
| </BarChart> | ||
| )} | ||
| </ResponsiveContainer> | ||
| ) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is half your PR editing indentation?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's just |
||
| } | ||
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.