Skip to content

fix(issuer): refresh badge count after award/revoke#2018

Merged
fatimakay merged 2 commits intodevelopfrom
fix/issuer-badge-count-stale
Apr 28, 2026
Merged

fix(issuer): refresh badge count after award/revoke#2018
fatimakay merged 2 commits intodevelopfrom
fix/issuer-badge-count-stale

Conversation

@fatimakay
Copy link
Copy Markdown

See Issue #2017

@fatimakay fatimakay force-pushed the fix/issuer-badge-count-stale branch from 9f5e452 to fe7aa5d Compare April 26, 2026 16:29
@onemanwenttomow
Copy link
Copy Markdown

Hi @fatimakay, great fix! Two small suggestions:

  1. Flatten the promise chain so .catch() covers updateList() failures too (currently it only catches errors from firstValueFrom onwards):
this.badgesLoaded = this.badgeClassService.badgesList
    .updateList()
    .then(() => firstValueFrom(this.badgeClassService.badgesByIssuerUrl$))
    .then((badgesByIssuer) => {
        const cmp = (a, b) => (a === b ? 0 : a < b ? -1 : 1);
        this.badges = (badgesByIssuer[this.issuer.issuerUrl] || []).sort((a, b) =>
            cmp(b.createdAt, a.createdAt),
        );
    })
    .catch((error) => {
        this.messageService.reportAndThrowError(
            `Failed to load badges for ${this.issuer ? this.issuer.name : this.issuerSlug}`,
            error,
        );
    });
  1. Consider making BadgeResult.awardedCount a getter - this might be a better long-term approach as it reads the live value from the model rather than a snapshot, removing the
    staleness problem at the source. The ngOnChanges addition could then also be dropped:
export class BadgeResult {
	constructor(
		public badge: BadgeClass | PublicApiBadgeClass,
		public issuerName: string,
		public requestCount: number,
		private _awardedCount?: number,
	) {}

	get awardedCount(): number {
		if (this._awardedCount !== undefined) return this._awardedCount;
		return this.badge instanceof BadgeClass ? this.badge.recipientCount : 0;
	}
}

@fatimakay
Copy link
Copy Markdown
Author

Hi @onemanwenttomow, thank you for reviewing. just updated the PR with your suggested changes!

Copy link
Copy Markdown

@onemanwenttomow onemanwenttomow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉

@fatimakay fatimakay enabled auto-merge April 28, 2026 07:57
@fatimakay fatimakay force-pushed the fix/issuer-badge-count-stale branch from 454ddac to 8e293f9 Compare April 28, 2026 07:57
@fatimakay fatimakay merged commit 31f8f84 into develop Apr 28, 2026
3 checks passed
@fatimakay fatimakay deleted the fix/issuer-badge-count-stale branch April 28, 2026 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants