File

src/app/sending-money/sending-money.component.ts

Implements

OnInit OnDestroy

Metadata

selector app-sending-money
styleUrls sending-money.component.css
templateUrl ./sending-money.component.html

Index

Properties
Methods
Accessors

Constructor

constructor(app: AppState, sessionStore: SessionStore, materialService: MaterialService, router: Router, ref: ChangeDetectorRef, templateService: TemplateService)
Parameters :
Name Type Optional
app AppState no
sessionStore SessionStore no
materialService MaterialService no
router Router no
ref ChangeDetectorRef no
templateService TemplateService no

Methods

addingCents
addingCents()
Returns : void
decimalKeyDown
decimalKeyDown(event: KeyboardEvent)
Parameters :
Name Type Optional
event KeyboardEvent no
Returns : void
decreaseSize
decreaseSize()
Returns : void
deletedCents
deletedCents()
Returns : void
hideLookUp
hideLookUp()
Returns : void
increaseSize
increaseSize(event: KeyboardEvent)
Parameters :
Name Type Optional
event KeyboardEvent no
Returns : void
isAmountValid
isAmountValid()
Returns : any
isAuthCheck
isAuthCheck()
Returns : void
Private isAuthRequired
isAuthRequired(model: MultiFactorModel)
Parameters :
Name Type Optional
model MultiFactorModel no
Returns : boolean
isMissingPayFromAccount
isMissingPayFromAccount()
Returns : void
keyDown
keyDown(event: KeyboardEvent)
Parameters :
Name Type Optional
event KeyboardEvent no
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void
resetForm
resetForm()
Returns : void
setDefaultAccount
setDefaultAccount(account: BankAccount)
Parameters :
Name Type Optional
account BankAccount no
Returns : void
showAgainPayment
showAgainPayment(template: Template)
Parameters :
Name Type Optional
template Template no
Returns : void
showLookUp
showLookUp()
Returns : void
showNewPayment
showNewPayment()
Returns : void
submitPayment
submitPayment()
Returns : void
toggleAuthInput
toggleAuthInput()
Returns : void
toggleAuthMethod
toggleAuthMethod()
Returns : void
toggleAuthRepeat
toggleAuthRepeat()
Returns : void
toggleAuthRequest
toggleAuthRequest()
Returns : void
toggleChangeAccount
toggleChangeAccount()
Returns : void
updateAmount
updateAmount(event?: )
Parameters :
Name Optional
event yes
Returns : void
updateDecimal
updateDecimal(value: )
Parameters :
Name Optional
value no
Returns : void
updateIntegral
updateIntegral(value: )
Parameters :
Name Optional
value no
Returns : void

Properties

account
account: BankAccount
Type : BankAccount
amount
amount:
Decorators : ViewChild
Public app
app: AppState
Type : AppState
authRequired
authRequired:
Default value : true
Private autoCompleteComponent
autoCompleteComponent: AutoCompleteComponent
Type : AutoCompleteComponent
Decorators : ViewChild
decimalAmount
decimalAmount: null
Type : null
Default value : null
decimalinput
decimalinput: ElementRef
Type : ElementRef
Decorators : ViewChild
defaultAccountSubscription
defaultAccountSubscription: Subscription
Type : Subscription
form
form:
Decorators : ViewChild
hideMaskedAccount
hideMaskedAccount:
Default value : false
input
input: ElementRef
Type : ElementRef
Decorators : ViewChild
integralAmount
integralAmount: null
Type : null
Default value : null
isAgainPayment
isAgainPayment:
Default value : false
isCopied
isCopied:
Default value : false
isLoading
isLoading:
Default value : false
isLookUp
isLookUp:
Default value : false
isNewPayment
isNewPayment:
Default value : false
limitResult
limitResult: LimitsResult
Type : LimitsResult
limitSubscription
limitSubscription: Subscription
Type : Subscription
loaderHeader
loaderHeader: string
Type : string
Default value : ''
loadingLimits
loadingLimits:
Default value : false
message
message: string
Type : string
Default value : ''
missingPayFromAccount
missingPayFromAccount:
Default value : false
payment
payment:
Default value : new Payment()
Public sessionStore
sessionStore: SessionStore
Type : SessionStore
showAuthInput
showAuthInput:
Default value : false
showAuthMethod
showAuthMethod:
Default value : false
showAuthRepeat
showAuthRepeat:
Default value : false
showAuthRequest
showAuthRequest:
Default value : false
showChangeAccount
showChangeAccount:
Default value : false
stateSubscription
stateSubscription: Subscription
Type : Subscription
template
template: Template
Type : Template

Accessors

