Skip to content
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

lock multi trading by answer ids #2966

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion backend/api/src/multi-sell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,22 @@ import { convertBet } from 'common/supabase/bets'
import { betsQueue } from 'shared/helpers/fn-queue'
import { getAnswersForContract } from 'shared/supabase/answers'
import { getContractMetrics } from 'shared/helpers/user-contract-metrics'
import { buildArray } from 'common/util/array'
import { createSupabaseDirectClient } from 'shared/supabase/init'

export const multiSell: APIHandler<'multi-sell'> = async (props, auth, req) => {
const pg = createSupabaseDirectClient()
const c = await pg.oneOrNone(
`select data->'shouldAnswersSumToOne')::boolean as sum_to_one from contracts where id = $1`,
[props.contractId]
)

return await betsQueue.enqueueFn(
() => multiSellMain(props, auth, req),
[props.contractId, auth.uid]
buildArray(
auth.uid,
!c || c.sum_to_one ? props.contractId : props.answerIds
)
)
}

Expand Down
15 changes: 13 additions & 2 deletions backend/api/src/place-multi-bet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,29 @@ import {
import { log } from 'shared/utils'
import { runShortTrans } from 'shared/short-transaction'
import { betsQueue } from 'shared/helpers/fn-queue'
import { buildArray } from 'common/util/array'
import { createSupabaseDirectClient } from 'shared/supabase/init'

export const placeMultiBet: APIHandler<'multi-bet'> = async (props, auth) => {
const isApi = auth.creds.kind === 'key'

const pg = createSupabaseDirectClient()
const c = await pg.oneOrNone(
`select data->'shouldAnswersSumToOne')::boolean as sum_to_one from contracts where id = $1`,
[props.contractId]
)

return await betsQueue.enqueueFn(
() => placeMultiBetMain(props, auth.uid, isApi),
[auth.uid, props.contractId]
buildArray(
auth.uid,
!c || c.sum_to_one ? props.contractId : props.answerIds
)
)
}

// Note: this returns a continuation function that should be run for consistency.
export const placeMultiBetMain = async (
const placeMultiBetMain = async (
body: ValidatedAPIParams<'multi-bet'>,
uid: string,
isApi: boolean
Expand Down
Loading