From a97bfd08f184fdcfa76d8b4ccd7a2b7f502bbe97 Mon Sep 17 00:00:00 2001 From: Rinat Arsaev <11846445+A77AY@users.noreply.github.com> Date: Wed, 26 Apr 2023 12:57:03 +0400 Subject: [PATCH] Add payements table terminal ID (#217) --- package.json | 2 +- src/app/api/wallet/management.service.ts | 7 ++++++- .../sections/wallets/wallets.component.html | 2 +- src/app/sections/wallets/wallets.component.ts | 7 ++----- .../payments-table.component.html | 7 +++++++ .../payments-table.component.ts | 1 + src/app/shared/pipes/amount-currency.pipe.ts | 19 +++++++++++++++---- 7 files changed, 33 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 77537ded..f32758ef 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "prettier-preset": "prettier \"**/*.{html,js,ts,css,scss,md,json,prettierrc,svg,huskyrc,yml,yaml}\"", "prettier": "npm run prettier-preset -- --list-different", "prettier-fix": "npm run prettier-preset -- --write", - "fix": "npm:lint-fix && npm run prettier-fix" + "fix": "npm run lint-fix && npm run prettier-fix" }, "dependencies": { "@angular/animations": "15.0.3", diff --git a/src/app/api/wallet/management.service.ts b/src/app/api/wallet/management.service.ts index 628fe076..604599f3 100644 --- a/src/app/api/wallet/management.service.ts +++ b/src/app/api/wallet/management.service.ts @@ -5,7 +5,7 @@ import { wallet_Management, } from '@vality/fistful-proto'; import { ContextSet } from '@vality/fistful-proto/internal/context'; -import { WalletParams } from '@vality/fistful-proto/internal/wallet'; +import { AccountBalance, WalletParams } from '@vality/fistful-proto/internal/wallet'; import { WalletID, EventRange, WalletState } from '@vality/fistful-proto/wallet'; import { combineLatest, from, map, Observable, switchMap } from 'rxjs'; @@ -46,4 +46,9 @@ export class ManagementService { Create(params: WalletParams, context: ContextSet): Observable { return this.client$.pipe(switchMap((c) => c.Create(params, context))); } + + // eslint-disable-next-line @typescript-eslint/naming-convention + GetAccountBalance(id: WalletID): Observable { + return this.client$.pipe(switchMap((c) => c.GetAccountBalance(id))); + } } diff --git a/src/app/sections/wallets/wallets.component.html b/src/app/sections/wallets/wallets.component.html index acea21fa..00a96df5 100644 --- a/src/app/sections/wallets/wallets.component.html +++ b/src/app/sections/wallets/wallets.component.html @@ -42,7 +42,7 @@ - {{ account.own_amount | amountCurrency : account.currency_sym_code }} + {{ account.current | amountCurrency : account.currency.symbolic_code }} diff --git a/src/app/sections/wallets/wallets.component.ts b/src/app/sections/wallets/wallets.component.ts index 1fb38a8f..2ebcd332 100644 --- a/src/app/sections/wallets/wallets.component.ts +++ b/src/app/sections/wallets/wallets.component.ts @@ -4,7 +4,7 @@ import { untilDestroyed, UntilDestroy } from '@ngneat/until-destroy'; import { StatWallet } from '@vality/fistful-proto/internal/fistful_stat'; import { clean, splitIds } from '@vality/ng-core'; import { of } from 'rxjs'; -import { startWith, map, shareReplay, switchMap, catchError } from 'rxjs/operators'; +import { startWith, map, shareReplay, catchError } from 'rxjs/operators'; import { Memoize } from 'typescript-memoize'; import { AccounterService } from '@cc/app/api/accounter'; @@ -82,10 +82,7 @@ export class WalletsComponent implements OnInit { @Memoize() getBalance(walletId: string) { - return this.walletManagementService.Get(walletId, {}).pipe( - switchMap((wallet) => - this.accounterService.GetAccountByID(Number(wallet.account.accounter_account_id)) - ), + return this.walletManagementService.GetAccountBalance(walletId).pipe( catchError((err) => { this.errorService.error(err); return of({}); diff --git a/src/app/shared/components/payments-table/payments-table.component.html b/src/app/shared/components/payments-table/payments-table.component.html index 3760c6dc..10e2456f 100644 --- a/src/app/shared/components/payments-table/payments-table.component.html +++ b/src/app/shared/components/payments-table/payments-table.component.html @@ -58,6 +58,13 @@ + + Terminal + + {{ payment.terminal_id.id }} + + + diff --git a/src/app/shared/components/payments-table/payments-table.component.ts b/src/app/shared/components/payments-table/payments-table.component.ts index 6beb83b7..1b99c42d 100644 --- a/src/app/shared/components/payments-table/payments-table.component.ts +++ b/src/app/shared/components/payments-table/payments-table.component.ts @@ -32,6 +32,7 @@ export class PaymentsTableComponent { 'revision', 'invoice', 'party', + 'terminal_id', 'actions' ); selection = new SelectionModel(); diff --git a/src/app/shared/pipes/amount-currency.pipe.ts b/src/app/shared/pipes/amount-currency.pipe.ts index ba28df0f..c8e4783f 100644 --- a/src/app/shared/pipes/amount-currency.pipe.ts +++ b/src/app/shared/pipes/amount-currency.pipe.ts @@ -1,9 +1,10 @@ import { formatCurrency, getCurrencySymbol } from '@angular/common'; import { Pipe, Inject, LOCALE_ID, DEFAULT_CURRENCY_CODE, PipeTransform } from '@angular/core'; import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; +import { CurrencyObject } from '@vality/domain-proto/domain'; import isNil from 'lodash-es/isNil'; import { ReplaySubject, combineLatest } from 'rxjs'; -import { map } from 'rxjs/operators'; +import { map, startWith } from 'rxjs/operators'; import { DomainStoreService } from '@cc/app/api/deprecated-damsel'; @@ -32,13 +33,23 @@ export class AmountCurrencyPipe implements PipeTransform { init() { this.isInit = true; - combineLatest([this.domainStoreService.getObjects('currency'), this.params$]) + combineLatest([ + this.domainStoreService.getObjects('currency').pipe(startWith([] as CurrencyObject[])), + this.params$, + ]) .pipe( map(([currencies, { amount, currencyCode, format }]) => { if (isNil(amount)) return '?'; - if (!currencyCode) return String(amount); const exponent = currencies.find((c) => c.data.symbolic_code === currencyCode) - .data.exponent; + ?.data?.exponent; + if (!currencyCode || !exponent) + return formatCurrency( + toMajor(amount, exponent), + this._locale, + '', + '', + format === 'short' ? '0.0-2' : undefined + ); return formatCurrency( toMajor(amount, exponent), this._locale,