[faucet] block coins request to faucet change address

This commit is contained in:
nymkappa 2024-05-18 16:13:58 +02:00
parent 38971d33a6
commit 203e2904d6
No known key found for this signature in database
GPG Key ID: 92358FC85D9645DE
4 changed files with 23 additions and 13 deletions

View File

@ -18,20 +18,22 @@
<div class="spinner-border text-light"></div>
} @else if (!user) {
<!-- User not logged in -->
<div class="alert alert-mempool d-block text-center pb-2 w-100">
<span class="mb-2">To limit abuse,&nbsp;</span>
<a routerLink="/login" [queryParams]="{'redirectTo': '/testnet4/faucet'}">authenticate&nbsp;</a>
<span class="mr-2">or</span>
<app-twitter-login customClass="btn" width="220px" redirectTo="/testnet4/faucet" buttonString="Sign up with Twitter"></app-twitter-login>
<div class="alert alert-mempool d-block text-center w-100">
<div class="d-inline align-middle">
<span>To limit abuse,&nbsp;</span>
<a routerLink="/login" [queryParams]="{'redirectTo': '/testnet4/faucet'}">authenticate&nbsp;</a>
<span class="mr-2">or</span>
</div>
<app-twitter-login customClass="btn btn-sm" width="220px" redirectTo="/testnet4/faucet" buttonString="Sign up with Twitter"></app-twitter-login>
</div>
}
@else if (error === 'not_available') {
<!-- User logged in but not a paid user or did not link its Twitter account -->
<div class="alert alert-mempool d-block text-center pb-2 w-100">
<span class="mb-2">To limit abuse,&nbsp;</span>
<a routerLink="/sponsor" [queryParams]="{'redirectTo': '/testnet4/faucet'}">become a sponsor&nbsp;</a>
<span class="mr-2">or</span>
<app-twitter-login customClass="btn" width="220px" redirectTo="/testnet4/faucet" buttonString="Link your Twitter"></app-twitter-login>
<div class="alert alert-mempool d-block text-center w-100">
<div class="d-inline align-middle">
<span class="mb-2 mr-2">To limit abuse</span>
</div>
<app-twitter-login customClass="btn btn-sm" width="180px" redirectTo="/testnet4/faucet" buttonString="Link your Twitter"></app-twitter-login>
</div>
}
@ -71,6 +73,7 @@
<div class="text-danger text-left" *ngIf="invalidAddress">
<div *ngIf="address?.errors?.['required']">Address is required</div>
<div *ngIf="address?.errors?.['pattern']">Must be a valid testnet4 address</div>
<div *ngIf="address?.errors?.['forbiddenAddress']">You cannot use this address</div>
</div>
</div>
</div>

View File

@ -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)]]
});

View File

@ -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 : ''">
<img src="./resources/twitter.svg" height="25" style="padding: 2px" [alt]="buttonString + ' with Twitter'" />
<span class="ml-2 text-light">{{ buttonString }}</span>
<span class="ml-2 text-light align-middle">{{ buttonString }}</span>
</a>

View File

@ -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) {