Skip to content

Commit e358331

Browse files
committed
Don't grant ad credits in free mode
1 parent 664f225 commit e358331

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

cli/src/hooks/use-gravity-ad.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,16 @@ export const useGravityAd = (): GravityAdState => {
9999
return
100100
}
101101

102+
// Include mode in request - FREE mode should not grant credits
103+
const agentMode = useChatStore.getState().agentMode
104+
102105
fetch(`${WEBSITE_URL}/api/v1/ads/impression`, {
103106
method: 'POST',
104107
headers: {
105108
'Content-Type': 'application/json',
106109
Authorization: `Bearer ${authToken}`,
107110
},
108-
body: JSON.stringify({ impUrl }),
111+
body: JSON.stringify({ impUrl, mode: agentMode }),
109112
})
110113
.then((res) => res.json())
111114
.then((data) => {

web/src/app/api/v1/ads/impression/_post.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ function generateImpressionOperationId(userId: string, impUrl: string): string {
9292
const bodySchema = z.object({
9393
// Only impUrl needed - we look up the ad data from our database
9494
impUrl: z.url(),
95+
// Mode to determine if credits should be granted (FREE mode gets no credits)
96+
mode: z.string().optional(),
9597
})
9698

9799
export async function postAdImpression(params: {
@@ -115,6 +117,7 @@ export async function postAdImpression(params: {
115117

116118
// Parse and validate request body
117119
let impUrl: string
120+
let mode: string | undefined
118121
try {
119122
const json = await req.json()
120123
const parsed = bodySchema.safeParse(json)
@@ -125,6 +128,7 @@ export async function postAdImpression(params: {
125128
)
126129
}
127130
impUrl = parsed.data.impUrl
131+
mode = parsed.data.mode
128132
} catch {
129133
return NextResponse.json(
130134
{ error: 'Invalid JSON in request body' },
@@ -230,9 +234,9 @@ export async function postAdImpression(params: {
230234
Math.floor(userShareDollars * 100),
231235
)
232236

233-
// Grant credits if any
234237
let creditsGranted = 0
235-
if (creditsToGrant > 0) {
238+
// FREE mode should not grant any credits
239+
if (mode !== 'FREE' && creditsToGrant > 0) {
236240
try {
237241
await processAndGrantCredit({
238242
userId,
@@ -282,7 +286,7 @@ export async function postAdImpression(params: {
282286
}
283287
}
284288

285-
// Update the ad_impression record with impression details
289+
// Update the ad_impression record with impression details (for ALL modes)
286290
try {
287291
await db
288292
.update(schema.adImpression)
@@ -294,7 +298,7 @@ export async function postAdImpression(params: {
294298
.where(eq(schema.adImpression.id, adRecord.id))
295299

296300
logger.info(
297-
{ userId, impUrl, creditsGranted },
301+
{ userId, impUrl, creditsGranted, creditsToGrant },
298302
'[ads] Updated ad impression record',
299303
)
300304
} catch (error) {

0 commit comments

Comments
 (0)