From 7bb24b80cf112d581b967b2a758ee55796f087d0 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 22 Dec 2024 13:08:51 +0200 Subject: [PATCH] TW-1614: Temple Tap Airdrop confirmation --- .env.dist | 1 + src/config.ts | 3 ++- src/index.ts | 29 ++++++++++++++++++++++++++++- templewallet-backend.json | 3 ++- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/.env.dist b/.env.dist index 129eb32..69d1d45 100644 --- a/.env.dist +++ b/.env.dist @@ -11,3 +11,4 @@ REDIS_URL= ADMIN_USERNAME= ADMIN_PASSWORD= COVALENT_API_KEY= +TEMPLE_TAP_API_URL= diff --git a/src/config.ts b/src/config.ts index 6cb899e..fab6eeb 100644 --- a/src/config.ts +++ b/src/config.ts @@ -14,7 +14,8 @@ export const EnvVars = { ADMIN_USERNAME: getEnv('ADMIN_USERNAME'), ADMIN_PASSWORD: getEnv('ADMIN_PASSWORD'), COVALENT_API_KEY: getEnv('COVALENT_API_KEY'), - ALCHEMY_API_KEY: getEnv('ALCHEMY_API_KEY') + ALCHEMY_API_KEY: getEnv('ALCHEMY_API_KEY'), + TEMPLE_TAP_API_URL: getEnv('TEMPLE_TAP_API_URL') }; for (const name in EnvVars) { diff --git a/src/index.ts b/src/index.ts index 3aff9f2..5ab4bd3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,7 +10,7 @@ import swaggerJSDoc from 'swagger-jsdoc'; import swaggerUi from 'swagger-ui-express'; import { getAdvertisingInfo } from './advertising/advertising'; -import { MIN_ANDROID_APP_VERSION, MIN_IOS_APP_VERSION } from './config'; +import { EnvVars, MIN_ANDROID_APP_VERSION, MIN_IOS_APP_VERSION } from './config'; import getDAppsStats from './getDAppsStats'; import { getMagicSquareQuestParticipants, startMagicSquareQuest } from './magic-square'; import { basicAuth } from './middlewares/basic-auth.middleware'; @@ -398,6 +398,33 @@ app.get('/api/signing-nonce', (req, res) => { } }); +app.post('/api/temple-tap/confirm-airdrop-username', async (req, res) => { + try { + const response = await fetch(new URL('/v1/confirm-airdrop-address', EnvVars.TEMPLE_TAP_API_URL), { + method: 'POST', + body: JSON.stringify(req.body), + headers: { + 'Content-Type': 'application/json' + } + }); + + const statusCode = String(response.status); + const responseBody = await response.text(); + + if (statusCode.startsWith('2') || statusCode.startsWith('4')) { + res.status(response.status).send(responseBody); + + return; + } + + throw new Error(responseBody); + } catch (error) { + console.error('Temple Tap API proxy endpoint exception:', error); + + res.status(500).send({ message: 'Unknown error' }); + } +}); + const swaggerOptions = { swaggerDefinition: { openapi: '3.0.0', diff --git a/templewallet-backend.json b/templewallet-backend.json index 3991301..7fa060f 100644 --- a/templewallet-backend.json +++ b/templewallet-backend.json @@ -12,7 +12,8 @@ "ALICE_BOB_PUBLIC_KEY": "SECRET_VALUE", "ALICE_BOB_PRIVATE_KEY": "SECRET_VALUE", "THREE_ROUTE_API_URL": "SECRET_VALUE", - "THREE_ROUTE_API_AUTH_TOKEN": "SECRET_VALUE" + "THREE_ROUTE_API_AUTH_TOKEN": "SECRET_VALUE", + "TEMPLE_TAP_API_URL": "SECRET_VALUE" } } ]