From 5d561acdf804187e8905d2d745e09aa80cc1e7d6 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Mon, 10 Oct 2022 14:23:16 -0500 Subject: [PATCH 1/2] Fix NaN --- common/calculate.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/calculate.ts b/common/calculate.ts index 44dc9113..47fee8c6 100644 --- a/common/calculate.ts +++ b/common/calculate.ts @@ -215,7 +215,7 @@ export function getContractBetMetrics(contract: Contract, yourBets: Bet[]) { } const profit = payout + saleValue + redeemed - totalInvested - const profitPercent = (profit / totalInvested) * 100 + const profitPercent = totalInvested === 0 ? 0 : (profit / totalInvested) * 100 const invested = isCpmm ? getCpmmInvested(yourBets) : getDpmInvested(yourBets) const hasShares = Object.values(totalShares).some( From cdc64c647525ae909d7e6b5794cd72e493e82147 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Mon, 10 Oct 2022 14:55:33 -0500 Subject: [PATCH 2/2] Correctly configure env var for firebase functions --- functions/.env.dev | 3 +++ functions/{.env => .env.prod} | 0 functions/package.json | 2 +- functions/src/update-metrics.ts | 4 +++- 4 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 functions/.env.dev rename functions/{.env => .env.prod} (100%) diff --git a/functions/.env.dev b/functions/.env.dev new file mode 100644 index 00000000..b5aae225 --- /dev/null +++ b/functions/.env.dev @@ -0,0 +1,3 @@ +# This sets which EnvConfig is deployed to Firebase Cloud Functions + +NEXT_PUBLIC_FIREBASE_ENV=DEV diff --git a/functions/.env b/functions/.env.prod similarity index 100% rename from functions/.env rename to functions/.env.prod diff --git a/functions/package.json b/functions/package.json index 0397c5db..cd2a9ec5 100644 --- a/functions/package.json +++ b/functions/package.json @@ -5,7 +5,7 @@ "firestore": "dev-mantic-markets.appspot.com" }, "scripts": { - "build": "yarn compile && rm -rf dist && mkdir -p dist/functions && cp -R ../common/lib dist/common && cp -R lib/src dist/functions/src && cp ../yarn.lock dist && cp package.json dist && cp .env dist", + "build": "yarn compile && rm -rf dist && mkdir -p dist/functions && cp -R ../common/lib dist/common && cp -R lib/src dist/functions/src && cp ../yarn.lock dist && cp package.json dist && cp .env.prod dist && cp .env.dev dist", "compile": "tsc -b", "watch": "tsc -w", "shell": "yarn build && firebase functions:shell", diff --git a/functions/src/update-metrics.ts b/functions/src/update-metrics.ts index 39faadbf..5dfb1eeb 100644 --- a/functions/src/update-metrics.ts +++ b/functions/src/update-metrics.ts @@ -30,7 +30,9 @@ const firestore = admin.firestore() export const scheduleUpdateMetrics = functions.pubsub .schedule('every 15 minutes') .onRun(async () => { - const response = await fetch(getFunctionUrl('updatemetrics'), { + const url = getFunctionUrl('updatemetrics') + console.log('Scheduling update metrics', url) + const response = await fetch(url, { headers: { 'Content-Type': 'application/json', },