diff --git a/src/app/components/member/components/member-about/member-about.component.ts b/src/app/components/member/components/member-about/member-about.component.ts index 15f2db9..6791b3c 100644 --- a/src/app/components/member/components/member-about/member-about.component.ts +++ b/src/app/components/member/components/member-about/member-about.component.ts @@ -63,7 +63,7 @@ export class MemberAboutComponent implements OnInit { this.drawerVisible$.next(false); } - public trackByUid(index: number, item: any): number { - return item.uid; + public trackByUid(index: number, item: any): any { + return item ? item.uid : index; } } diff --git a/src/app/pages/member/pages/activity/activity.page.ts b/src/app/pages/member/pages/activity/activity.page.ts index 2df3e41..11f97b2 100644 --- a/src/app/pages/member/pages/activity/activity.page.ts +++ b/src/app/pages/member/pages/activity/activity.page.ts @@ -184,7 +184,7 @@ export class ActivityPage implements OnInit { return ['/', ROUTER_UTILS.config.space.root, spaceId]; } - public trackByUid(index: number, item: any): number { - return item.uid; + public trackByUid(index: number, item: any): any { + return item ? item.uid : index; } } diff --git a/src/app/pages/member/pages/awards/awards.page.ts b/src/app/pages/member/pages/awards/awards.page.ts index a4c0e1d..3cb6b2a 100644 --- a/src/app/pages/member/pages/awards/awards.page.ts +++ b/src/app/pages/member/pages/awards/awards.page.ts @@ -50,7 +50,7 @@ export class AwardsPage { return this.auth.isLoggedIn$; } - public trackByUid(index: number, item: any): number { - return item.uid; + public trackByUid(index: number, item: any): any { + return item ? item.uid : index; } } diff --git a/src/app/pages/member/pages/badges/badges.page.ts b/src/app/pages/member/pages/badges/badges.page.ts index 73b7372..c10c07c 100644 --- a/src/app/pages/member/pages/badges/badges.page.ts +++ b/src/app/pages/member/pages/badges/badges.page.ts @@ -124,7 +124,7 @@ export class BadgesPage implements OnInit { return this.auth.isLoggedIn$; } - public trackByUid(index: number, item: Transaction) { - return item.uid; + public trackByUid(index: number, item: any): any { + return item ? item.uid : index; } } diff --git a/src/app/pages/member/pages/member/member.page.ts b/src/app/pages/member/pages/member/member.page.ts index 6043451..3a5994f 100644 --- a/src/app/pages/member/pages/member/member.page.ts +++ b/src/app/pages/member/pages/member/member.page.ts @@ -16,7 +16,7 @@ import { SeoService } from '@core/services/seo'; import { ROUTER_UTILS } from '@core/utils/router.utils'; import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; import { FILE_SIZES, Member } from '@build-5/interfaces'; -import { BehaviorSubject, Subscription, skip } from 'rxjs'; +import { BehaviorSubject, Subscription, filter, map, skip } from 'rxjs'; import { MemberApi } from './../../../../@api/member.api'; import { NavigationService } from './../../../../@core/services/navigation/navigation.service'; import { DataService } from './../../services/data.service'; @@ -104,6 +104,16 @@ export class MemberPage implements OnInit, OnDestroy { } public listenMember(memberId: string): void { + const isValidMemberId = typeof memberId === 'string' && /[a-zA-Z0-9]/.test(memberId); + + if (!isValidMemberId) { + this.data.awardsCompleted$.next([]); + this.data.awardsPending$.next([]); + this.data.space$.next([]); + this.data.member$.next(undefined); + return; + } + this.subscriptions$.push( this.memberApi .topAwardsCompleted(memberId) @@ -118,19 +128,34 @@ export class MemberPage implements OnInit, OnDestroy { ); // TODO Implement search. This is parked since we will be implementing new search here. this.subscriptions$.push( - this.memberApi.topSpaces(memberId).pipe(untilDestroyed(this)).subscribe(this.data.space$), + this.memberApi + .topSpaces(memberId) + .pipe( + untilDestroyed(this), + map((spaces) => + spaces.filter( + (space) => space && typeof space.uid === 'string' && space.uid.trim() !== '', + ), + ), + ) + .subscribe((filteredSpaces) => { + this.data.space$.next(filteredSpaces); + }), ); this.subscriptions$.push( this.memberApi .listen(memberId) - .pipe(untilDestroyed(this)) - .subscribe((v) => { - // Only pass next stage. - this.data.member$.next(v); + .pipe( + untilDestroyed(this), + filter((v) => v && typeof v.uid === 'string' && v.uid.trim() !== ''), + ) + .subscribe((validMember) => { + // Only pass next stage if valid. + this.data.member$.next(validMember); }), ); - // Badges. + // Continue with other actions if memberId is valid. this.data.refreshBadges(); } diff --git a/src/app/pages/member/pages/nfts/nfts.page.ts b/src/app/pages/member/pages/nfts/nfts.page.ts index 3d76ac3..9f07f2d 100644 --- a/src/app/pages/member/pages/nfts/nfts.page.ts +++ b/src/app/pages/member/pages/nfts/nfts.page.ts @@ -75,8 +75,8 @@ export class NFTsPage implements OnInit { return this.auth.member$; } - public trackByUid(_index: number, item: any): number { - return item.uid; + public trackByUid(index: number, item: any): any { + return item ? item.uid : index; } public convertAllToSoonaverseModel(algoliaItems: any[]) { diff --git a/src/app/pages/member/pages/spaces/member-spaces.component.ts b/src/app/pages/member/pages/spaces/member-spaces.component.ts index af34481..f383c53 100644 --- a/src/app/pages/member/pages/spaces/member-spaces.component.ts +++ b/src/app/pages/member/pages/spaces/member-spaces.component.ts @@ -49,7 +49,7 @@ export class MemberSpacesComponent implements OnInit { ); } - public trackByUid(index: number, item: any): number { - return item.uid; + public trackByUid(index: number, item: any): any { + return item ? item.uid : index; } } diff --git a/src/app/pages/member/pages/tokens/tokens.page.ts b/src/app/pages/member/pages/tokens/tokens.page.ts index 6a13fe8..98e1d25 100644 --- a/src/app/pages/member/pages/tokens/tokens.page.ts +++ b/src/app/pages/member/pages/tokens/tokens.page.ts @@ -289,8 +289,8 @@ export class TokensPage implements OnInit, OnDestroy { ); } - public trackByUid(index: number, item: any): number { - return item.uid; + public trackByUid(index: number, item: any): any { + return item ? item.uid : index; } public understandNotMintedWarning(): void { diff --git a/src/app/pages/member/pages/transactions/transactions.page.ts b/src/app/pages/member/pages/transactions/transactions.page.ts index dd547e2..9107dd6 100644 --- a/src/app/pages/member/pages/transactions/transactions.page.ts +++ b/src/app/pages/member/pages/transactions/transactions.page.ts @@ -201,8 +201,8 @@ export class TransactionsPage implements OnInit, OnDestroy { }); } - public trackByUid(index: number, item: any): number { - return item.uid; + public trackByUid(index: number, item: any): any { + return item ? item.uid : index; } private cancelSubscriptions(): void {