File

src/app/services/limits.service.ts

Index

Methods

Constructor

constructor(sessionStore: SessionStore, http: HttpClient)
Parameters :
Name Type Optional
sessionStore SessionStore no
http HttpClient no

Methods

verify
verify(amount?: Number)
Parameters :
Name Type Optional
amount Number yes
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { combineLatest } from 'rxjs/observable/combineLatest';
import { of } from 'rxjs/observable/of';
import { catchError, filter, map } from 'rxjs/operators';
import { ACCOUNT_TYPES, LIMITS_API } from '../app.constants';
import { LimitsResult } from '../models/limits-result.model';
import { SessionStore } from '../stores/session.store';

@Injectable()
export class LimitsService {
  constructor(private sessionStore: SessionStore, private http: HttpClient) {}

  verify(amount?: Number): Observable<LimitsResult> {
    if (!amount) {
      return of(new LimitsResult());
    }

    const callable$ = this.http.get(`${LIMITS_API}/verify?amount=${amount}&type=${ACCOUNT_TYPES.ELECTRONIC}`);
    const session$ = this.sessionStore.session$;

    return combineLatest(session$, callable$).pipe(
      filter(([session, response]) => session !== null && session !== undefined),
      map(([session, response]) => {
        const result = new LimitsResult();
        const limits = session.limits;
        if (limits.electronic.verify < amount) {
          result.requiresMfa = true;
        }
        return result;
      }),
      catchError((response) => {
        // The backedn returned an unsuccessful response code.
        console.error(
          `Backend returned code ${response.status}, ` + `body was: ${response.error}`
        );
        const result = new LimitsResult();
        result.addError(response.error);
        return of(result);
      })
    );
  }
}

results matching ""

    No results matching ""