Skip to content

Commit

Permalink
fix: add mfa flow to sync/fetch txns personal card
Browse files Browse the repository at this point in the history
  • Loading branch information
sumrender committed Dec 10, 2024
1 parent 1996d94 commit d8c4504
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 20 deletions.
24 changes: 21 additions & 3 deletions src/app/core/services/personal-cards.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { Observable, of } from 'rxjs';
import { map } from 'rxjs/operators';
import { PersonalCard } from '../models/personal_card.model';
import { YodleeAccessToken } from '../models/yoodle-token.model';
Expand Down Expand Up @@ -190,10 +190,28 @@ export class PersonalCardsService {
return this.expenseAggregationService.get('/yodlee/personal/access_token') as Observable<YodleeAccessToken>;
}

htmlFormUrl(url: string, accessToken: string): string {
isMfaEnabled(personalCardId: string, usePlatformApi): Observable<boolean> {
if (!usePlatformApi) {
return of(false); // TODO sumrender: hack, this will be removed with old personalCards removal in next pr;
}
const payload = {
data: {
id: personalCardId,
},
};
return this.spenderPlatformV1ApiService
.post<PlatformApiResponse<{ is_mfa_enabled: boolean }>>('/personal_cards/mfa', payload)
.pipe(map((res) => res.data.is_mfa_enabled));
}

htmlFormUrl(url: string, accessToken: string, isMfaFlow: boolean): string {
let extraParams = 'configName=Aggregation&callback=https://www.fylehq.com';
if (isMfaFlow) {
extraParams = 'configName=Aggregation&flow=refresh&callback=https://www.fylehq.com';
}
const pageContent = `<form id="fastlink-form" name="fastlink-form" action="${url}" method="POST">
<input name="accessToken" value="Bearer ${accessToken}" hidden="true" />
<input name="extraParams" value="configName=Aggregation&callback=https://www.fylehq.com" hidden="true" />
<input name="extraParams" value="${extraParams}" hidden="true" />
</form>
<script type="text/javascript">
document.getElementById("fastlink-form").submit();
Expand Down
56 changes: 39 additions & 17 deletions src/app/fyle/personal-cards/personal-cards.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,12 @@ export class PersonalCardsPage implements OnInit, AfterViewInit {
})
)
.subscribe((yodleeConfig) => {
this.openYoodle(yodleeConfig.fast_link_url, yodleeConfig.access_token);
this.openYoodle(yodleeConfig.fast_link_url, yodleeConfig.access_token, false);
});
}

openYoodle(url: string, access_token: string): void {
const pageContentUrl = this.personalCardsService.htmlFormUrl(url, access_token);
openYoodle(url: string, access_token: string, isMfaFlow: boolean): void {
const pageContentUrl = this.personalCardsService.htmlFormUrl(url, access_token, isMfaFlow);
const browser = this.inAppBrowserService.create(pageContentUrl, '_blank', 'location=no');
this.spinnerDialog.show();
/* added this for failsafe */
Expand All @@ -374,7 +374,11 @@ export class PersonalCardsPage implements OnInit, AfterViewInit {
requestId: string;
}[];
if (decodedData && decodedData[0]) {
this.postAccounts([decodedData[0].requestId]);
if (isMfaFlow) {
this.syncTransactions();
} else {
this.postAccounts([decodedData[0].requestId]);
}
}
});
}
Expand Down Expand Up @@ -480,25 +484,43 @@ export class PersonalCardsPage implements OnInit, AfterViewInit {
});
}

fetchNewTransactionsWithMfa(): void {
from(this.loaderService.showLoader('Redirecting you to our banking partner...', 10000))
.pipe(
switchMap(() => this.personalCardsService.getToken(this.usePlatformApi)),
finalize(async () => {
await this.loaderService.hideLoader();
})
)
.subscribe((yodleeConfig) => {
this.openYoodle(yodleeConfig.fast_link_url, yodleeConfig.access_token, true);
});
}

fetchNewTransactions(): void {
this.isfetching = true;
this.isTransactionsLoading = true;
if (this.selectionMode) {
this.switchSelectionMode();
}
this.personalCardsService
.syncTransactions(this.selectedAccount, this.usePlatformApi)
.pipe(
finalize(() => {
this.acc = [];
this.isfetching = false;
const params = this.loadData$.getValue();
params.pageNumber = 1;
this.loadData$.next(params);
this.trackingService.transactionsFetchedOnPersonalCards();
})
)
.subscribe(noop);
this.personalCardsService.isMfaEnabled(this.selectedAccount, this.usePlatformApi).subscribe((isMfaEnabled) => {
if (isMfaEnabled) {
this.fetchNewTransactionsWithMfa();
} else {
this.syncTransactions();
}
});
}

syncTransactions(): void {
this.personalCardsService.syncTransactions(this.selectedAccount, this.usePlatformApi).subscribe(() => {
this.acc = [];
this.isfetching = false;
const params = this.loadData$.getValue();
params.pageNumber = 1;
this.loadData$.next(params);
this.trackingService.transactionsFetchedOnPersonalCards();
});
}

hideSelectedTransactions(): void {
Expand Down

0 comments on commit d8c4504

Please sign in to comment.