[faucet] block coins request to faucet change address
This commit is contained in:
		
							parent
							
								
									38971d33a6
								
							
						
					
					
						commit
						203e2904d6
					
				| @ -18,20 +18,22 @@ | |||||||
|       <div class="spinner-border text-light"></div> |       <div class="spinner-border text-light"></div> | ||||||
|     } @else if (!user) { |     } @else if (!user) { | ||||||
|       <!-- User not logged in --> |       <!-- User not logged in --> | ||||||
|       <div class="alert alert-mempool d-block text-center pb-2 w-100"> |       <div class="alert alert-mempool d-block text-center w-100"> | ||||||
|         <span class="mb-2">To limit abuse, </span> |         <div class="d-inline align-middle"> | ||||||
|  |           <span>To limit abuse, </span> | ||||||
|           <a routerLink="/login" [queryParams]="{'redirectTo': '/testnet4/faucet'}">authenticate </a> |           <a routerLink="/login" [queryParams]="{'redirectTo': '/testnet4/faucet'}">authenticate </a> | ||||||
|           <span class="mr-2">or</span> |           <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> | ||||||
|  |         <app-twitter-login customClass="btn btn-sm" width="220px" redirectTo="/testnet4/faucet" buttonString="Sign up with Twitter"></app-twitter-login> | ||||||
|       </div> |       </div> | ||||||
|     } |     } | ||||||
|     @else if (error === 'not_available') { |     @else if (error === 'not_available') { | ||||||
|       <!-- User logged in but not a paid user or did not link its Twitter account --> |       <!-- 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"> |       <div class="alert alert-mempool d-block text-center w-100"> | ||||||
|         <span class="mb-2">To limit abuse, </span> |         <div class="d-inline align-middle"> | ||||||
|         <a routerLink="/sponsor" [queryParams]="{'redirectTo': '/testnet4/faucet'}">become a sponsor </a> |           <span class="mb-2 mr-2">To limit abuse</span> | ||||||
|         <span class="mr-2">or</span> |         </div> | ||||||
|         <app-twitter-login customClass="btn" width="220px" redirectTo="/testnet4/faucet" buttonString="Link your Twitter"></app-twitter-login> |         <app-twitter-login customClass="btn btn-sm" width="180px" redirectTo="/testnet4/faucet" buttonString="Link your Twitter"></app-twitter-login> | ||||||
|       </div> |       </div> | ||||||
|     } |     } | ||||||
|      |      | ||||||
| @ -71,6 +73,7 @@ | |||||||
|               <div class="text-danger text-left" *ngIf="invalidAddress"> |               <div class="text-danger text-left" *ngIf="invalidAddress"> | ||||||
|                 <div *ngIf="address?.errors?.['required']">Address is required</div> |                 <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?.['pattern']">Must be a valid testnet4 address</div> | ||||||
|  |                 <div *ngIf="address?.errors?.['forbiddenAddress']">You cannot use this address</div> | ||||||
|               </div> |               </div> | ||||||
|             </div> |             </div> | ||||||
|           </div> |           </div> | ||||||
|  | |||||||
| @ -1,5 +1,5 @@ | |||||||
| import { Component, OnDestroy, OnInit, ChangeDetectorRef } from "@angular/core"; | 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 { Subscription } from "rxjs"; | ||||||
| import { StorageService } from "../../services/storage.service"; | import { StorageService } from "../../services/storage.service"; | ||||||
| import { ServicesApiServices } from "../../services/services-api.service"; | import { ServicesApiServices } from "../../services/services-api.service"; | ||||||
| @ -74,8 +74,14 @@ export class FaucetComponent implements OnInit, OnDestroy { | |||||||
|         } |         } | ||||||
|         this.status = status; |         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({ |         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)]] |           'satoshis': [this.status.min, [Validators.required, Validators.min(this.status.min), Validators.max(this.status.max)]] | ||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -2,5 +2,5 @@ | |||||||
|   [class]="(disabled ? 'disabled': '') + (customClass ? customClass : 'w-100 btn mt-1 d-flex justify-content-center align-items-center')" |   [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 : ''"> |   style="background-color: #1DA1F2" [style]="width ? 'width: ' + width : ''"> | ||||||
|   <img src="./resources/twitter.svg" height="25" style="padding: 2px" [alt]="buttonString + ' with Twitter'" /> |   <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> | </a> | ||||||
|  | |||||||
| @ -25,6 +25,7 @@ const MempoolErrors = { | |||||||
|   'faucet_too_soon': `You cannot request any more coins right now. Try again later.`, |   '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_not_available': `The faucet is not available right now. Try again later.`, | ||||||
|   'faucet_maximum_reached': `You are not allowed to request more coins`, |   'faucet_maximum_reached': `You are not allowed to request more coins`, | ||||||
|  |   'faucet_address_not_allowed': `You cannot use this address`, | ||||||
| } as { [error: string]: string }; | } as { [error: string]: string }; | ||||||
| 
 | 
 | ||||||
| export function isMempoolError(error: string) { | export function isMempoolError(error: string) { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user