From a898a811214ca70cc5bc2d2973ff84324dbd6155 Mon Sep 17 00:00:00 2001 From: Sinclair Chen Date: Mon, 14 Oct 2024 16:09:45 -0700 Subject: [PATCH] lock multi trading by answer ids resolves MAN-1631 --- backend/api/src/multi-sell.ts | 13 ++++++++++++- backend/api/src/place-multi-bet.ts | 15 +++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/backend/api/src/multi-sell.ts b/backend/api/src/multi-sell.ts index 42843017db..b9d59fa010 100644 --- a/backend/api/src/multi-sell.ts +++ b/backend/api/src/multi-sell.ts @@ -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 + ) ) } diff --git a/backend/api/src/place-multi-bet.ts b/backend/api/src/place-multi-bet.ts index 88c9839cfd..852e6d1af2 100644 --- a/backend/api/src/place-multi-bet.ts +++ b/backend/api/src/place-multi-bet.ts @@ -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