-
Notifications
You must be signed in to change notification settings - Fork 165
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
Trading ban #2853
base: main
Are you sure you want to change the base?
Trading ban #2853
Changes from all commits
ba32955
e0dc418
170e7ff
7fa80ec
f0d27a3
8105dce
602e651
e4ca16f
4061d16
e8022e6
55eaa89
68a1b3d
119b933
7b7f498
67f1c0b
810b211
074f23b
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { APIError, authEndpoint, validate } from 'api/helpers/endpoint' | ||
import { z } from 'zod' | ||
import { trackPublicEvent } from 'shared/analytics' | ||
import { throwErrorIfNotMod } from 'shared/helpers/auth' | ||
import { isAdminId } from 'common/envs/constants' | ||
import { log } from 'shared/utils' | ||
import { createSupabaseDirectClient } from 'shared/supabase/init' | ||
import { updateUser } from 'shared/supabase/users' | ||
|
||
const bodySchema = z | ||
.object({ | ||
userId: z.string(), | ||
unban: z.boolean().optional(), | ||
}) | ||
.strict() | ||
|
||
export const banUserFromMana = authEndpoint(async (req, auth) => { | ||
const { userId, unban } = validate(bodySchema, req.body) | ||
const pg = createSupabaseDirectClient() | ||
await throwErrorIfNotMod(auth.uid) | ||
if (isAdminId(userId)) throw new APIError(403, 'Cannot ban admin') | ||
await trackPublicEvent(auth.uid, 'ban user from trading mana', { | ||
userId, | ||
}) | ||
await updateUser(pg, userId, { | ||
isBannedFromMana: !unban, | ||
}) | ||
log(`Updated trading ban status for user ${userId}`) | ||
return { success: true } | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,15 +14,15 @@ const bodySchema = z | |
}) | ||
.strict() | ||
|
||
export const banuser = authEndpoint(async (req, auth) => { | ||
export const banUserFromPosting = authEndpoint(async (req, auth) => { | ||
const { userId, unban } = validate(bodySchema, req.body) | ||
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. best to name properties in the positive valence, like |
||
const db = createSupabaseDirectClient() | ||
const pg = createSupabaseDirectClient() | ||
await throwErrorIfNotMod(auth.uid) | ||
if (isAdminId(userId)) throw new APIError(403, 'Cannot ban admin') | ||
await trackPublicEvent(auth.uid, 'ban user', { | ||
userId, | ||
}) | ||
await updateUser(db, userId, { | ||
await updateUser(pg, userId, { | ||
isBannedFromPosting: !unban, | ||
}) | ||
log('updated user') | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { APIError, authEndpoint, validate } from 'api/helpers/endpoint' | ||
import { z } from 'zod' | ||
import { trackPublicEvent } from 'shared/analytics' | ||
import { throwErrorIfNotMod } from 'shared/helpers/auth' | ||
import { isAdminId } from 'common/envs/constants' | ||
import { log } from 'shared/utils' | ||
import { createSupabaseDirectClient } from 'shared/supabase/init' | ||
import { updateUser } from 'shared/supabase/users' | ||
|
||
const bodySchema = z | ||
.object({ | ||
userId: z.string(), | ||
unban: z.boolean().optional(), | ||
}) | ||
.strict() | ||
|
||
export const banUserFromSweepcash = authEndpoint(async (req, auth) => { | ||
const { userId, unban } = validate(bodySchema, req.body) | ||
const pg = createSupabaseDirectClient() | ||
await throwErrorIfNotMod(auth.uid) | ||
if (isAdminId(userId)) throw new APIError(403, 'Cannot ban admin') | ||
await trackPublicEvent(auth.uid, 'ban user from trading sweepcash', { | ||
userId, | ||
}) | ||
await updateUser(pg, userId, { | ||
isBannedFromSweepcash: !unban, | ||
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.
|
||
}) | ||
log(`Updated trading ban status for user ${userId}`) | ||
return { success: true } | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,11 +16,15 @@ import { Answer } from 'common/answer' | |
import { CpmmState, getCpmmProbability } from 'common/calculate-cpmm' | ||
import { ValidatedAPIParams } from 'common/api/schema' | ||
import { onCreateBets } from 'api/on-create-bet' | ||
<<<<<<< trading-ban | ||
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. fix these merge errors |
||
import { isAdminId, TWOMBA_ENABLED } from 'common/envs/constants' | ||
======= | ||
import { | ||
BANNED_TRADING_USER_IDS, | ||
isAdminId, | ||
TWOMBA_ENABLED, | ||
} from 'common/envs/constants' | ||
>>>>>>> main | ||
import * as crypto from 'crypto' | ||
import { formatMoneyWithDecimals } from 'common/util/format' | ||
import { | ||
|
@@ -294,7 +298,15 @@ export const fetchContractBetDataAndValidate = async ( | |
contract.token === 'CASH' ? bet.cash_balance : bet.balance, | ||
]) | ||
) | ||
|
||
const unfilledBetUserIds = Object.keys(balanceByUserId) | ||
if ( | ||
(isAdminId(uid) && contract.token === 'CASH') || | ||
(user.isBannedFromSweepcash && contract.token === 'CASH') | ||
) { | ||
throw new APIError(403, 'Banned from trading on sweepstakes markets.') | ||
} | ||
|
||
const balance = contract.token === 'CASH' ? user.cashBalance : user.balance | ||
if (amount !== undefined && balance < amount) | ||
throw new APIError(403, 'Insufficient balance.') | ||
|
@@ -307,11 +319,16 @@ export const fetchContractBetDataAndValidate = async ( | |
'You must be kyc verified to trade on sweepstakes markets.' | ||
) | ||
} | ||
<<<<<<< trading-ban | ||
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. more merge indicators to remove |
||
if (user.userDeleted) { | ||
throw new APIError(403, 'You are banned or deleted.') | ||
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. just deleted now |
||
======= | ||
if (isAdminId(user.id) && contract.token === 'CASH' && isProd()) { | ||
throw new APIError(403, 'Admins cannot trade on sweepstakes markets.') | ||
} | ||
if (BANNED_TRADING_USER_IDS.includes(user.id) || user.userDeleted) { | ||
throw new APIError(403, 'You are banned or deleted. And not #blessed.') | ||
>>>>>>> main | ||
} | ||
log( | ||
`Loaded user ${user.username} with id ${user.id} betting on slug ${contract.slug} with contract id: ${contract.id}.` | ||
|
@@ -322,7 +339,12 @@ export const fetchContractBetDataAndValidate = async ( | |
log( | ||
`Loaded user ${user.username} with id ${user.id} betting on slug ${contract.slug} with contract id: ${contract.id}.` | ||
) | ||
|
||
if (user.isBannedFromMana && contract.token !== 'CASH') { | ||
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. might as well check for the mana token |
||
throw new APIError(403, 'You are banned from trading mana (or deleted).') | ||
} | ||
log( | ||
`Loaded user ${user.username} with id ${user.id} betting on slug ${contract.slug} with contract id: ${contract.id}.` | ||
) | ||
return { | ||
user, | ||
contract, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,11 +7,7 @@ import { createUser } from 'web/lib/api/api' | |
import { randomString } from 'common/util/random' | ||
import { identifyUser, setUserProperty } from 'web/lib/service/analytics' | ||
import { useStateCheckEquality } from 'web/hooks/use-state-check-equality' | ||
import { | ||
AUTH_COOKIE_NAME, | ||
BANNED_TRADING_USER_IDS, | ||
TEN_YEARS_SECS, | ||
} from 'common/envs/constants' | ||
import { AUTH_COOKIE_NAME, TEN_YEARS_SECS } from 'common/envs/constants' | ||
import { getCookie, setCookie } from 'web/lib/util/cookie' | ||
import { | ||
type PrivateUser, | ||
|
@@ -114,12 +110,13 @@ export function AuthProvider(props: { | |
useEffect(() => { | ||
if (authUser) { | ||
if ( | ||
BANNED_TRADING_USER_IDS.includes(authUser.user.id) || | ||
(authUser.user.isBannedFromPosting && | ||
authUser.user.isBannedFromMana) && authUser.user.isBannedFromSweepcash || | ||
authUser.user.userDeleted | ||
) { | ||
const message = authUser.user.userDeleted | ||
? 'You have deleted the account associated with this email. To restore your account please email [email protected]' | ||
: 'You are banned from trading. To learn more please email [email protected]' | ||
: 'You are banned from Manifold. To learn more please email [email protected]' | ||
|
||
firebaseLogout().then(() => { | ||
alert(message) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would prefer
isBannedFromManaTrading