src/app/stores/app-state.store.ts
Properties |
Methods |
Accessors |
constructor(sessionStore: SessionStore, limitsService: LimitsService)
|
|||||||||
Defined in src/app/stores/app-state.store.ts:32
|
|||||||||
Parameters :
|
clear |
clear()
|
Defined in src/app/stores/app-state.store.ts:219
|
Returns :
void
|
getCombinedInfo |
getCombinedInfo()
|
Defined in src/app/stores/app-state.store.ts:215
|
Returns :
CombinedRequest
|
getContactInfo |
getContactInfo()
|
Defined in src/app/stores/app-state.store.ts:250
|
Returns :
string
|
getDefaultAccount |
getDefaultAccount()
|
Defined in src/app/stores/app-state.store.ts:262
|
Returns :
Observable<BankAccount>
|
onChange | ||||||
onChange(property: string)
|
||||||
Defined in src/app/stores/app-state.store.ts:59
|
||||||
Parameters :
Returns :
void
|
setContactInfo | ||||||
setContactInfo(input: string)
|
||||||
Defined in src/app/stores/app-state.store.ts:228
|
||||||
Parameters :
Returns :
void
|
setSecretWord | ||||||
setSecretWord(secret: string)
|
||||||
Defined in src/app/stores/app-state.store.ts:143
|
||||||
Parameters :
Returns :
void
|
trim | ||||||
trim(input: string)
|
||||||
Defined in src/app/stores/app-state.store.ts:246
|
||||||
Parameters :
Returns :
any
|
Private _session |
_session:
|
Type : Session
|
Defined in src/app/stores/app-state.store.ts:29
|
Private _state |
_state:
|
Default value : new AppStateModel()
|
Defined in src/app/stores/app-state.store.ts:27
|
Private _stateSrc |
_stateSrc:
|
Default value : new BehaviorSubject<AppStateModel>(this._state)
|
Defined in src/app/stores/app-state.store.ts:28
|
Private amountSubject |
amountSubject:
|
Type : Subject<number>
|
Default value : new Subject()
|
Defined in src/app/stores/app-state.store.ts:31
|
Private request |
request:
|
Type : Subscription
|
Defined in src/app/stores/app-state.store.ts:32
|
state$ |
state$:
|
Default value : this._stateSrc.asObservable()
|
Defined in src/app/stores/app-state.store.ts:30
|
isValid |
getisValid()
|
Defined in src/app/stores/app-state.store.ts:64
|
loadingIsLimits | ||||||
getloadingIsLimits()
|
||||||
Defined in src/app/stores/app-state.store.ts:73
|
||||||
setloadingIsLimits(result: boolean)
|
||||||
Defined in src/app/stores/app-state.store.ts:68
|
||||||
Parameters :
Returns :
void
|
limitsResult | ||||
getlimitsResult()
|
||||
Defined in src/app/stores/app-state.store.ts:82
|
||||
setlimitsResult(result: )
|
||||
Defined in src/app/stores/app-state.store.ts:77
|
||||
Parameters :
Returns :
void
|
accounts | ||||||
getaccounts()
|
||||||
Defined in src/app/stores/app-state.store.ts:91
|
||||||
setaccounts(value: [])
|
||||||
Defined in src/app/stores/app-state.store.ts:86
|
||||||
Parameters :
Returns :
void
|
useMfaModal | ||||||
getuseMfaModal()
|
||||||
Defined in src/app/stores/app-state.store.ts:100
|
||||||
setuseMfaModal(value: boolean)
|
||||||
Defined in src/app/stores/app-state.store.ts:95
|
||||||
Parameters :
Returns :
void
|
hasPassedMfa | ||||||
gethasPassedMfa()
|
||||||
Defined in src/app/stores/app-state.store.ts:109
|
||||||
sethasPassedMfa(value: boolean)
|
||||||
Defined in src/app/stores/app-state.store.ts:104
|
||||||
Parameters :
Returns :
void
|
hideMaskedAccount | ||||||
gethideMaskedAccount()
|
||||||
Defined in src/app/stores/app-state.store.ts:118
|
||||||
sethideMaskedAccount(value: boolean)
|
||||||
Defined in src/app/stores/app-state.store.ts:113
|
||||||
Parameters :
Returns :
void
|
isNew | ||||||
getisNew()
|
||||||
Defined in src/app/stores/app-state.store.ts:127
|
||||||
setisNew(value: boolean)
|
||||||
Defined in src/app/stores/app-state.store.ts:122
|
||||||
Parameters :
Returns :
void
|
passMfa |
getpassMfa()
|
Defined in src/app/stores/app-state.store.ts:131
|
passSecret |
getpassSecret()
|
Defined in src/app/stores/app-state.store.ts:135
|
secretWasSet |
getsecretWasSet()
|
Defined in src/app/stores/app-state.store.ts:139
|
template | ||||
gettemplate()
|
||||
Defined in src/app/stores/app-state.store.ts:155
|
||||
settemplate(template: )
|
||||
Defined in src/app/stores/app-state.store.ts:149
|
||||
Parameters :
Returns :
void
|
payment | ||||
getpayment()
|
||||
Defined in src/app/stores/app-state.store.ts:166
|
||||
setpayment(payment: )
|
||||
Defined in src/app/stores/app-state.store.ts:159
|
||||
Parameters :
Returns :
void
|
bankAccount | ||||
getbankAccount()
|
||||
Defined in src/app/stores/app-state.store.ts:175
|
||||
setbankAccount(bankAccount: )
|
||||
Defined in src/app/stores/app-state.store.ts:170
|
||||
Parameters :
Returns :
void
|
multiFactorModel | ||||
getmultiFactorModel()
|
||||
Defined in src/app/stores/app-state.store.ts:184
|
||||
setmultiFactorModel(multiFactorModel: )
|
||||
Defined in src/app/stores/app-state.store.ts:179
|
||||
Parameters :
Returns :
void
|
acknowledgeDuplicate | ||||||
getacknowledgeDuplicate()
|
||||||
Defined in src/app/stores/app-state.store.ts:193
|
||||||
setacknowledgeDuplicate(value: boolean)
|
||||||
Defined in src/app/stores/app-state.store.ts:188
|
||||||
Parameters :
Returns :
void
|
duplicateInfo | ||||
getduplicateInfo()
|
||||
Defined in src/app/stores/app-state.store.ts:202
|
||||
setduplicateInfo(value: )
|
||||
Defined in src/app/stores/app-state.store.ts:197
|
||||
Parameters :
Returns :
void
|
selectedMethod | ||||
getselectedMethod()
|
||||
Defined in src/app/stores/app-state.store.ts:211
|
||||
setselectedMethod(selectedMethod: )
|
||||
Defined in src/app/stores/app-state.store.ts:206
|
||||
Parameters :
Returns :
void
|
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { Observable } from 'rxjs/Observable';
import { debounceTime, filter, first, map } from 'rxjs/operators';
import { Subject } from 'rxjs/Subject';
import { Subscription } from 'rxjs/Subscription';
import {
AppStateModel,
BankAccount,
CombinedRequest,
MultiFactorModel,
Payment,
SelectedMultiFactorMethod,
Session,
Template,
} from '../models';
import { DuplicateInfo } from '../models/duplicate-info';
import { LimitsResult } from '../models/limits-result.model';
import { LimitsService } from '../services/limits.service';
import { SessionStore } from './session.store';
const PHONE = 'PHONE';
const EMAIL = 'EMAIL';
@Injectable()
export class AppState {
private _state = new AppStateModel();
private _stateSrc = new BehaviorSubject<AppStateModel>(this._state);
private _session: Session;
state$ = this._stateSrc.asObservable();
private amountSubject: Subject<number> = new Subject();
private request: Subscription;
constructor(private sessionStore: SessionStore, private limitsService: LimitsService) {
console.log('constructing app state store');
this.sessionStore.session$
.filter((session) => !!session && !!session.accounts)
.subscribe((session) => {
console.log('state store got session');
this._session = session;
this.multiFactorModel = null;
this.accounts = session.accounts;
});
this.amountSubject.pipe(debounceTime(500)).subscribe((amount: number) => {
if (amount === 0) {
return;
}
this.loadingIsLimits = true;
if (this.request) {
this.request.unsubscribe();
}
this.request = this.limitsService.verify(amount).subscribe((result) => {
this.limitsResult = result;
this.loadingIsLimits = false;
});
});
}
onChange(property: string) {
console.log(`on state change: ${property}`);
this._stateSrc.next(this._state);
}
get isValid(): boolean {
return this._state.isValid;
}
set loadingIsLimits(result: boolean) {
this._state.loadingIsLimits = result;
this.onChange('loadingIsLimits');
}
get loadingIsLimits(): boolean {
return this._state.loadingIsLimits;
}
set limitsResult(result: LimitsResult) {
this._state.limitsResult = result;
this.onChange('limitsResult');
}
get limitsResult(): LimitsResult {
return this._state.limitsResult;
}
set accounts(value: BankAccount[]) {
this._state.accounts = value;
this.onChange('accounts');
}
get accounts(): BankAccount[] {
return this._state.accounts;
}
set useMfaModal(value: boolean) {
this._state.useMfaModal = value;
this.onChange('useMfaModal');
}
get useMfaModal(): boolean {
return this._state.useMfaModal;
}
set hasPassedMfa(value: boolean) {
this._state.hasPassedMfa = value;
this.onChange('hasPassedMfa');
}
get hasPassedMfa(): boolean {
return this._state.hasPassedMfa;
}
set hideMaskedAccount(value: boolean) {
this._state.hideMaskedAccount = value;
this.onChange('hideMaskedAccount');
}
get hideMaskedAccount(): boolean {
return this._state.hideMaskedAccount;
}
set isNew(value: boolean) {
this._state.isNew = value;
this.onChange('isNew');
}
get isNew(): boolean {
return this._state.isNew;
}
get passMfa(): boolean {
return this._state.passMfa;
}
get passSecret(): boolean {
return this._state.passSecret;
}
get secretWasSet(): boolean {
return this._state.secretWasSet;
}
setSecretWord(secret: string) {
this._state.template.secret = secret;
this._state.secretWasSet = true;
this.onChange('secret word');
}
set template(template: Template) {
this._state.secretWasSet = false;
this._state.template = template;
this.onChange('template');
}
get template(): Template {
return this._state.template;
}
set payment(payment: Payment) {
this._state.payment = payment;
const nextAmount = payment && payment.amount ? payment.amount : null;
this.amountSubject.next(nextAmount);
this.onChange('payment');
}
get payment(): Payment {
return this._state.payment;
}
set bankAccount(bankAccount: BankAccount) {
this._state.bankAccount = bankAccount;
this.onChange('bankAccount');
}
get bankAccount(): BankAccount {
return this._state.bankAccount;
}
set multiFactorModel(multiFactorModel: MultiFactorModel) {
this._state.multiFactorModel = multiFactorModel;
this.onChange('multiFactorModel');
}
get multiFactorModel(): MultiFactorModel {
return this._state.multiFactorModel;
}
set acknowledgeDuplicate(value: boolean) {
this._state.acknowledgedDuplicate = value;
this.onChange('userHasAcknowledgeDuplicatePayment');
}
get acknowledgeDuplicate(): boolean {
return this._state.acknowledgedDuplicate;
}
set duplicateInfo(value: DuplicateInfo) {
this._state.duplicateInfo = value;
this.onChange('duplicateInfo');
}
get duplicateInfo(): DuplicateInfo {
return this._state.duplicateInfo;
}
set selectedMethod(selectedMethod: SelectedMultiFactorMethod) {
this._state.selectedMethod = selectedMethod;
this.onChange('selectedMethod');
}
get selectedMethod(): SelectedMultiFactorMethod {
return this._state.selectedMethod;
}
getCombinedInfo(): CombinedRequest {
return new CombinedRequest(this.payment, this.template);
}
clear() {
this.template = null;
this.payment = null;
const mfaModel = this._state.multiFactorModel;
this._state = new AppStateModel(this._session);
this._state.multiFactorModel = mfaModel;
this.onChange('cleared all (except mfa model)!');
}
setContactInfo(input: string) {
this.trim(input);
const isPhone = input.indexOf('@') === -1;
if (this.template) {
if (isPhone) {
this.template.p2PPayToEmailAddress = null;
this.template.defaultContactMethod = PHONE;
this.template.p2PPayToPhoneNumber = input;
this.onChange('setContactInfo');
return;
}
this.template.p2PPayToPhoneNumber = null;
this.template.defaultContactMethod = EMAIL;
this.template.p2PPayToEmailAddress = input;
this.onChange('setContactInfo');
}
}
trim(input: string) {
return input.replace(/\s/g, '');
}
getContactInfo(): string {
if (!this.template) {
return null;
}
switch (this.template.defaultContactMethod) {
case EMAIL:
return this.template.p2PPayToEmailAddress;
case PHONE:
return this.template.p2PPayToPhoneNumber;
}
}
getDefaultAccount(): Observable<BankAccount> {
return this.state$.pipe(
first((state) => !!state && !!state.accounts),
map((state) => {
if (
state.template &&
state.template.payFromBankAccount &&
(!state.template.customerMessages || state.template.customerMessages.length === 0)
) {
return state.template.payFromBankAccount;
}
if (!state.accounts) {
return null;
}
return state.accounts.reverse().reduce((p, c) => c, null);
})
);
}
}