From 203e2904d6c16e0f6c14bf54bbd5b04a3f38fabe Mon Sep 17 00:00:00 2001 From: nymkappa <1612910616@pm.me> Date: Sat, 18 May 2024 16:13:58 +0200 Subject: [PATCH] [faucet] block coins request to faucet change address --- .../components/faucet/faucet.component.html | 23 +++++++++++-------- .../app/components/faucet/faucet.component.ts | 10 ++++++-- .../twitter-login.component.html | 2 +- .../mempool-error/mempool-error.component.ts | 1 + 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/frontend/src/app/components/faucet/faucet.component.html b/frontend/src/app/components/faucet/faucet.component.html index 1de123292..b75112708 100644 --- a/frontend/src/app/components/faucet/faucet.component.html +++ b/frontend/src/app/components/faucet/faucet.component.html @@ -18,20 +18,22 @@
} @else if (!user) { -
- To limit abuse,  - authenticate  - or - +
+
+ To limit abuse,  + authenticate  + or +
+
} @else if (error === 'not_available') { -
- To limit abuse,  - become a sponsor  - or - +
+
+ To limit abuse +
+
} @@ -71,6 +73,7 @@
Address is required
Must be a valid testnet4 address
+
You cannot use this address
diff --git a/frontend/src/app/components/faucet/faucet.component.ts b/frontend/src/app/components/faucet/faucet.component.ts index 0dfdb0780..bfb485d0e 100644 --- a/frontend/src/app/components/faucet/faucet.component.ts +++ b/frontend/src/app/components/faucet/faucet.component.ts @@ -1,5 +1,5 @@ import { Component, OnDestroy, OnInit, ChangeDetectorRef } from "@angular/core"; -import { FormBuilder, FormGroup, Validators } from "@angular/forms"; +import { FormBuilder, FormGroup, Validators, ValidatorFn, AbstractControl, ValidationErrors } from "@angular/forms"; import { Subscription } from "rxjs"; import { StorageService } from "../../services/storage.service"; import { ServicesApiServices } from "../../services/services-api.service"; @@ -74,8 +74,14 @@ export class FaucetComponent implements OnInit, OnDestroy { } this.status = status; + const notFaucetAddressValidator = (faucetAddress: string): ValidatorFn => { + return (control: AbstractControl): ValidationErrors | null => { + const forbidden = control.value === faucetAddress; + return forbidden ? { forbiddenAddress: { value: control.value } } : null; + }; + } this.faucetForm = this.formBuilder.group({ - 'address': ['', [Validators.required, Validators.pattern(getRegex('address', 'testnet4'))]], + 'address': ['', [Validators.required, Validators.pattern(getRegex('address', 'testnet4')), notFaucetAddressValidator(this.status.address)]], 'satoshis': [this.status.min, [Validators.required, Validators.min(this.status.min), Validators.max(this.status.max)]] }); diff --git a/frontend/src/app/components/twitter-login/twitter-login.component.html b/frontend/src/app/components/twitter-login/twitter-login.component.html index 2fe2392e0..6ff40bd50 100644 --- a/frontend/src/app/components/twitter-login/twitter-login.component.html +++ b/frontend/src/app/components/twitter-login/twitter-login.component.html @@ -2,5 +2,5 @@ [class]="(disabled ? 'disabled': '') + (customClass ? customClass : 'w-100 btn mt-1 d-flex justify-content-center align-items-center')" style="background-color: #1DA1F2" [style]="width ? 'width: ' + width : ''"> - {{ buttonString }} + {{ buttonString }} diff --git a/frontend/src/app/shared/components/mempool-error/mempool-error.component.ts b/frontend/src/app/shared/components/mempool-error/mempool-error.component.ts index 4bb86f16d..a17c30715 100644 --- a/frontend/src/app/shared/components/mempool-error/mempool-error.component.ts +++ b/frontend/src/app/shared/components/mempool-error/mempool-error.component.ts @@ -25,6 +25,7 @@ const MempoolErrors = { 'faucet_too_soon': `You cannot request any more coins right now. Try again later.`, 'faucet_not_available': `The faucet is not available right now. Try again later.`, 'faucet_maximum_reached': `You are not allowed to request more coins`, + 'faucet_address_not_allowed': `You cannot use this address`, } as { [error: string]: string }; export function isMempoolError(error: string) {