import { Component } from '@angular/core' ; import { FormBuilder } from '@angular/forms' ; import { BehaviorSubject , Observable , timer } from 'rxjs' ; import { scan , takeWhile } from 'rxjs/operators' ; import { OnboardingV3VerifyPhoneService , PhoneVerificationStep , } from './verify-phone.service' ; /**
 * Verify phone component for onboarding v3
 */ @ Component ( { selector : 'm-onboardingV3__phone' , templateUrl : './verify-phone.component.html' , styleUrls : [ './verify-phone.component.ng.scss' ] , } ) export class OnboardingV3VerifyPhoneComponent { /**
     * Holds an observable of a retry countdown.
     */ public retryTimer$ : Observable < number > ; /**
     * FormGroup object
     */ public form = this . fb . group ( { number : [ '' ] , code : [ '' ] , secret : [ '' ] , friendFinding : [ '' ] , } ) ; constructor ( private fb , private service ) { } returns { Observable < boolean > } get inProgress$ ( ) : Observable < boolean > { return this . service . inProgress$ ; } returns { BehaviorSubject < PhoneVerificationStep > } get verificationStep$ ( ) : BehaviorSubject < PhoneVerificationStep > { return this . service . verificationStep$ ; } returns { void } public onSend ( ) { this . service . sendCode ( this . form . get ( 'number' ) . value ) ; this . startRetryTimer ( ) ; } returns { void } public onCodeSubmit ( ) { this . service . verifyCode ( this . form . get ( 'number' ) . value , this . form . get ( 'code' ) . value ) ; } returns { void } public onChangeNumberClick ( ) { this . verificationStep$ . next ( 'InputNumberStep' ) ; } param { number } returns { void } private startRetryTimer ( seconds = 30 ) { this . retryTimer$ = timer ( 0 , 1000 ) . pipe ( scan ( acc => -- acc , seconds ) , takeWhile ( x => x >= 0 ) ) ; } }