-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(core): testnet faucet page with recaptcha #344
Merged
Merged
Changes from all commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
a9a6451
feat(ui-ux): testnet faucet page
chloezxyy bbaa14d
feat(ui-ux): add recaptcha v2
chloezxyy 903a20e
fix(ui-ux): hide /faucet navigation and page if not in Testnet env
chloezxyy 86e53db
feat(server): nestjs setup
lykalabrada 7abc99f
remove nvmrc
lykalabrada e089e23
fix(ui-ux): evmAddress input and captcha validation
chloezxyy ae3a8e3
code refactor
chloezxyy c60bf7d
Merge branch 'main' into chloe/testnet-faucet-ui
chloezxyy 77f546f
code cleanup
chloezxyy dced78a
Merge branch 'chloe/testnet-faucet-ui' of https://github.com/Birthday…
chloezxyy 23175ef
feature(api): added api for faucet to allocate fund to user (#346)
fullstackninja864 41e8aa7
fix lint
207daac
fix typo
4081d0a
fix lint
0f8186c
fix ci
e356202
fix ci
ebced18
fix ci
9d56e3c
fix ci
d0d75e6
fix ci
b4b0b41
fix ci
caa2c47
fix ci
90111e1
fix ci
d1f4d05
merged lyka/api-setup branch
nattadex 532d82b
moved faucet dir to apps/web
nattadex e70ff48
changed to getRpcUrl instead of getBaseUrl
nattadex 1588039
api testing
nattadex f763bff
fixed the cors issue
nattadex 098866a
removed comment
nattadex 65d90ad
print out transaction hash or error
nattadex 1b1327a
merge main
nattadex 9fcd32d
ran prettier
nattadex b50c1c5
removed unused code
nattadex baeef45
fixed lint issues
nattadex 792ab66
Merge branch 'main' into chloe/testnet-faucet-ui
chloezxyy 659439d
add import { NestFactory } from '@nestjs/core';
chloezxyy 7373182
fix import problems
chloezxyy 912f623
feat: use user input wallet address
chloezxyy beb6078
fix: use current connection
chloezxyy ef41a8f
fix: cors
chloezxyy 4f4832d
fix: use MetascanServerApp
chloezxyy e9592dd
fix: update allowedHeaders MetascanServerApp
chloezxyy 6425835
feat(server): recaptcha guard on faucet route
chloezxyy 3e1abe8
feat(ui-ux): handle recaptcha validation when sending funds
chloezxyy c245272
add recaptcha public site key in /web/.env file
chloezxyy e35a18a
fix format
chloezxyy 078b434
fix(server): private validateRecaptcha guard method
chloezxyy 0875318
Merge branch 'main' into chloe/testnet-faucet-ui
chloezxyy a0e87eb
update comments
chloezxyy 39585f8
feat(ui-ux): added ux for faucet (#357)
nattadex 2b07d1b
fixed package.json
fullstackninja864 c74ce55
updated ethers version
fullstackninja864 4c19bdc
UI fixes
fullstackninja864 671ccad
fix lint
fullstackninja864 f34bdcc
hide faucet page
fullstackninja864 d0f59dc
remove log
fullstackninja864 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use
5741
now for server port 🙏