File

src/app/models/app-state.model.ts

Index

Properties
Methods
Accessors

Constructor

constructor(session?: Session)
Parameters :
Name Type Optional
session Session yes

Methods

Private isEmailOrPhoneValid
isEmailOrPhoneValid()
Returns : boolean
Private isEmailValid
isEmailValid()
Returns : boolean
Private isPhoneValid
isPhoneValid()
Returns : boolean

Properties

accounts
accounts: BankAccount[]
Type : BankAccount[]
acknowledgedDuplicate
acknowledgedDuplicate:
Default value : false
bankAccount
bankAccount: BankAccount
Type : BankAccount
Default value : null
duplicateInfo
duplicateInfo: DuplicateInfo
Type : DuplicateInfo
Default value : null
hasPassedMfa
hasPassedMfa:
Default value : false
hideMaskedAccount
hideMaskedAccount:
Default value : false
isNew
isNew:
Default value : false
limitsResult
limitsResult: LimitsResult
Type : LimitsResult
Default value : null
loadingIsLimits
loadingIsLimits:
Default value : false
multiFactorModel
multiFactorModel: MultiFactorModel
Type : MultiFactorModel
Default value : null
payment
payment: Payment
Type : Payment
Default value : null
secretWasSet
secretWasSet:
Default value : false
selectedMethod
selectedMethod: SelectedMultiFactorMethod
Type : SelectedMultiFactorMethod
Default value : null
template
template: Template
Type : Template
Default value : null
useMfaModal
useMfaModal:
Default value : false

Accessors

isSecretValid
getisSecretValid()
passMfa
getpassMfa()
passSecret
getpassSecret()
isValid
getisValid()
import { MultiFactorTypes } from '../enums/multi-factor-types';
import { SecretTypes } from '../enums/secret-types';
import { BankAccount } from './bank-account.model';
import { DuplicateInfo } from './duplicate-info';
import { LimitsResult } from './limits-result.model';
import { MultiFactorModel } from './multifactor-model-response.model';
import { Payment } from './payment.model';
import { SelectedMultiFactorMethod } from './select-multi-factor-method.model';
import { Session } from './session.model';
import { Template } from './template.model';

export class AppStateModel {
  hasPassedMfa = false;
  useMfaModal = false;
  accounts: BankAccount[];
  isNew = false;
  secretWasSet = false;
  template: Template = null;
  payment: Payment = null;
  loadingIsLimits = false;
  limitsResult: LimitsResult = null;
  bankAccount: BankAccount = null;
  multiFactorModel: MultiFactorModel = null;
  selectedMethod: SelectedMultiFactorMethod = null;
  hideMaskedAccount = false;
  acknowledgedDuplicate = false;
  duplicateInfo: DuplicateInfo = null;

  constructor(session?: Session) {
    if (!session) {
      return;
    }
    this.accounts = session.accounts;
  }

  get isSecretValid(): boolean {
    return !!this.template.secret && (this.secretWasSet || this.passSecret);
  }

  get passMfa(): boolean {
    if (this.hasPassedMfa) {
      return true; // already mfa'd
    }
    if (!this.multiFactorModel) {
      return false;
    }
    if (!this.multiFactorModel.mfaType) {
      return false;
    }
    if (this.limitsResult && this.limitsResult.requiresMfa && !this.hasPassedMfa) {
      return false;
    }
    if (this.multiFactorModel.mfaType === MultiFactorTypes.Never) {
      return true; // never have to mfa unless limits requires it
    }
    const newOnly = this.multiFactorModel.mfaType === MultiFactorTypes.NewOnly;
    if (newOnly && !this.isNew) {
      return true;
    }
    return false;
  }

  get passSecret(): boolean {
    if (!this.template) {
      console.log('no template; do not pass secret');
      return false;
    }
    if (!this.template.secret) {
      console.log('no secret; do not pass secret');
      return false; // if secret is empty string, null, or undefined
    }
    if (this.template.isSecretRequired) {
      console.log('secret is required on template; do not pass secret');
      return false;
    }
    if (!this.multiFactorModel) {
      console.log('no mfa; do not pass secret');
      return false;
    }
    if (this.multiFactorModel.secretType === SecretTypes.Always) {
      console.log('secret always required; do not pass secret');
      return false;
    }
    if (this.multiFactorModel.secretType !== SecretTypes.NewOrModified) {
      console.log('secret type setting unknown; do not pass secret');
      return false;
    }
    return true; // only if NewOrModified and all other conditions
  }

  get isValid(): boolean {
    // console.log({
    //   payment: this.payment,
    //   limitsResult: this.limitsResult,
    //   template: this.template,
    //   isEmailOrPhoneValid: this.isEmailOrPhoneValid()
    // });
    return (
      this.payment !== undefined &&
      this.payment !== null &&
      this.payment.amount > 0 &&
      this.limitsResult !== null &&
      this.limitsResult.isAllowed &&
      this.template !== null &&
      this.template !== undefined &&
      this.payment !== null &&
      this.template.name.length > 0 &&
      this.isEmailOrPhoneValid()
    );
  }

  private isEmailOrPhoneValid() {
    return this.isEmailValid() || this.isPhoneValid();
  }

  private isEmailValid(): boolean {
    const isValid =
      this.template !== null &&
      this.template !== undefined &&
      this.template.p2PPayToEmailAddress !== null &&
      this.template.p2PPayToEmailAddress !== undefined &&
      this.template.p2PPayToEmailAddress.length > 0;
    return isValid;
  }

  private isPhoneValid(): boolean {
    const isValid =
      this.template !== null &&
      this.template !== undefined &&
      this.template.p2PPayToPhoneNumber !== null &&
      this.template.p2PPayToPhoneNumber !== undefined &&
      this.template.p2PPayToPhoneNumber.length > 0;
    return isValid;
  }
}

results matching ""

    No results matching ""