payFromAccount
getpayFromAccount()
import { TemplateService } from './../services/template.service';
import { ChangeDetectorRef, Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { Router } from '@angular/router';
import { filter, tap } from 'rxjs/operators';
import { Subscription } from 'rxjs/Subscription';
import { MultiFactorTypes } from '../enums/multi-factor-types';
import { BankAccount, MultiFactorModel, Payment, Template } from '../models';
import { LimitsResult } from '../models/limits-result.model';
import { MaskPipe } from '../pipes';
import { MaterialService } from '../services';
import { SessionStore } from '../stores';
import { AppState } from '../stores/app-state.store';
import { AutoCompleteComponent } from './auto-complete';
import { PayingAgainComponent } from './paying-again';

@Component({
  selector: 'app-sending-money',
  templateUrl: './sending-money.component.html',
  styleUrls: ['./sending-money.component.css'],
})
export class SendingMoneyComponent implements OnInit, OnDestroy {
  @ViewChild('integralInput') input: ElementRef;
  @ViewChild('decimalInput') decimalinput: ElementRef;
  @ViewChild('Amount') amount;
  @ViewChild('userForm') form;
  @ViewChild(AutoCompleteComponent)
  private autoCompleteComponent: AutoCompleteComponent;
  isCopied = false;
  isNewPayment = false;
  isAgainPayment = false;
  isLookUp = false;
  showChangeAccount = false;
  showAuthRequest = false;
  showAuthMethod = false;
  showAuthRepeat = false;
  showAuthInput = false;
  integralAmount = null;
  decimalAmount = null;
  payment = new Payment();
  account: BankAccount;
  template: Template;
  missingPayFromAccount = false;
  hideMaskedAccount = false;
  loaderHeader = '';
  message = '';
  isLoading = false;
  authRequired = true;
  limitResult: LimitsResult;
  limitSubscription: Subscription;
  defaultAccountSubscription: Subscription;
  stateSubscription: Subscription;
  loadingLimits = false;

  constructor(
    public app: AppState,
    public sessionStore: SessionStore,
    private materialService: MaterialService,
    private router: Router,
    private ref: ChangeDetectorRef,
    private templateService: TemplateService
  ) {}

  ngOnInit() {
    this.app.acknowledgeDuplicate = false;
    this.templateService.reloadCache();
    this.app.template = null;
    this.defaultAccountSubscription = this.app
      .getDefaultAccount()
      .filter((bankAccount) => !!bankAccount)
      .subscribe((bankAccount) => {
        this.setDefaultAccount(bankAccount);
      });

    this.app.state$
      .pipe(
        filter((state) => state !== null && state !== undefined),
        tap((state) => {
          this.authRequired = this.isAuthRequired(state.multiFactorModel);
        })
      )
      .subscribe((state) => {
        this.limitResult = state.limitsResult;
        this.loadingLimits = state.loadingIsLimits;
      });

    console.log('app-user-form component loaded');
    this.materialService.render();
    setTimeout(() => {
      this.input.nativeElement.focus();
    }, 0);
  }

  ngOnDestroy(): void {
    if (this.defaultAccountSubscription) {
      this.defaultAccountSubscription.unsubscribe();
    }
  }

  private isAuthRequired(model: MultiFactorModel): boolean {
    const type = model && model.mfaType ? model.mfaType : '';
    if (type === MultiFactorTypes.Never) {
      return false;
    }
    return true;
  }

  updateIntegral(value) {
    if (!value) {
      return;
    }
    const val = value.replace(/\D/g, '');
    this.integralAmount = val;
    this.input.nativeElement.value = val;
    this.updateAmount();
  }

  updateDecimal(value) {
    if (!value) {
      return;
    }
    const val = value.replace(/\D/g, '');
    this.decimalAmount = val;
    this.decimalinput.nativeElement.value = val;
    this.updateAmount();
  }

  updateAmount(event?) {
    const amt = parseFloat(`${this.integralAmount}.${this.decimalAmount}`);
    this.payment.amount = amt;
    this.app.payment = this.payment;
    this.ref.detectChanges();
  }

  showLookUp() {
    this.isLookUp = true;
  }

  hideLookUp() {
    this.isLookUp = false;
  }

  showNewPayment() {
    this.isNewPayment = true;
    this.isAgainPayment = false;
    this.isAmountValid();
    this.authRequired = this.isAuthRequired(this.app.multiFactorModel);
  }

  showAgainPayment(template: Template) {
    this.isNewPayment = false;
    this.isAgainPayment = true;
    this.template = template;
    this.isMissingPayFromAccount();
    this.authRequired = this.isAuthRequired(this.app.multiFactorModel);
    this.setDefaultAccount(this.app.template.payFromBankAccount);
  }

  isMissingPayFromAccount() {
    this.missingPayFromAccount = false;
    if (
      this.template.customerMessages.length > 0 ||
      (this.template.payFromBankAccount && this.template.payFromBankAccount.accountNumber.length < 2)
    ) {
      this.missingPayFromAccount = true;
    }
  }

  get payFromAccount() {
    if (this.hideMaskedAccount) {
      return this.account.name;
    } else {
      const maskPipe = new MaskPipe();
      const maskedAccountNumber = maskPipe.transform(this.account.accountNumber);
      return `${this.account.accountType} Account - ${maskedAccountNumber}`;
    }
  }

  toggleChangeAccount() {
    this.showChangeAccount = !this.showChangeAccount;
  }

  toggleAuthRequest() {
    this.showAuthRequest = !this.showAuthRequest;
  }

  toggleAuthMethod() {
    this.showAuthMethod = !this.showAuthMethod;
  }

  toggleAuthRepeat() {
    this.showAuthRepeat = !this.showAuthRepeat;
  }

  toggleAuthInput() {
    this.showAuthInput = !this.showAuthInput;
  }

  isAuthCheck() {
    if (!this.app.hasPassedMfa) {
      this.input.nativeElement.blur();
      event.preventDefault();
      this.app.useMfaModal = true;
      this.toggleAuthRequest();
    } else {
      return;
    }
  }

  setDefaultAccount(account: BankAccount) {
    console.log('setting default account', account);
    if (!account || !account.id) {
      return;
    }
    this.account = account;
    this.showChangeAccount = false;
    this.app.bankAccount = account;
    if (
      this.app.template &&
      this.app.template.payFromBankAccount &&
      !this.app.template.payFromBankAccount.id
    ) {
      this.app.template.payFromBankAccount = account;
    }
  }

  increaseSize(event: KeyboardEvent) {
    const length = this.input.nativeElement.value.length;
    if (length > 0 && length < 6) {
      this.input.nativeElement.style.width = (this.input.nativeElement.value.length + 1) * 47 + 'px';
    }
  }

  decreaseSize() {
    if (this.input.nativeElement.value.length > 0) {
      this.input.nativeElement.style.width = (this.input.nativeElement.value.length - 1) * 47 + 'px';
    }
  }

  addingCents() {
    this.decimalinput.nativeElement.focus();

    setTimeout(() => {
      this.decimalinput.nativeElement.value = '';
    }, 0);
  }

  deletedCents() {
    if (this.decimalAmount) {
      return;
    }
    this.input.nativeElement.focus();
    this.decimalAmount = null;
  }

  resetForm() {
    this.integralAmount = '';
    this.decimalAmount = '';
    this.updateAmount();
    this.input.nativeElement.style.width = '52px';
    this.isNewPayment = false;
    this.isAgainPayment = false;
    this.form.reset();
    this.autoCompleteComponent.resetAutoCompleteForm();
  }

  isAmountValid() {
    return this.amount.pristine || (this.amount.dirty && this.amount.valid && this.integralAmount > 0);
  }

  keyDown(event: KeyboardEvent) {
    switch (event.key) {
      case 'Backspace':
      case 'Delete':
        this.decreaseSize();
        break;
      case 'Dot':
      case 'Decimal':
      case '.':
        this.addingCents();
        break;
      case '0':
      case '1':
      case '2':
      case '3':
      case '4':
      case '5':
      case '6':
      case '7':
      case '8':
      case '9':
      case 'Unidentified':
        this.increaseSize(event);
        break;
    }
  }

  decimalKeyDown(event: KeyboardEvent) {
    switch (event.key) {
      case 'Backspace':
      case 'Delete':
        this.deletedCents();
        break;
    }
  }

  submitPayment() {
    this.router.navigate(['/payment/create']);
  }
}
<div [hidden]="isLoading">
  <div class="scroller" id="sendMoneyScroller">
    <form #userForm="ngForm">
      <div id="sendingMoneyFormCtn">
        <!-- Amount To Send -->
        <div class="amount-to-send-ctn">
          <div id="amountLabel"><p class="para-dark">Amount to Send:</p></div>

          <div id="settingUpAmount">
            <div id="dollarSymbol"><p>$</p></div>

            <div id="dollarAmount">
              <input
                #integralInput
                #Amount="ngModel"
                [ngModel]="integralAmount"
                (ngModelChange)="updateIntegral($event)"
                id="amountSend"
                type="tel"
                maxlength="6"
                name="integralAmount"
                tabindex="1"
                placeholder="0"
                autocomplete="off"
                pattern="[0-9]{1,}"
                (keydown)="keyDown($event)"
                required
              />
              <input
                #decimalInput
                [ngModel]="decimalAmount"
                (ngModelChange)="updateDecimal($event)"
                id="amountSendCent"
                type="tel"
                maxlength="2"
                name="decimalAmount"
                tabindex="2"
                autocomplete="off"
                placeholder="00"
                (keydown)="decimalKeyDown($event)"
              />
            </div>
          </div>

          <div *ngIf="!isAmountValid()" class="alert alert-danger alert-amount">
            Please provide amount above a dollar
          </div>

          <div class="limit-alert-ctn" [ngClass]="{ show: loadingLimits }">
            <div class="limit-alert-loader">
              <app-loading-linear
                [message]="'Checking your limits'"
                *ngIf="loadingLimits"
              ></app-loading-linear>
            </div>

            <div
              *ngIf="!loadingLimits && limitResult && !limitResult.isAllowed"
              class="alert alert-danger alert-amount limit-alert"
            >
              {{ limitResult.errors[0].message }}
            </div>
          </div>

          <div id="amountActionLabel">
            <p class="para-medium" id="tt4">Tap above to change amount</p>
            <div class="mdl-tooltip" for="tt4">
              You can change how much you want to send by clicking on the amount above
            </div>
          </div>
        </div>
        <!-- Form -->
        <div class="form-ctn" id="userForm">
          <!-- Look Up Recipient -->
          <app-auto-complete
            (pay)="showNewPayment()"
            (payAgain)="showAgainPayment($event)"
          ></app-auto-complete>

          <!-- Account Logic -->
          <div id="changeAccount" *ngIf="isNewPayment || (isAgainPayment && !missingPayFromAccount)">
            <p class="para-dark">
              <a class="action-link" (click)="toggleChangeAccount()">
                Take money from
                <app-account-label [account]="account"></app-account-label>
              </a>
            </p>
          </div>

          <!-- Pay From Bank Account Option (If Account is missing) -->
          <div *ngIf="isAgainPayment && missingPayFromAccount">
            <p class="from-account">From which account?</p>
            <div class="input-select" (click)="toggleChangeAccount()">
              <input
                type="text"
                class="cursor-pointer"
                [value]="payFromAccount"
                placeholder="Select Account"
                tabindex="3"
                required
                minlength="1"
                autocomplete="off"
                disabled
              />
              <span class="select cursor-pointer"> <i class="material-icons"> arrow_drop_down </i> </span>
            </div>
          </div>

          <app-new-payment style="display: inline" *ngIf="isNewPayment"></app-new-payment>
          <app-paying-again
            style="display: inline"
            *ngIf="isAgainPayment"
            (isSubmitPayment)="submitPayment()"
          ></app-paying-again>

          <div
            style="display: block"
            *ngIf="!isAmountValid()"
            class="alert alert-danger alert-missing-amount"
          >
            Don't forget to add an amount
          </div>
        </div>
        <div class="two-action-ctn">
          <p class="para-dark" *ngIf="!app.hasPassedMfa && authRequired">
            <a id="alreadyHaveAuth" (click)="isAuthCheck()">
              <i class="material-icons">lock_outline</i> I Already Have An Authentication Code</a
            >
          </p>
          <p class="para-dark status-positive" *ngIf="app.hasPassedMfa">
            <i class="material-icons">lock_open</i> This Payment Is Authenticated
          </p>
        </div>
        <div class="two-action-ctn">
          <p id="cancelPayment" class="para-dark"><a (click)="resetForm()">Cancel Current Payment</a></p>
        </div>
      </div>
    </form>
  </div>
</div>

<app-change-account
  style="display: inline"
  *ngIf="showChangeAccount"
  [template]="template"
  (closeChangeAccount)="toggleChangeAccount()"
  (setAndCloseAccount)="setDefaultAccount($event)"
></app-change-account>

<app-authenticate-request
  *ngIf="showAuthRequest"
  (closeAuthRequest)="toggleAuthRequest()"
  (openAuthMethod)="toggleAuthMethod()"
  (openAuthRepeat)="toggleAuthRepeat()"
></app-authenticate-request>
<app-authenticate-method
  *ngIf="showAuthMethod"
  (closeAuthMethod)="toggleAuthMethod()"
  (openAuthInput)="toggleAuthInput()"
></app-authenticate-method>
<app-authenticate-repeat
  *ngIf="showAuthRepeat"
  (closeAuthRepeat)="toggleAuthRepeat()"
  (openAuthInput)="toggleAuthInput()"
></app-authenticate-repeat>
<app-authenticate-input
  *ngIf="showAuthInput"
  (closeAuthInput)="toggleAuthInput()"
  (openAuthMethod)="toggleAuthMethod()"
></app-authenticate-input>

<div *ngIf="isLoading"><app-loader [header]="loaderHeader" [message]="message"></app-loader></div>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""