-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): testnet faucet page with recaptcha (#344)
* feat(ui-ux): testnet faucet page * feat(ui-ux): add recaptcha v2 * fix(ui-ux): hide /faucet navigation and page if not in Testnet env * feat(server): nestjs setup * remove nvmrc * fix(ui-ux): evmAddress input and captcha validation * code refactor * code cleanup * feature(api): added api for faucet to allocate fund to user (#346) * feature(api): added api for faucet to allocate fund to user * added e2e test * fixed pr comments * added e2e for ratelimiting * added invalid address test case * fix lint * fix typo * fix lint * fix ci * fix ci * fix ci * fix ci * fix ci * fix ci * fix ci * fix ci * moved faucet dir to apps/web * changed to getRpcUrl instead of getBaseUrl * api testing * fixed the cors issue * removed comment * print out transaction hash or error * ran prettier * removed unused code * fixed lint issues * add import { NestFactory } from '@nestjs/core'; * fix import problems * feat: use user input wallet address * fix: use current connection * fix: cors * fix: use MetascanServerApp * fix: update allowedHeaders MetascanServerApp * feat(server): recaptcha guard on faucet route * feat(ui-ux): handle recaptcha validation when sending funds * add recaptcha public site key in /web/.env file * fix format * fix(server): private validateRecaptcha guard method * update comments * feat(ui-ux): added ux for faucet (#357) * added loader and link to metascan * fixing issue that txnHash does not exist on metascan yet * reverted linking to metascan * revert unnecessayr change for sectionDesc * added more text * Update apps/web/src/pages/faucet/index.tsx Co-authored-by: Harsh R <53080940+fullstackninja864@users.noreply.github.com> * did UI comments & ran prettier * changed to using react-icon * removed react-spinners * set isLoading back to false * ui comments * Update apps/web/src/pages/faucet/index.tsx Co-authored-by: Harsh R <53080940+fullstackninja864@users.noreply.github.com> * Update apps/web/src/pages/faucet/index.tsx Co-authored-by: Harsh R <53080940+fullstackninja864@users.noreply.github.com> * used animate-spin * used tailwind color * revert isLoading value to false * changed to divs * will do button variants in a diff PR * added invalid address error text * enable button even after errors * print default error msg * made recaptcha dark * minor fixes --------- Co-authored-by: Harsh R <53080940+fullstackninja864@users.noreply.github.com> Co-authored-by: Harsh <harshrathi.dev@gmail.com> * fixed package.json * updated ethers version * UI fixes * fix lint * hide faucet page * remove log --------- Co-authored-by: Lyka Labrada <lykalabrada@gmail.com> Co-authored-by: Harsh R <53080940+fullstackninja864@users.noreply.github.com> Co-authored-by: pierregee <pierre@cakedefi.com> Co-authored-by: nattadex <elocinnat99@gmail.com> Co-authored-by: Harsh <harshrathi.dev@gmail.com>
- Loading branch information
1 parent
e0f5721
commit a193692
Showing
37 changed files
with
13,281 additions
and
6,831 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { NestFactory } from '@nestjs/core'; | ||
import { NestFastifyApplication } from '@nestjs/platform-fastify'; | ||
|
||
import { AppModule } from './app.module'; | ||
|
||
/** | ||
* App which starts the default Metascan Server Application | ||
*/ | ||
export class MetascanServerApp<App extends NestFastifyApplication = NestFastifyApplication> { | ||
protected app?: App; | ||
|
||
constructor(protected readonly module: any) {} | ||
|
||
async createNestApp(): Promise<App> { | ||
const app = await NestFactory.create(AppModule); | ||
await this.configureApp(app); | ||
// @ts-ignore | ||
return app; | ||
} | ||
|
||
async configureApp(app): Promise<void> { | ||
app.enableCors({ | ||
allowedHeaders: '*', | ||
methods: ['GET', 'PUT', 'POST', 'DELETE'], | ||
maxAge: 60 * 24 * 7, | ||
origin: | ||
process.env.NODE_ENV === 'production' | ||
? [ | ||
'https://meta.defiscan.live/', | ||
/https:\/\/([^.]*.\.)*defimetascan\.app/, // allow all subdomains of defimetascan | ||
/https:\/\/([^.]*.)--defimetascan\.netlify\.app/, // allow all netlify preview deployments | ||
/https?:\/\/localhost(:\d+)?/, // allow localhost connection | ||
] | ||
: '*', | ||
}); | ||
} | ||
|
||
/** | ||
* Run any additional initialisation steps before starting the server. | ||
* If there are additional steps, can be overriden by any extending classes | ||
*/ | ||
async init() { | ||
this.app = await this.createNestApp(); | ||
return this.app.init(); | ||
} | ||
|
||
async start(): Promise<App> { | ||
const app = await this.init(); | ||
|
||
const PORT = process.env.PORT || 3001; | ||
await app.listen(PORT).then(() => { | ||
// eslint-disable-next-line no-console | ||
console.log(`Started server on port ${PORT}`); | ||
}); | ||
return app; | ||
} | ||
|
||
/** | ||
* Stop NestJs and un-assign this.app | ||
*/ | ||
async stop(): Promise<void> { | ||
await this.app?.close(); | ||
this.app = undefined; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import { HttpModule } from '@nestjs/axios'; | ||
import { CacheModule } from '@nestjs/cache-manager'; | ||
import { Module } from '@nestjs/common'; | ||
|
||
import { RecaptchaGuard } from '../recaptcha/RecaptchaGuard'; | ||
import { FaucetController } from './FaucetController'; | ||
import { FaucetService } from './FaucetService'; | ||
|
||
@Module({ | ||
imports: [CacheModule.register()], | ||
imports: [CacheModule.register(), HttpModule], | ||
controllers: [FaucetController], | ||
providers: [FaucetService], | ||
providers: [FaucetService, RecaptchaGuard], | ||
}) | ||
export class FaucetModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,9 @@ | ||
import { NestFactory } from '@nestjs/core'; | ||
|
||
import { AppModule } from './app.module'; | ||
import { MetascanServerApp } from './MetascanServerApp'; | ||
|
||
async function bootstrap() { | ||
const app = await NestFactory.create(AppModule); | ||
const PORT = process.env.PORT || 5741; | ||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
app.listen(PORT).then(() => { | ||
// eslint-disable-next-line no-console | ||
console.log(`Started server on port ${PORT}`); | ||
}); | ||
const app = new MetascanServerApp(AppModule); | ||
await app.start(); | ||
} | ||
|
||
void bootstrap(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { HttpService } from '@nestjs/axios'; | ||
import { ExecutionContext, Injectable, Logger } from '@nestjs/common'; | ||
import { Request } from 'express'; | ||
|
||
@Injectable() | ||
export class RecaptchaGuard { | ||
private readonly logger: Logger; | ||
|
||
constructor(private readonly httpService: HttpService) { | ||
this.logger = new Logger(RecaptchaGuard.name); | ||
} | ||
|
||
async canActivate(context: ExecutionContext): Promise<boolean> { | ||
const request = context.switchToHttp().getRequest<Request>(); | ||
return this.validateRecaptcha(request); | ||
} | ||
|
||
private async validateRecaptcha(request: Request): Promise<boolean> { | ||
const response = request.body.recaptchaValue; | ||
|
||
if (!response) { | ||
this.logger.log('Invalid body in recaptcha request'); | ||
return false; | ||
} | ||
|
||
const { data } = await this.httpService | ||
.post( | ||
`https://www.google.com/recaptcha/api/siteverify`, | ||
null, // Since we're sending data in the body, set it to null | ||
{ | ||
params: { | ||
secret: process.env.SECRET_KEY, | ||
response, | ||
}, | ||
}, | ||
) | ||
.toPromise(); | ||
return data.success; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
NEXT_PUBLIC_RPC_URL_MAINNET="https://blockscout.mainnet.ocean.jellyfishsdk.com" | ||
NEXT_PUBLIC_RPC_URL_TESTNET="https://blockscout.testnet.ocean.jellyfishsdk.com" | ||
NEXT_PUBLIC_RPC_URL_CHANGI="https://blockscout.changi.ocean.jellyfishsdk.com" | ||
NEXT_PUBLIC_RPC_URL_CHANGI="https://blockscout.changi.ocean.jellyfishsdk.com" | ||
NEXT_PUBLIC_SERVER_URL="http://localhost:3001/" | ||
|
||
NEXT_PUBLIC_SITE_KEY="6LeeoO8oAAAAALPSYZr1_Itr9bBzzQBVDjgjMT0-" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.