MI-21: Fix withdrawal error message (#146)

This commit is contained in:
Rinat Arsaev 2023-08-28 18:08:17 +04:00 committed by GitHub
parent c152e05222
commit 757bc46e38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 13 deletions

8
package-lock.json generated
View File

@ -25,7 +25,7 @@
"@sentry/angular-ivy": "^7.63.0",
"@sentry/integrations": "^7.63.0",
"@sentry/tracing": "^7.63.0",
"@vality/ng-core": "^16.2.1-pr-33-c999544.0",
"@vality/ng-core": "^16.2.1-pr-33-89c646b.0",
"@vality/swag-anapi-v2": "2.0.0",
"@vality/swag-api-keys-v2": "^0.1.2-870c41d.0",
"@vality/swag-claim-management": "0.1.1-7a03f9b.0",
@ -6409,9 +6409,9 @@
}
},
"node_modules/@vality/ng-core": {
"version": "16.2.1-pr-33-c999544.0",
"resolved": "https://registry.npmjs.org/@vality/ng-core/-/ng-core-16.2.1-pr-33-c999544.0.tgz",
"integrity": "sha512-2CqoYXqFS5Dr0Dzl/+YU6z+bKI+yNJib5PfFO5OZeh4RnWd9Iktse4lSOCynbqFQ8qarWq/FkA2EYoluD4waFQ==",
"version": "16.2.1-pr-33-89c646b.0",
"resolved": "https://registry.npmjs.org/@vality/ng-core/-/ng-core-16.2.1-pr-33-89c646b.0.tgz",
"integrity": "sha512-8qDubL4XhAtP4GoPY/W5FSa6/4+rzqCCRq/91nWpYX3Vquta1SZi02bXv0S7oxJMNr+pNUUHw6qHkbDhFbKgBA==",
"dependencies": {
"@ng-matero/extensions": "^16.0.0",
"@s-libs/js-core": "^16.0.0",

View File

@ -42,7 +42,7 @@
"@sentry/angular-ivy": "^7.63.0",
"@sentry/integrations": "^7.63.0",
"@sentry/tracing": "^7.63.0",
"@vality/ng-core": "^16.2.1-pr-33-c999544.0",
"@vality/ng-core": "^16.2.1-pr-33-89c646b.0",
"@vality/swag-anapi-v2": "2.0.0",
"@vality/swag-api-keys-v2": "^0.1.2-870c41d.0",
"@vality/swag-claim-management": "0.1.1-7a03f9b.0",

View File

@ -1,8 +1,10 @@
import { Pipe, PipeTransform } from '@angular/core';
import { TranslocoService } from '@ngneat/transloco';
import { AsyncTransform } from '@vality/ng-core';
import { PaymentError } from '@vality/swag-payments';
import lowerCase from 'lodash-es/lowerCase';
import upperFirst from 'lodash-es/upperFirst';
import { isObservable, Observable, of } from 'rxjs';
function renderSubErrorMessage(error?: string, sub?: string) {
if (!error) return sub;
@ -17,15 +19,18 @@ function getErrorLabel(error: PaymentError) {
@Pipe({
name: 'withdrawalErrorMessage',
pure: false,
})
export class WithdrawalErrorMessagePipe implements PipeTransform {
constructor(private t: TranslocoService) {}
export class WithdrawalErrorMessagePipe extends AsyncTransform<string> implements PipeTransform {
constructor(private t: TranslocoService) {
super();
}
transform(error: PaymentError): string {
protected getValue(error: PaymentError) {
return this.formatErrors(error);
}
private formatErrors(error: PaymentError): string {
private formatErrors(error: PaymentError): Observable<string> {
let curError: PaymentError = error;
let translation = this.getErrorDict();
@ -34,15 +39,15 @@ export class WithdrawalErrorMessagePipe implements PipeTransform {
curError = curError.subError;
}
if (typeof translation === 'string') return translation;
return getErrorLabel(error);
if (isObservable(translation)) return translation as Observable<string>;
return of(getErrorLabel(error));
}
private getErrorDict() {
return {
failed: this.t.translate('withdrawalErrorMessage.failed', null, 'wallet-section'),
failed: this.t.selectTranslate('withdrawalErrorMessage.failed', null, 'wallet-section'),
authorization_failed: {
unknown: this.t.translate(
unknown: this.t.selectTranslate(
'withdrawalErrorMessage.authorization_failed.unknown',
null,
'wallet-section',