From 53907d2d5271bb180e059965860a6fd04fb40443 Mon Sep 17 00:00:00 2001 From: mantikoros Date: Mon, 13 Dec 2021 11:58:47 -0600 Subject: [PATCH] user.balanceUsd => user.balance --- functions/src/place-bet.ts | 6 +++--- functions/src/types/user.ts | 2 +- web/lib/firebase/users.ts | 4 ++-- web/pages/account.tsx | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/functions/src/place-bet.ts b/functions/src/place-bet.ts index 5dc4f44f..6a1e737a 100644 --- a/functions/src/place-bet.ts +++ b/functions/src/place-bet.ts @@ -30,7 +30,7 @@ export const placeBet = functions.runWith({ minInstances: 1 }).https.onCall( return { status: 'error', message: 'User not found' } const user = userSnap.data() as User - if (user.balanceUsd < amount) + if (user.balance < amount) return { status: 'error', message: 'Insufficient balance' } const contractDoc = firestore.doc(`contracts/${contractId}`) @@ -53,7 +53,7 @@ export const placeBet = functions.runWith({ minInstances: 1 }).https.onCall( transaction.create(newBetDoc, newBet) transaction.update(contractDoc, { pot: newPot }) - transaction.update(userDoc, { balanceUsd: newBalance }) + transaction.update(userDoc, { balance: newBalance }) return { status: 'success' } }) @@ -104,7 +104,7 @@ const getNewBetInfo = ( createdTime: Date.now(), } - const newBalance = user.balanceUsd - amount + const newBalance = user.balance - amount return { newBet, newPot, newBalance } } diff --git a/functions/src/types/user.ts b/functions/src/types/user.ts index ad3a84b1..8fae1c0b 100644 --- a/functions/src/types/user.ts +++ b/functions/src/types/user.ts @@ -4,7 +4,7 @@ export type User = { name: string username: string avatarUrl: string - balanceUsd: number + balance: number createdTime: number lastUpdatedTime: number } \ No newline at end of file diff --git a/web/lib/firebase/users.ts b/web/lib/firebase/users.ts index ea9cd7c7..e436b463 100644 --- a/web/lib/firebase/users.ts +++ b/web/lib/firebase/users.ts @@ -14,7 +14,7 @@ export type User = { name: string username: string avatarUrl: string - balanceUsd: number + balance: number createdTime: number lastUpdatedTime: number } @@ -50,7 +50,7 @@ export function listenForLogin(onUser: (_user: User | null) => void) { username: user.displayName?.replace(/\s+/g, '') || 'DefaultUsername', avatarUrl: user.photoURL || '', email: user.email || 'default@blah.com', - balanceUsd: 10000, + balance: 10000, // TODO: use Firestore timestamp? createdTime: Date.now(), lastUpdatedTime: Date.now(), diff --git a/web/pages/account.tsx b/web/pages/account.tsx index 13b89382..ac6681b3 100644 --- a/web/pages/account.tsx +++ b/web/pages/account.tsx @@ -31,7 +31,7 @@ export default function Account() {

{user?.name}

{user?.email}

-

${user?.balanceUsd} USD

+

M${user?.balance}