Skip to content

Commit

Permalink
Add retirement messages ordering in new trust chain.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dariy Miseldzhani committed Dec 20, 2024
1 parent e6712be commit 9232211
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -424,54 +424,47 @@ export class MessagesReportBlockComponent implements OnInit {
// return ret
// });

const allRetireMessages: any = [];
retires.forEach((retirements: IRetirementMessage[]) => {
retirements.forEach((item: IRetirementMessage) => {
// this.groupedByContractRetirements = Array.from(
// new Map(allRetireMessages
// .map((item: any) => [item.documents[0].credentialSubject[0].contractId, []])
// )).map(([contractId, documents]) => ({
// contractId,
// selectedItemIndex: 0,
// __ifRetireMessage: true,
// documents: allRetireMessages.filter((item: any) => item.documents[0].credentialSubject[0].contractId === contractId)
// }))

let allRetireMessages: any = [];
retires.forEach((retirements: any[]) => {
retirements.forEach((item: any) => {
if (item.documents[0].credentialSubject[0].tokens.some((token: any) => token.tokenId === this.mintTokenId)) {
item.id == item.consensusTimestamp;
item.id = item.consensusTimestamp;
item.__ifRetireMessage = true;
item.__timestamp = this.datePipe.transform(new Date(item.documents[0].issuanceDate), 'yyyy-MM-dd, hh:mm:ss');
allRetireMessages.push(item);
}
});
});

this.groupedByContractRetirements = Array.from(
new Map(allRetireMessages
.map((item: any) => [item.documents[0].credentialSubject[0].contractId, []])
)).map(([contractId, documents]) => ({
contractId,
selectedItemIndex: 0,
__ifRetireMessage: true,
documents: allRetireMessages.filter((item: any) => item.documents[0].credentialSubject[0].contractId === contractId)
}))


allRetireMessages.sort((a: any, b: any) => new Date(a.documents[0].issuanceDate).getTime() - new Date(b.documents[0].issuanceDate).getTime());

// For different topics different ordering
let lastOrderMessageTopic1 = this._topics1?.[this._topics1.length - 1]?.messages.reduce((acc: number, item: any) => item.__order > acc ? item.__order : acc, 0) + 1;
allRetireMessages.forEach((element: any) => {
var newElement = {...element, __order: lastOrderMessageTopic1}
newElement.__ifRetireMessage = true;
newElement.__timestamp = this.datePipe.transform(new Date(newElement.documents[0].issuanceDate), 'yyyy-MM-dd, mm:hh:ss');

this._messages1.push(newElement);
this._topics1[this._topics1.length - 1].messages.push(newElement);

lastOrderMessageTopic1++;
});


let lastOrderMessageTopic2 = this._topics2?.[0]?.messages.reduce((acc: number, item: any) => item.__order > acc ? item.__order : acc, 0) + 1;
allRetireMessages.forEach((element: any) => {
var newElement = {...element, __order: lastOrderMessageTopic2}
newElement.__ifRetireMessage = true;
newElement.__timestamp = this.datePipe.transform(new Date(newElement.documents[0].issuanceDate), 'yyyy-MM-dd, mm:hh:ss');

this._messages2.push(newElement);
this._topics2[0].messages.push(newElement);

lastOrderMessageTopic2++;
});

console.log(this._topics1);
console.log(this._topics2);

this.retirementMessages = [...allRetireMessages];

this._gridTemplateColumns1 = 'repeat(' + (this.gridSize + this.retirementMessages.length + 1) + ', 230px)';
Expand Down Expand Up @@ -508,8 +501,6 @@ export class MessagesReportBlockComponent implements OnInit {
this._messages2.forEach(message => {
if (message.__ifMintMessage) {
this.mintTokenId = message.__tokenId;

// this.mintTokenSerials = (report.vpDocument?.document as any).serials.map((serialItem: any) => serialItem.serial); // Fix
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,16 +296,10 @@ export class ReportBlockComponent implements OnInit {
this.policyCreatorDocument = report.policyCreatorDocument;
this.documents = report.documents || [];



// Testing
this.mintTokenId = report.mintDocument?.tokenId || '';
this.mintTokenSerials = (report.vpDocument?.document as any).serials.map((serialItem: any) => serialItem.serial); // Fix
this.mintTokenSerials = (report.vpDocument?.document as any).serials.map((serialItem: any) => serialItem.serial);
this.vpDocument = report.vpDocument;
this.loadRetireData();
// ...



const mainDocument = this.createAdditionalDocument(report);
if (mainDocument) {
Expand Down

0 comments on commit 9232211

Please sign in to comment.