Skip to content

Commit

Permalink
IMP-180: Generate next wallet id based on latest id (#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
A77AY committed Mar 13, 2024
1 parent 5be03f4 commit 28bfdd3
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/app/sections/claim/claim.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ <h2 class="mat-headline-5">Changeset</h2>
>
Change status
</button>
<button mat-raised-button (click)="createWallet()">Add wallet modification</button>
<button mat-raised-button (click)="createShop()">Add shop modifications</button>
<button color="primary" mat-raised-button (click)="addModification()">
Add modification
Expand Down
43 changes: 38 additions & 5 deletions src/app/sections/claim/claim.component.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { Component, DestroyRef } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { ActivatedRoute } from '@angular/router';
import { DialogResponseStatus, DialogService } from '@vality/ng-core';
import { DialogResponseStatus, DialogService, NotifyLogService } from '@vality/ng-core';
import { BehaviorSubject, combineLatest, defer, merge, Observable, Subject, switchMap } from 'rxjs';
import { first, map, shareReplay } from 'rxjs/operators';

import { ClaimManagementService } from '@cc/app/api/claim-management';
import { PartyManagementService } from '@cc/app/api/payment-processing';
import { getUnionKey, inProgressFrom, progressTo } from '@cc/utils';

import { NotificationErrorService, handleError } from '../../shared/services/notification-error';
import { DomainMetadataFormExtensionsService } from '../../shared/services';
import { handleError } from '../../shared/services/notification-error';

import { AddModificationDialogComponent } from './components/add-modification-dialog/add-modification-dialog.component';
import { ChangeStatusDialogComponent } from './components/change-status-dialog/change-status-dialog.component';
Expand All @@ -27,7 +28,7 @@ export class ClaimComponent {
switchMap(({ partyID }) =>
this.partyManagementService
.Get(partyID)
.pipe(progressTo(this.progress$), handleError(this.notificationErrorService.error)),
.pipe(progressTo(this.progress$), handleError(this.log.error)),
),
shareReplay({ refCount: true, bufferSize: 1 }),
);
Expand All @@ -39,7 +40,7 @@ export class ClaimComponent {
switchMap(({ partyID, claimID }) =>
this.claimManagementService
.GetClaim(partyID, Number(claimID))
.pipe(progressTo(this.progress$), handleError(this.notificationErrorService.error)),
.pipe(progressTo(this.progress$), handleError(this.log.error)),
),
shareReplay({ refCount: true, bufferSize: 1 }),
);
Expand All @@ -63,8 +64,9 @@ export class ClaimComponent {
private partyManagementService: PartyManagementService,
private allowedClaimStatusesService: AllowedClaimStatusesService,
private dialogService: DialogService,
private notificationErrorService: NotificationErrorService,
private log: NotifyLogService,
private destroyRef: DestroyRef,
private domainMetadataFormExtensionsService: DomainMetadataFormExtensionsService,
) {}

reloadClaim() {
Expand Down Expand Up @@ -124,4 +126,35 @@ export class ClaimComponent {
}
});
}

createWallet() {
combineLatest([
this.party$,
this.claim$,
this.domainMetadataFormExtensionsService.generateNextWalletId(),
])
.pipe(
first(),
switchMap(([party, claim, nextWalledId]) =>
this.dialogService
.open(AddModificationDialogComponent, {
party,
claim,
createModification: {
wallet_modification: {
id: nextWalledId,
modification: { creation: {} },
},
},
})
.afterClosed(),
),
takeUntilDestroyed(this.destroyRef),
)
.subscribe((result) => {
if (result.status === DialogResponseStatus.Success) {
this.reloadClaim();
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Party } from '@vality/domain-proto/domain';
import { ModificationChange, Modification } from '@vality/domain-proto/internal/claim_management';
import { DialogSuperclass, DEFAULT_DIALOG_CONFIG, NotifyLogService } from '@vality/ng-core';
import { BehaviorSubject } from 'rxjs';
import { DeepPartial } from 'utility-types';

import { ClaimManagementService } from '@cc/app/api/claim-management';
import { inProgressFrom, progressTo } from '@cc/utils';
Expand All @@ -16,12 +17,19 @@ import { inProgressFrom, progressTo } from '@cc/utils';
})
export class AddModificationDialogComponent extends DialogSuperclass<
AddModificationDialogComponent,
{ party: Party; claim: Claim; modificationUnit?: ModificationUnit }
{
party: Party;
claim: Claim;
modificationUnit?: ModificationUnit;
createModification?: DeepPartial<Modification>;
}
> {
static defaultDialogConfig = DEFAULT_DIALOG_CONFIG.large;

control = this.fb.control<Modification | ModificationChange>(
this.dialogData.modificationUnit?.modification || null,
this.dialogData.modificationUnit?.modification ||
(this.dialogData.createModification as Modification) ||
null,
Validators.required,
);
isLoading$ = inProgressFrom(() => this.progress$);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as short from 'short-uuid';

import { DomainStoreService } from '@cc/app/api/domain-config';

import { FistfulStatisticsService, createDsl } from '../../../api/fistful-stat';
import {
MetadataFormData,
MetadataFormExtension,
Expand All @@ -32,6 +33,14 @@ export class DomainMetadataFormExtensionsService {
determinant: (data) => of(isTypeWithAliases(data, 'ID', 'base')),
extension: () => of({ generate: () => of(short().generate()), isIdentifier: true }),
},
{
determinant: (data) => of(isTypeWithAliases(data, 'WalletID', 'claim_management')),
extension: () =>
of({
generate: () => this.generateNextWalletId(),
isIdentifier: true,
}),
},
{
determinant: (data) => of(isTypeWithAliases(data, 'Timestamp', 'base')),
extension: () =>
Expand Down Expand Up @@ -74,12 +83,32 @@ export class DomainMetadataFormExtensionsService {
shareReplay({ refCount: true, bufferSize: 1 }),
);

constructor(private domainStoreService: DomainStoreService) {}
constructor(
private domainStoreService: DomainStoreService,
private fistfulStatisticsService: FistfulStatisticsService,
) {}

createPartyClaimExtensions(party: Party, claim: Claim) {
return createPartyClaimDomainMetadataFormExtensions(party, claim);
}

generateNextWalletId() {
return this.fistfulStatisticsService
.GetWallets({
dsl: createDsl({ wallets: {} }),
})
.pipe(
map((res) =>
String(
Math.max(
1,
...res.data.wallets.map((w) => Number(w.id)).filter((id) => !isNaN(id)),
) + 1,
),
),
);
}

private createDomainObjectsOptions(metadata: ThriftAstMetadata[]): MetadataFormExtension[] {
const domainFields = new MetadataFormData<string, 'struct'>(
metadata,
Expand Down

0 comments on commit 28bfdd3

Please sign in to comment.