src/app/models/app-state.model.ts
Properties |
Methods |
|
Accessors |
constructor(session?: Session)
|
||||||
Defined in src/app/models/app-state.model.ts:27
|
||||||
Parameters :
|
Private isEmailOrPhoneValid |
isEmailOrPhoneValid()
|
Defined in src/app/models/app-state.model.ts:112
|
Returns :
boolean
|
Private isEmailValid |
isEmailValid()
|
Defined in src/app/models/app-state.model.ts:116
|
Returns :
boolean
|
Private isPhoneValid |
isPhoneValid()
|
Defined in src/app/models/app-state.model.ts:126
|
Returns :
boolean
|
accounts |
accounts:
|
Type : BankAccount[]
|
Defined in src/app/models/app-state.model.ts:15
|
acknowledgedDuplicate |
acknowledgedDuplicate:
|
Default value : false
|
Defined in src/app/models/app-state.model.ts:26
|
bankAccount |
bankAccount:
|
Type : BankAccount
|
Default value : null
|
Defined in src/app/models/app-state.model.ts:22
|
duplicateInfo |
duplicateInfo:
|
Type : DuplicateInfo
|
Default value : null
|
Defined in src/app/models/app-state.model.ts:27
|
hasPassedMfa |
hasPassedMfa:
|
Default value : false
|
Defined in src/app/models/app-state.model.ts:13
|
hideMaskedAccount |
hideMaskedAccount:
|
Default value : false
|
Defined in src/app/models/app-state.model.ts:25
|
isNew |
isNew:
|
Default value : false
|
Defined in src/app/models/app-state.model.ts:16
|
limitsResult |
limitsResult:
|
Type : LimitsResult
|
Default value : null
|
Defined in src/app/models/app-state.model.ts:21
|
loadingIsLimits |
loadingIsLimits:
|
Default value : false
|
Defined in src/app/models/app-state.model.ts:20
|
multiFactorModel |
multiFactorModel:
|
Type : MultiFactorModel
|
Default value : null
|
Defined in src/app/models/app-state.model.ts:23
|
payment |
payment:
|
Type : Payment
|
Default value : null
|
Defined in src/app/models/app-state.model.ts:19
|
secretWasSet |
secretWasSet:
|
Default value : false
|
Defined in src/app/models/app-state.model.ts:17
|
selectedMethod |
selectedMethod:
|
Type : SelectedMultiFactorMethod
|
Default value : null
|
Defined in src/app/models/app-state.model.ts:24
|
template |
template:
|
Type : Template
|
Default value : null
|
Defined in src/app/models/app-state.model.ts:18
|
useMfaModal |
useMfaModal:
|
Default value : false
|
Defined in src/app/models/app-state.model.ts:14
|
isSecretValid |
getisSecretValid()
|
Defined in src/app/models/app-state.model.ts:36
|
passMfa |
getpassMfa()
|
Defined in src/app/models/app-state.model.ts:40
|
passSecret |
getpassSecret()
|
Defined in src/app/models/app-state.model.ts:63
|
isValid |
getisValid()
|
Defined in src/app/models/app-state.model.ts:91
|
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;
}
}