Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<v-dialog [progress]="progress()" title="Create wallet webhook">
<cc-fistful-thrift-form
[extensions]="extensions$ | async"
[formControl]="control"
namespace="webhooker"
type="WebhookParams"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
import { distinctUntilChanged, map, of } from 'rxjs';

import { CommonModule } from '@angular/common';
import { Component, inject, signal } from '@angular/core';
import { FormControl, ReactiveFormsModule } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button';

import { WebhookParams } from '@vality/fistful-proto/webhooker';
import { DialogModule, DialogSuperclass, NotifyLogService, progressTo } from '@vality/matez';
import {
DialogModule,
DialogSuperclass,
NotifyLogService,
getValueChanges,
progressTo,
} from '@vality/matez';
import { isTypeWithAliases } from '@vality/ng-thrift';

import { ThriftWalletWebhooksManagementService } from '~/api/services';
import { FistfulThriftFormComponent } from '~/components/fistful-thrift-form';
import { DomainMetadataFormExtensionsService } from '~/components/thrift-api-crud';

@Component({
selector: 'cc-create-wallet-webhook-dialog',
imports: [DialogModule, FistfulThriftFormComponent, ReactiveFormsModule, MatButtonModule],
imports: [
CommonModule,
DialogModule,
FistfulThriftFormComponent,
ReactiveFormsModule,
MatButtonModule,
],
templateUrl: './create-wallet-webhook-dialog.component.html',
})
export class CreateWalletWebhookDialogComponent extends DialogSuperclass<
Expand All @@ -19,12 +36,23 @@ export class CreateWalletWebhookDialogComponent extends DialogSuperclass<
> {
private walletWebhooksManagementService = inject(ThriftWalletWebhooksManagementService);
private log = inject(NotifyLogService);
private domainMetadataFormExtensionsService = inject(DomainMetadataFormExtensionsService);

control = new FormControl<Partial<WebhookParams>>(
{ party_id: this.dialogData.partyId },
{ nonNullable: true },
);
progress = signal(0);
extensions$ = this.domainMetadataFormExtensionsService.createFullDomainObjectsOptionsByType(
'WalletConfigObject',
'wallet_config',
getValueChanges(this.control).pipe(
map((value) => value?.party_id ?? this.dialogData.partyId),
distinctUntilChanged(),
map((partyId) => (obj) => obj.object.wallet_config.data.party_ref.id === partyId),
),
(data) => of(isTypeWithAliases(data, 'WalletID', 'webhooker')),
);

create() {
this.walletWebhooksManagementService
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<v-dialog [progress]="progress()" title="Create shop webhook">
<cc-domain-thrift-editor
[extensions]="extensions$ | async"
[formControl]="control"
namespace="webhooker"
type="WebhookParams"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
import { distinctUntilChanged, map } from 'rxjs';

import { CommonModule } from '@angular/common';
import { Component, inject, signal } from '@angular/core';
import { FormControl, ReactiveFormsModule } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button';

import { WebhookParams } from '@vality/domain-proto/webhooker';
import { DialogModule, DialogSuperclass, NotifyLogService, progressTo } from '@vality/matez';
import {
DialogModule,
DialogSuperclass,
NotifyLogService,
getValueChanges,
progressTo,
} from '@vality/matez';

import { ThriftShopWebhooksManagementService } from '~/api/services';
import { DomainThriftFormComponent } from '~/components/thrift-api-crud';
import {
DomainMetadataFormExtensionsService,
DomainThriftFormComponent,
} from '~/components/thrift-api-crud';

@Component({
selector: 'cc-create-webhook-dialog',
imports: [DialogModule, DomainThriftFormComponent, ReactiveFormsModule, MatButtonModule],
imports: [
CommonModule,
DialogModule,
DomainThriftFormComponent,
ReactiveFormsModule,
MatButtonModule,
],
templateUrl: './create-webhook-dialog.component.html',
})
export class CreateWebhookDialogComponent extends DialogSuperclass<
Expand All @@ -19,12 +37,22 @@ export class CreateWebhookDialogComponent extends DialogSuperclass<
> {
private webhooksManagementService = inject(ThriftShopWebhooksManagementService);
private log = inject(NotifyLogService);
private domainMetadataFormExtensionsService = inject(DomainMetadataFormExtensionsService);

control = new FormControl<Partial<WebhookParams>>(
{ party_ref: { id: this.dialogData.partyId } },
{ nonNullable: true },
);
progress = signal(0);
extensions$ = this.domainMetadataFormExtensionsService.createFullDomainObjectsOptionsByType(
'ShopConfigObject',
'shop_config',
getValueChanges(this.control).pipe(
map((value) => value?.party_ref?.id ?? this.dialogData.partyId),
distinctUntilChanged(),
map((partyId) => (obj) => obj.object.shop_config.data.party_ref.id === partyId),
),
);

create() {
this.webhooksManagementService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
</div>
} @else {
<cc-domain-thrift-editor
[extensions]="extensions$ | async"
[formControl]="control"
namespace="api_extensions"
noToolbar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
catchError,
combineLatest,
debounceTime,
distinctUntilChanged,
map,
of,
shareReplay,
Expand Down Expand Up @@ -31,10 +32,11 @@ import {
progressTo,
} from '@vality/matez';

import { DomainObjectsStoreService } from '~/api/domain-config';
import { ThriftInvoiceTemplatingService } from '~/api/services';
import { ConfigService } from '~/services';

import { DomainThriftFormComponent } from '../thrift-api-crud';
import { DomainMetadataFormExtensionsService, DomainThriftFormComponent } from '../thrift-api-crud';

@Component({
templateUrl: './create-invoice-template-dialog.component.html',
Expand All @@ -59,6 +61,8 @@ export class CreateInvoiceTemplateDialogComponent extends DialogSuperclass<Creat
private configService = inject(ConfigService);
private clipboard = inject(Clipboard);
private fb = inject(FormBuilder);
private domainMetadataFormExtensionsService = inject(DomainMetadataFormExtensionsService);
private domainStoreService = inject(DomainObjectsStoreService);

linkForm = this.fb.group({
name: null,
Expand Down Expand Up @@ -111,6 +115,46 @@ export class CreateInvoiceTemplateDialogComponent extends DialogSuperclass<Creat
}),
shareReplay({ refCount: true, bufferSize: 1 }),
);
extensions$ = combineLatest([
this.domainMetadataFormExtensionsService.createFullDomainObjectsOptionsByType(
'ShopConfigObject',
'shop_config',
getValueChanges(this.control).pipe(
map((value) => value?.party_id?.id),
distinctUntilChanged(),
map((partyId) =>
partyId
? (obj) => obj.object.shop_config.data.party_ref.id === partyId
: () => true,
),
),
),
this.domainMetadataFormExtensionsService.createFullDomainObjectsOptionsByType(
'CurrencyObject',
'currency',
getValueChanges(this.control).pipe(
map((value) => value?.shop_id?.id),
distinctUntilChanged(),
switchMap((shopId) =>
shopId
? this.domainStoreService.getObject({
shop_config: { id: shopId },
}).value$
: of(null),
),
map((shop) =>
shop
? (obj) =>
obj.object.currency.data.symbolic_code ===
shop.object.shop_config.data.account.currency.symbolic_code
: () => true,
),
),
),
]).pipe(
map((extensionGroups) => extensionGroups.flat()),
shareReplay({ refCount: true, bufferSize: 1 }),
);

create() {
this.createTemplate$.next(null);
Expand Down
45 changes: 39 additions & 6 deletions src/components/shops-table/shops-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export class ShopsTableComponent {
private partyManagementService = inject(ThriftPartyManagementService);

shops = input<ShopWithInfo[]>([]);
isHistoryView = input(false, { transform: booleanAttribute });
@Input() progress: number | boolean = false;
@Input() hasMore: boolean = false;
@Output() update = new EventEmitter<UpdateOptions>();
Expand Down Expand Up @@ -120,12 +121,24 @@ export class ShopsTableComponent {
)[getUnionKey(d.data.suspension)],
}),
},
{
field: 'Settlement/Guarantee Accounts',
header: { value: 'Accounts', description: 'Settlement/Guarantee' },
cell: (d) => ({
value: d.data.account.settlement,
description: d.data.account.guarantee,
}),
},
createCurrencyColumn(
(d) =>
this.getSettlementAccountState(d).pipe(
map((b) => ({ amount: b.own_amount, code: b.currency.symbolic_code })),
),
{ header: 'Own', isLazyCell: true },
{
header: 'Own',
isLazyCell: true,
hidden: toObservable(this.isHistoryView, { injector: this.injector }),
},
),
createCurrencyColumn(
(d) =>
Expand All @@ -135,21 +148,33 @@ export class ShopsTableComponent {
code: b.currency.symbolic_code,
})),
),
{ header: 'Hold', isLazyCell: true },
{
header: 'Hold',
isLazyCell: true,
hidden: toObservable(this.isHistoryView, { injector: this.injector }),
},
),
createCurrencyColumn(
(d) =>
this.getSettlementAccountState(d).pipe(
map((b) => ({ amount: b.available_amount, code: b.currency.symbolic_code })),
),
{ header: 'Available', isLazyCell: true },
{
header: 'Available',
isLazyCell: true,
hidden: toObservable(this.isHistoryView, { injector: this.injector }),
},
),
createCurrencyColumn(
(d) =>
this.getGuaranteeAccountState(d).pipe(
map((b) => ({ amount: b.own_amount, code: b.currency.symbolic_code })),
),
{ header: 'Guarantee Own', isLazyCell: true },
{
header: 'Guarantee Own',
isLazyCell: true,
hidden: toObservable(this.isHistoryView, { injector: this.injector }),
},
),
createCurrencyColumn(
(d) =>
Expand All @@ -159,14 +184,22 @@ export class ShopsTableComponent {
code: b.currency.symbolic_code,
})),
),
{ header: 'Guarantee Hold', isLazyCell: true },
{
header: 'Guarantee Hold',
isLazyCell: true,
hidden: toObservable(this.isHistoryView, { injector: this.injector }),
},
),
createCurrencyColumn(
(d) =>
this.getGuaranteeAccountState(d).pipe(
map((b) => ({ amount: b.available_amount, code: b.currency.symbolic_code })),
),
{ header: 'Guarantee Available', isLazyCell: true },
{
header: 'Guarantee Available',
isLazyCell: true,
hidden: toObservable(this.isHistoryView, { injector: this.injector }),
},
),
{ field: 'version', cell: (d) => ({ value: d.info.version }) },
{ field: 'changed_at', cell: (d) => ({ value: d.info.changed_at, type: 'datetime' }) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@
[extendMenu]="menuColumn"
[hasMore]="resource.hasMore()"
[shops]="shopsResource.value()"
isHistoryView
(more)="resource.more()"
(update)="resource.reload()"
/>
}
@case ('wallet_config') {
<cc-wallets-table [extendMenu]="menuColumn" [resource]="fullObjectsResource" />
<cc-wallets-table
[extendMenu]="menuColumn"
[resource]="fullObjectsResource"
isHistoryView
/>
}
@default {
<cc-domain-objects-table [menu]="menuColumn" [resource]="resource" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { Observable, of } from 'rxjs';
import { Observable, combineLatest, of } from 'rxjs';
import { map, shareReplay } from 'rxjs/operators';
import short from 'short-uuid';

import { Injectable, inject } from '@angular/core';

import { ThriftAstMetadata, metadata$ } from '@vality/domain-proto';
import { DomainObject } from '@vality/domain-proto/domain';
import { getNoTimeZoneIsoString } from '@vality/matez';
import { VersionedObject } from '@vality/domain-proto/domain_config_v2';
import { PossiblyAsync, getNoTimeZoneIsoString, getPossiblyAsyncObservable } from '@vality/matez';
import { ThriftData, ThriftFormExtension, isTypeWithAliases } from '@vality/ng-thrift';

import { DomainObjectsStoreService, DomainService } from '~/api/domain-config';
import { AuthorStoreService } from '~/api/domain-config/stores/author-store.service';

import { createDomainObjectExtensions } from './utils/create-domain-object-extension';
import { getDomainObjectOption } from './utils/get-domain-object-option';
import { getDomainObjectOption, getFullDomainObjectOption } from './utils/get-domain-object-option';

@Injectable({
providedIn: 'root',
Expand Down Expand Up @@ -101,6 +102,39 @@ export class DomainMetadataFormExtensionsService {
shareReplay({ refCount: true, bufferSize: 1 }),
);

createFullDomainObjectsOptionsByType(
objectType: string,
objectKey: keyof DomainObject,
filterFn$: PossiblyAsync<Parameters<VersionedObject[]['filter']>[0]>,
determinant?: ThriftFormExtension['determinant'],
): Observable<ThriftFormExtension[]> {
return metadata$.pipe(
map((metadata) => {
const objectFields = new ThriftData<string, 'struct'>(
metadata,
'domain',
objectType,
).ast;
const refType = objectFields.find((n) => n.name === 'ref').type as string;
return createDomainObjectExtensions(
refType,
() =>
combineLatest([
this.domainStoreService.getObjects(objectKey).value$,
getPossiblyAsyncObservable(filterFn$),
]).pipe(
map(([objects, filterFn]) =>
objects
.filter(filterFn)
.map((obj) => getFullDomainObjectOption(obj)),
),
),
determinant,
);
}),
);
}

private createDomainObjectsOptions(metadata: ThriftAstMetadata[]): ThriftFormExtension[] {
const domainFields = new ThriftData<string, 'struct'>(metadata, 'domain', 'DomainObject')
.ast;
Expand Down
Loading
Loading