Skip to content

Commit

Permalink
Allow select mods to resolve sweepstakes (#3207)
Browse files Browse the repository at this point in the history
* sweepstakes_mods logic and remove "resolved by"

* Change sweepstakes resolved notification to always attribute Manifold as resolver
  • Loading branch information
SirSaltyy authored Dec 10, 2024
1 parent 2d6d932 commit a530f66
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 16 deletions.
6 changes: 4 additions & 2 deletions backend/api/src/resolve-market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { resolveLoveMarketOtherAnswers } from 'shared/love/love-markets'
import { betsQueue } from 'shared/helpers/fn-queue'
import { createSupabaseDirectClient } from 'shared/supabase/init'
import { broadcastUserUpdates } from 'shared/supabase/users'
import { SWEEPSTAKES_MOD_IDS } from 'common/envs/constants'

export const resolveMarket: APIHandler<'market/:contractId/resolve'> = async (
props,
Expand Down Expand Up @@ -65,11 +66,12 @@ export const resolveMarketMain: APIHandler<
if (
isProd() &&
contract.token === 'CASH' &&
auth.uid !== HOUSE_LIQUIDITY_PROVIDER_ID
auth.uid !== HOUSE_LIQUIDITY_PROVIDER_ID &&
!SWEEPSTAKES_MOD_IDS.includes(auth.uid)
) {
throw new APIError(
403,
'Only the Manifold account can resolve prize cash markets'
'Only the Manifold account and approved mods can resolve prize cash markets'
)
}

Expand Down
7 changes: 7 additions & 0 deletions common/src/envs/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ export function isAdminId(id: string) {
export function isModId(id: string) {
return MOD_IDS.includes(id)
}
export function isSweepstakesModId(id: string) {
return SWEEPSTAKES_MOD_IDS.includes(id)
}
export const DOMAIN = ENV_CONFIG.domain
export const LOVE_DOMAIN = ENV_CONFIG.loveDomain
export const LOVE_DOMAIN_ALTERNATE = ENV_CONFIG.loveDomainAlternate
Expand Down Expand Up @@ -206,6 +209,10 @@ export const MOD_IDS = [
'oPxjIzlvC5fRbGCaVgkvAiyoXBB2', // mattyb
]

export const SWEEPSTAKES_MOD_IDS = [
'uglwf3YKOZNGjjEXKc5HampOFRE2', //SirSalty
]

export const MVP = ['Eliza', 'Gabrielle', 'jacksonpolack']

export const VERIFIED_USERNAMES = [
Expand Down
21 changes: 16 additions & 5 deletions web/components/contract/contract-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,21 @@ import { UserHovercard } from '../user/user-hovercard'
import { useDisplayUserById } from 'web/hooks/use-user-supabase'

export function AuthorInfo(props: {
contract: Contract
resolverId?: string // live updated
creatorId: string
creatorName: string
creatorUsername: string
creatorAvatarUrl?: string
token: string
resolverId?: string
}) {
const { contract, resolverId } = props
const { creatorId, creatorName, creatorUsername, creatorAvatarUrl } = contract
const {
creatorId,
creatorName,
creatorUsername,
creatorAvatarUrl,
token,
resolverId,
} = props
const resolver = useDisplayUserById(resolverId)
return (
<Row className="grow flex-wrap items-center gap-4">
Expand All @@ -46,7 +56,8 @@ export function AuthorInfo(props: {
className={'mr-1'}
/>
</UserHovercard>
{resolver && resolver.id !== contract.creatorId && (

{resolver && resolver.id !== creatorId && token !== 'CASH' && (
<span>
resolved by{' '}
<UserHovercard userId={resolver.id}>
Expand Down
6 changes: 5 additions & 1 deletion web/components/contract/contract-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,11 @@ export function ContractPageContent(props: ContractParams) {
</Col>
<Row className="text-ink-600 flex-wrap items-center justify-between gap-y-1 text-sm">
<AuthorInfo
contract={props.contract}
creatorId={props.contract.creatorId}
creatorName={props.contract.creatorName}
creatorUsername={props.contract.creatorUsername}
creatorAvatarUrl={props.contract.creatorAvatarUrl}
token={liveContract.token}
resolverId={liveContract.resolverId}
/>
<ContractSummaryStats
Expand Down
9 changes: 7 additions & 2 deletions web/components/contract/danger-zone.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Contract, MINUTES_ALLOWED_TO_UNRESOLVE } from 'common/contract'
import { useEffect } from 'react'
import { useAdmin, useTrusted } from 'web/hooks/use-admin'
import {
useAdmin,
useSweepstakesTrusted,
useTrusted,
} from 'web/hooks/use-admin'
import { useUser } from 'web/hooks/use-user'
import { Button } from '../buttons/button'
import { DeleteMarketButton } from '../buttons/delete-market-button'
Expand Down Expand Up @@ -41,6 +45,7 @@ export function DangerZone(props: {

const isAdmin = useAdmin()
const isMod = useTrusted()
const isSweepstakesTrusted = useSweepstakesTrusted()
const user = useUser()
const isCreator = user?.id === creatorId
const isClosed = !!closeTime && closeTime < Date.now()
Expand All @@ -63,7 +68,7 @@ export function DangerZone(props: {
!isResolved &&
outcomeType !== 'STONK' &&
mechanism !== 'none' &&
(token === 'CASH' ? isAdmin : isCreator || isAdmin || isMod)
(token === 'CASH' ? isSweepstakesTrusted : isCreator || isAdmin || isMod)

const now = dayjs().utc()
const creatorCanUnresolve =
Expand Down
27 changes: 22 additions & 5 deletions web/components/notifications/notification-types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -798,13 +798,27 @@ export function MarketResolvedNotification(props: {

const resolvedByAdmin = sourceUserUsername != sourceContractCreatorUsername

const showManifoldAsResolver = token === 'CASH'

const resolverName = showManifoldAsResolver
? MANIFOLD_USER_NAME
: resolvedByAdmin
? 'A mod'
: sourceUserName
const resolverUsername = showManifoldAsResolver
? MANIFOLD_USER_USERNAME
: sourceUserUsername
const resolverAvatarUrl = showManifoldAsResolver
? MANIFOLD_AVATAR_URL
: notification.sourceUserAvatarUrl

const content =
sourceText === 'CANCEL' ? (
<>
<NotificationUserLink
userId={sourceId}
name={resolvedByAdmin ? 'A mod' : sourceUserName}
username={sourceUserUsername}
name={resolverName}
username={resolverUsername}
/>{' '}
cancelled {isChildOfGroup && <span>the question</span>}
{!isChildOfGroup && (
Expand All @@ -821,8 +835,8 @@ export function MarketResolvedNotification(props: {
<>
<NotificationUserLink
userId={sourceId}
name={resolvedByAdmin ? 'A mod' : sourceUserName}
username={sourceUserUsername}
name={resolverName}
username={resolverUsername}
/>{' '}
resolved {isChildOfGroup && <span>the question</span>}
{!isChildOfGroup && (
Expand Down Expand Up @@ -878,7 +892,10 @@ export function MarketResolvedNotification(props: {
icon={
<>
<AvatarNotificationIcon
notification={notification}
notification={{
...notification,
sourceUserAvatarUrl: resolverAvatarUrl,
}}
symbol={sourceText === 'CANCEL' ? '🚫' : profitable ? '💰' : '☑️'}
/>
{!!secondaryTitle && (
Expand Down
7 changes: 6 additions & 1 deletion web/hooks/use-admin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useUser } from './use-user'
import { isAdminId, isModId } from 'common/envs/constants'
import { isAdminId, isModId, isSweepstakesModId } from 'common/envs/constants'

export const useAdmin = () => {
const user = useUser()
Expand All @@ -16,6 +16,11 @@ export const useTrusted = () => {
return user ? isModId(user.id) : false
}

export const useSweepstakesTrusted = () => {
const user = useUser()
return user ? isAdminId(user.id) || isSweepstakesModId(user.id) : false
}

export const useDev = () => {
return process.env.NODE_ENV === 'development'
}

0 comments on commit a530f66

Please sign in to comment.