From b3d204b128721b8888f60a68d85f5f2aa566c205 Mon Sep 17 00:00:00 2001 From: Ian Philips Date: Fri, 6 May 2022 16:32:03 -0400 Subject: [PATCH] Improve error message --- functions/src/create-answer.ts | 6 ++++-- functions/src/place-bet.ts | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/functions/src/create-answer.ts b/functions/src/create-answer.ts index 82c19bf1..386436a9 100644 --- a/functions/src/create-answer.ts +++ b/functions/src/create-answer.ts @@ -72,11 +72,13 @@ export const createAnswer = functions.runWith({ minInstances: 1 }).https.onCall( console.log('user current invested amount', currentInvested) console.log('mana limit:', manaLimitPerUser) - if (manaLimitPerUser && currentInvested + amount > manaLimitPerUser) + if (manaLimitPerUser && currentInvested + amount > manaLimitPerUser) { + const manaAllowed = manaLimitPerUser - currentInvested return { status: 'error', - message: `Market investment limit is M$${manaLimitPerUser}, you've M$${currentInvested} already`, + message: `Market bet cap is M$${manaLimitPerUser}, M$${manaAllowed} left`, } + } const [lastAnswer] = await getValues( firestore .collection(`contracts/${contractId}/answers`) diff --git a/functions/src/place-bet.ts b/functions/src/place-bet.ts index e7bfe528..35ebdba0 100644 --- a/functions/src/place-bet.ts +++ b/functions/src/place-bet.ts @@ -82,11 +82,13 @@ export const placeBet = functions.runWith({ minInstances: 1 }).https.onCall( console.log('user current invested amount', currentInvested) console.log('mana limit:', manaLimitPerUser) - if (manaLimitPerUser && currentInvested + amount > manaLimitPerUser) + if (manaLimitPerUser && currentInvested + amount > manaLimitPerUser) { + const manaAllowed = manaLimitPerUser - currentInvested return { status: 'error', - message: `Market investment limit is M$${manaLimitPerUser}, you've M$${currentInvested} already`, + message: `Market bet cap is M$${manaLimitPerUser}, M$${manaAllowed} left`, } + } } const newBetDoc = firestore