forked from manifoldmarkets/manifold
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
One free like per day + purchase likes (manifoldmarkets#2424)
* Likes with cost * Show mana * Confirmation dialogs * Include alternate love domain in fromLove calculation * Get one free like per day * Request all sign up bonuses if you create a lover * Make likes clearer
- Loading branch information
Showing
14 changed files
with
269 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { type APIHandler } from 'api/helpers/endpoint' | ||
import { createSupabaseDirectClient } from 'shared/supabase/init' | ||
|
||
export const hasFreeLike: APIHandler<'has-free-like'> = async ( | ||
_props, | ||
auth | ||
) => { | ||
return { | ||
status: 'success', | ||
hasFreeLike: await getHasFreeLike(auth.uid), | ||
} | ||
} | ||
|
||
export const getHasFreeLike = async (userId: string) => { | ||
const pg = createSupabaseDirectClient() | ||
|
||
const likeGivenToday = await pg.oneOrNone<object>( | ||
` | ||
select 1 | ||
from love_likes | ||
where creator_id = $1 | ||
and created_time at time zone 'UTC' at time zone 'America/Los_Angeles' >= (now() at time zone 'UTC' at time zone 'America/Los_Angeles')::date | ||
and created_time at time zone 'UTC' at time zone 'America/Los_Angeles' < ((now() at time zone 'UTC' at time zone 'America/Los_Angeles')::date + interval '1 day') | ||
limit 1 | ||
`, | ||
[userId] | ||
) | ||
return !likeGivenToday | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import * as admin from 'firebase-admin' | ||
import { runTxn } from './run-txn' | ||
import { LIKE_COST } from 'common/love/constants' | ||
|
||
export async function runLikePurchaseTxn(userId: string, targetId: string) { | ||
return admin.firestore().runTransaction(async (fbTransaction) => { | ||
return await runTxn(fbTransaction, { | ||
amount: LIKE_COST, | ||
fromId: userId, | ||
fromType: 'USER', | ||
toId: 'BANK', | ||
toType: 'BANK', | ||
category: 'LIKE_PURCHASE', | ||
token: 'M$', | ||
data: { targetId }, | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.