diff --git a/src/app/@shell/ui/header/header.component.ts b/src/app/@shell/ui/header/header.component.ts index bb8da6e..34ae5eb 100644 --- a/src/app/@shell/ui/header/header.component.ts +++ b/src/app/@shell/ui/header/header.component.ts @@ -113,7 +113,7 @@ export class HeaderComponent implements OnInit, OnDestroy { ) {} public ngOnInit(): void { - this.member$.pipe(untilDestroyed(this)).subscribe((obj) => { + this.member$.pipe(untilDestroyed(this)).subscribe((obj) => { if (obj?.uid) { this.cancelAccessSubscriptions(); this.accessSubscriptions$.push( diff --git a/src/app/components/cart/components/cart-modal/cart-modal.component.html b/src/app/components/cart/components/cart-modal/cart-modal.component.html index e22c621..c7c5273 100644 --- a/src/app/components/cart/components/cart-modal/cart-modal.component.html +++ b/src/app/components/cart/components/cart-modal/cart-modal.component.html @@ -9,61 +9,82 @@
-
-
+
- {{ item.nft.name }} -
-
-
- NFT -
-
+
NFT
+
{{ item.nft.name }}
-
- Collection -
-
+
Collection
+
{{ item.collection.name }}
-
- Royalties -
-
- {{ (item.collection.royaltiesFee || 0) * 100 }}% -
+
Royalties
+
{{ (item.collection.royaltiesFee || 0) * 100 }}%
- -
- Status -
+ +
Status
{{ cartStatus.status }} @@ -77,11 +98,14 @@
-
- Qty Added / Available -
+
Qty Added / Available
- + Your Cart (change)="updateQuantity($event, item.nft.uid)" min="1" [max]="(cartService.getAvailableNftQuantity(item) | async) ?? 1" - [disabled]="((cartService.getAvailableNftQuantity(item) | async) ?? 1) <= 1"> + [disabled]=" + ((cartService.getAvailableNftQuantity(item) | async) ?? 1) <= 1 + " + /> - / {{ (cartService.getAvailableNftQuantity(item) | async) }} + / {{ cartService.getAvailableNftQuantity(item) | async }} @@ -104,9 +131,7 @@
-
- Price Each (USD Value) -
+
Price Each (USD Value)
Your Cart > {{ item.pricing.originalPrice - | formatToken - : item.pricing.tokenSymbol - : true - : true + | formatToken : item.pricing.tokenSymbol : true : true | async }}   ({{ unitsService.getUsd( - cartService.valueDivideExponent({ value: item.pricing.originalPrice || 0, exponents: cartService.getDefaultNetworkDecimals() }), + cartService.valueDivideExponent({ + value: item.pricing.originalPrice || 0, + exponents: cartService.getDefaultNetworkDecimals() + }), item.pricing.tokenSymbol ) | async @@ -134,15 +159,15 @@
{{ item.pricing.discountedPrice - | formatToken - : item.pricing.tokenSymbol - : true - : true + | formatToken : item.pricing.tokenSymbol : true : true | async }}   ({{ unitsService.getUsd( - cartService.valueDivideExponent({ value: item.pricing.discountedPrice || 0, exponents: cartService.getDefaultNetworkDecimals() }), + cartService.valueDivideExponent({ + value: item.pricing.discountedPrice || 0, + exponents: cartService.getDefaultNetworkDecimals() + }), item.pricing.tokenSymbol ) | async @@ -162,7 +187,9 @@ -
+
@@ -228,7 +255,7 @@
- + {{ cartStatus.status }} @@ -243,7 +270,12 @@
- + Your Cart (change)="updateQuantity($event, item.nft.uid)" min="1" [max]="(cartService.getAvailableNftQuantity(item) | async) ?? 1" - [disabled]="((cartService.getAvailableNftQuantity(item) | async) ?? 1) <= 1"> + [disabled]=" + ((cartService.getAvailableNftQuantity(item) | async) ?? 1) <= 1 + " + /> - / {{ (cartService.getAvailableNftQuantity(item) | async) }} + / {{ cartService.getAvailableNftQuantity(item) | async }} @@ -273,15 +308,15 @@ > {{ item.pricing.originalPrice - | formatToken - : item.pricing.tokenSymbol - : true - : true + | formatToken : item.pricing.tokenSymbol : true : true | async }}   ({{ unitsService.getUsd( - cartService.valueDivideExponent({ value: item.pricing.originalPrice || 0, exponents: cartService.getDefaultNetworkDecimals() }), + cartService.valueDivideExponent({ + value: item.pricing.originalPrice || 0, + exponents: cartService.getDefaultNetworkDecimals() + }), item.pricing.tokenSymbol ) | async @@ -293,15 +328,15 @@
{{ item.pricing.discountedPrice - | formatToken - : item.pricing.tokenSymbol - : true - : true + | formatToken : item.pricing.tokenSymbol : true : true | async }}   ({{ unitsService.getUsd( - cartService.valueDivideExponent({ value: item.pricing.discountedPrice || 0, exponents: cartService.getDefaultNetworkDecimals() }), + cartService.valueDivideExponent({ + value: item.pricing.discountedPrice || 0, + exponents: cartService.getDefaultNetworkDecimals() + }), item.pricing.tokenSymbol ) | async @@ -322,7 +357,7 @@ nzType="default" [disabled]=" (cartService.getCurrentStep() !== stepType.CONFIRM && - cartService.getSelectedNetwork() === item.pricing.tokenSymbol) || + cartService.getSelectedNetwork() === item.pricing.tokenSymbol) || (isLoading$ | async) " (click)="removeFromCart(item)" @@ -330,12 +365,10 @@ [nzTooltipTitle]=" cartService.getCurrentStep() !== stepType.CONFIRM && cartService.getSelectedNetwork() === item.pricing.tokenSymbol - ? 'Item is part of a pending transaction. Please wait for the transaction to expire or be completed before removing this item from the cart.' - : ( - (isLoading$ | async) + ? 'Item is part of a pending transaction. Please wait for the transaction to expire or be completed before removing this item from the cart.' + : (isLoading$ | async) ? 'Cart items are loading. Please wait.' : '' - ) " > Your Cart
-
Your cart is empty.
@@ -368,7 +400,7 @@ nz-button nzType="default" (click)="clearCart()" - [disabled]="(isLoading$ | async)" + [disabled]="isLoading$ | async" nz-tooltip [nzTooltipTitle]="(isLoading$ | async) ? 'Waiting for cart items to finish loading' : ''" class="text-red-600 hover:text-red-800" diff --git a/src/app/components/cart/components/cart-modal/cart-modal.component.ts b/src/app/components/cart/components/cart-modal/cart-modal.component.ts index f68a42d..3a74f6d 100644 --- a/src/app/components/cart/components/cart-modal/cart-modal.component.ts +++ b/src/app/components/cart/components/cart-modal/cart-modal.component.ts @@ -5,9 +5,7 @@ import { ChangeDetectorRef, ChangeDetectionStrategy, } from '@angular/core'; -import { - Network, -} from '@build-5/interfaces'; +import { Network } from '@build-5/interfaces'; import { Subscription, take, of, Observable } from 'rxjs'; import { CartService, CartItem } from '@components/cart/services/cart.service'; import { AuthService } from '@components/auth/services/auth.service'; @@ -30,7 +28,7 @@ export enum StepType { styleUrls: ['./cart-modal.component.less'], changeDetection: ChangeDetectionStrategy.OnPush, }) -export class CartModalComponent implements OnInit, OnDestroy { +export class CartModalComponent implements OnDestroy { private subscriptions$ = new Subscription(); public collectionPath: string = ROUTER_UTILS.config.collection.root; public nftPath: string = ROUTER_UTILS.config.nft.root; @@ -60,11 +58,7 @@ export class CartModalComponent implements OnInit, OnDestroy { private router: Router, public unitsService: UnitsService, public deviceService: DeviceService, - ) { - - } - - ngOnInit() {} + ) {} trackByItemId(index: number, item: CartItem): string { return item.nft.uid; @@ -78,26 +72,29 @@ export class CartModalComponent implements OnInit, OnDestroy { const inputElement = event.target as HTMLInputElement; let newQuantity = Number(inputElement.value); - this.cartService.getCartItems().pipe( - take(1), - switchMap(cartItems => { - const item = cartItems.find(item => item.nft.uid === itemId); - if (item) { - return this.cartService.getAvailableNftQuantity(item).pipe( - map(maxQuantity => ({ item, maxQuantity })), - ); - } else { - return of(null); + this.cartService + .getCartItems() + .pipe( + take(1), + switchMap((cartItems) => { + const item = cartItems.find((item) => item.nft.uid === itemId); + if (item) { + return this.cartService + .getAvailableNftQuantity(item) + .pipe(map((maxQuantity) => ({ item, maxQuantity }))); + } else { + return of(null); + } + }), + ) + .subscribe((result) => { + if (result) { + const { maxQuantity } = result; + newQuantity = Math.max(1, Math.min(newQuantity, maxQuantity)); + inputElement.value = String(newQuantity); + this.cartService.updateCartItemQuantity(itemId, newQuantity); } - }), - ).subscribe(result => { - if (result) { - const { maxQuantity } = result; - newQuantity = Math.max(1, Math.min(newQuantity, maxQuantity)); - inputElement.value = String(newQuantity); - this.cartService.updateCartItemQuantity(itemId, newQuantity); - } - }); + }); } public handleClose(): void { diff --git a/src/app/components/cart/components/checkout/checkout-overlay.component.html b/src/app/components/cart/components/checkout/checkout-overlay.component.html index 4046326..43d6045 100644 --- a/src/app/components/cart/components/checkout/checkout-overlay.component.html +++ b/src/app/components/cart/components/checkout/checkout-overlay.component.html @@ -33,8 +33,7 @@

- +

@@ -74,33 +73,33 @@

- - NFT: - - + NFT: + {{ item.nft.name }}
- - COL: - - + COL: + {{ item.collection.name }}
- - Royalties: - - - {{ (item.collection.royaltiesFee || 0) * 100 }}% - + Royalties: + {{ (item.collection.royaltiesFee || 0) * 100 }}%
+ + {{ item.quantity }} {{ @@ -116,7 +115,10 @@


({{ unitsService.getUsd( - cartService.valueDivideExponent({ value: item.salePrice || 0, exponents: cartService.getDefaultNetworkDecimals() }), + cartService.valueDivideExponent({ + value: item.salePrice || 0, + exponents: cartService.getDefaultNetworkDecimals() + }), group.network ) | async @@ -129,9 +131,7 @@

- - Total - + Total @@ -206,7 +206,10 @@

}}   ({{ unitsService.getUsd( - cartService.valueDivideExponent({ value: item.salePrice || 0, exponents: cartService.getDefaultNetworkDecimals() }), + cartService.valueDivideExponent({ + value: item.salePrice || 0, + exponents: cartService.getDefaultNetworkDecimals() + }), group.network ) | async @@ -228,7 +231,10 @@

}}   ({{ unitsService.getUsd( - cartService.valueDivideExponent({ value: (item.quantity * item.salePrice) || 0, exponents: cartService.getDefaultNetworkDecimals() }), + cartService.valueDivideExponent({ + value: item.quantity * item.salePrice || 0, + exponents: cartService.getDefaultNetworkDecimals() + }), group.network ) | async @@ -256,7 +262,6 @@

-

diff --git a/src/app/components/cart/components/checkout/checkout-overlay.component.ts b/src/app/components/cart/components/checkout/checkout-overlay.component.ts index 678663e..694c170 100644 --- a/src/app/components/cart/components/checkout/checkout-overlay.component.ts +++ b/src/app/components/cart/components/checkout/checkout-overlay.component.ts @@ -24,7 +24,15 @@ import { AuthService } from '@components/auth/services/auth.service'; import { NotificationService } from '@core/services/notification'; import { OrderApi } from '@api/order.api'; import { NftApi } from '@api/nft.api'; -import { BehaviorSubject, firstValueFrom, interval, Observable, Subscription, forkJoin, of } from 'rxjs'; +import { + BehaviorSubject, + firstValueFrom, + interval, + Observable, + Subscription, + forkJoin, + of, +} from 'rxjs'; import { map, switchMap } from 'rxjs/operators'; import { TransactionService } from '@core/services/transaction'; import { @@ -406,14 +414,14 @@ export class CheckoutOverlayComponent implements OnInit, OnDestroy { } public groupItems() { - const availabilityChecks$ = this.items.map(item => + const availabilityChecks$ = this.items.map((item) => this.cartService.isCartItemAvailableForSale(item).pipe( - map(result => ({ item, isAvailable: result.isAvailable })), - switchMap(result => result ? of(result) : of({ item, isAvailable: false })) - ) + map((result) => ({ item, isAvailable: result.isAvailable })), + switchMap((result) => (result ? of(result) : of({ item, isAvailable: false }))), + ), ); - forkJoin(availabilityChecks$).subscribe(results => { + forkJoin(availabilityChecks$).subscribe((results) => { const groups: { [tokenSymbol: string]: GroupedCartItem } = {}; this.unavailableItemCount = 0; @@ -424,7 +432,9 @@ export class CheckoutOverlayComponent implements OnInit, OnDestroy { } const tokenSymbol = - (item.nft?.placeholderNft ? item.collection?.mintingData?.network : item.nft?.mintingData?.network) || DEFAULT_NETWORK; + (item.nft?.placeholderNft + ? item.collection?.mintingData?.network + : item.nft?.mintingData?.network) || DEFAULT_NETWORK; const discount = this.discount(item); const originalPrice = this.calcPrice(item, 1); const discountedPrice = this.calcPrice(item, discount); @@ -432,10 +442,18 @@ export class CheckoutOverlayComponent implements OnInit, OnDestroy { item.salePrice = price; const network = - (item.nft?.placeholderNft ? item.collection?.mintingData?.network : item.nft?.mintingData?.network) || DEFAULT_NETWORK; + (item.nft?.placeholderNft + ? item.collection?.mintingData?.network + : item.nft?.mintingData?.network) || DEFAULT_NETWORK; if (!groups[tokenSymbol]) { - groups[tokenSymbol] = { tokenSymbol, items: [], totalQuantity: 0, totalPrice: 0, network }; + groups[tokenSymbol] = { + tokenSymbol, + items: [], + totalQuantity: 0, + totalPrice: 0, + network, + }; } groups[tokenSymbol].items.push(item); @@ -468,10 +486,11 @@ export class CheckoutOverlayComponent implements OnInit, OnDestroy { } public isCartItemAvailableForSale(item: CartItem): Observable { - return this.cartService.isCartItemAvailableForSale(item).pipe(map(result => result.isAvailable)); + return this.cartService + .isCartItemAvailableForSale(item) + .pipe(map((result) => result.isAvailable)); } - public reset(): void { this.receivedTransactions = false; this.currentStep = StepType.CONFIRM; @@ -506,10 +525,9 @@ export class CheckoutOverlayComponent implements OnInit, OnDestroy { } public goToMemberNfts(): void { - const memberId = this.auth.member$.value?.uid; - if(!memberId) { + if (!memberId) { return; } diff --git a/src/app/components/cart/services/cart.service.ts b/src/app/components/cart/services/cart.service.ts index 4e4cc7c..7266e31 100644 --- a/src/app/components/cart/services/cart.service.ts +++ b/src/app/components/cart/services/cart.service.ts @@ -1,5 +1,16 @@ import { Injectable, NgZone } from '@angular/core'; -import { BehaviorSubject, Observable, Subscription, map, of, take, tap, catchError, finalize, combineLatest } from 'rxjs'; +import { + BehaviorSubject, + Observable, + Subscription, + map, + of, + take, + tap, + catchError, + finalize, + combineLatest, +} from 'rxjs'; import { Nft, Collection, @@ -127,22 +138,28 @@ export class CartService { } private loadMemberSpaces(memberId: string): void { - this.memberApi.allSpacesAsMember(memberId).pipe( - untilDestroyed(this), - map(spaces => spaces.map(space => space.uid)), - ).subscribe(spaceIds => { - this.memberSpacesSubject$.next(spaceIds); - spaceIds.forEach(spaceId => this.updateMemberGuardianStatus(spaceId)); - }); + this.memberApi + .allSpacesAsMember(memberId) + .pipe( + untilDestroyed(this), + map((spaces) => spaces.map((space) => space.uid)), + ) + .subscribe((spaceIds) => { + this.memberSpacesSubject$.next(spaceIds); + spaceIds.forEach((spaceId) => this.updateMemberGuardianStatus(spaceId)); + }); } private loadMemberAwards(memberId: string): void { - this.memberApi.topAwardsCompleted(memberId).pipe( - untilDestroyed(this), - map(awards => awards.map(award => award.uid)), - ).subscribe(awardIds => { - this.memberAwardsSubject$.next(awardIds); - }); + this.memberApi + .topAwardsCompleted(memberId) + .pipe( + untilDestroyed(this), + map((awards) => awards.map((award) => award.uid)), + ) + .subscribe((awardIds) => { + this.memberAwardsSubject$.next(awardIds); + }); } private updateMemberGuardianStatus(spaceId: string) { @@ -227,21 +244,23 @@ export class CartService { return; } - const freshDataObservables = cartItems.map(item => + const freshDataObservables = cartItems.map((item) => this.nftApi.getNftById(item.nft.uid).pipe( take(1), - map(freshNft => freshNft ? { ...item, nft: freshNft } : item), - catchError(() => of(item)) - ) + map((freshNft) => (freshNft ? { ...item, nft: freshNft } : item)), + catchError(() => of(item)), + ), ); - combineLatest(freshDataObservables).pipe( - take(1), - finalize(() => this.isLoadingSubject$.next(false)) - ).subscribe(updatedCartItems => { - this.cartItemsSubject$.next(updatedCartItems); - this.cartModalOpenSubject$.next(true); - }); + combineLatest(freshDataObservables) + .pipe( + take(1), + finalize(() => this.isLoadingSubject$.next(false)), + ) + .subscribe((updatedCartItems) => { + this.cartItemsSubject$.next(updatedCartItems); + this.cartModalOpenSubject$.next(true); + }); } public hideCartModal(): void { @@ -253,37 +272,50 @@ export class CartService { } public openCheckoutOverlay(): void { - if (!this.checkoutOverlayOpenSubject$.getValue()) { - const checkoutTransaction = getCheckoutTransaction(); if (checkoutTransaction && checkoutTransaction.transactionId) { if (checkoutTransaction.source === 'nftCheckout') { - this.notification.error('You currently have an open order. Pay for it or let it expire.', ''); + this.notification.error( + 'You currently have an open order. Pay for it or let it expire.', + '', + ); return; } if (checkoutTransaction.source === 'cartCheckout') { this.setCurrentTransaction(checkoutTransaction.transactionId); - this.getCurrentTransaction().pipe(take(1)).subscribe(currentTransaction => { - if (currentTransaction && currentTransaction.uid) { - const expiresOn: dayjs.Dayjs = dayjs(currentTransaction.createdOn!.toDate()).add(TRANSACTION_AUTO_EXPIRY_MS, 'ms'); - - if (expiresOn.isBefore(dayjs()) || currentTransaction.payload?.void || currentTransaction.payload?.reconciled) { - removeItem(StorageItem.CheckoutTransaction); - this.pendingTransaction$.next(undefined); - this.setCurrentStep(StepType.CONFIRM); - this.openModal(); + this.getCurrentTransaction() + .pipe(take(1)) + .subscribe((currentTransaction) => { + if (currentTransaction && currentTransaction.uid) { + const expiresOn: dayjs.Dayjs = dayjs(currentTransaction.createdOn!.toDate()).add( + TRANSACTION_AUTO_EXPIRY_MS, + 'ms', + ); + + if ( + expiresOn.isBefore(dayjs()) || + currentTransaction.payload?.void || + currentTransaction.payload?.reconciled + ) { + removeItem(StorageItem.CheckoutTransaction); + this.pendingTransaction$.next(undefined); + this.setCurrentStep(StepType.CONFIRM); + this.openModal(); + } else { + this.openModal(); + } } else { this.openModal(); } - } else { - this.openModal(); - } - }); + }); } else { - this.notification.error('CheckoutTransaction exists and source is not nftCheckout, the checkout-overlay is not open and the pending transaction not expired or complete and the source is not cartCheckout, this should never happen.', ''); + this.notification.error( + 'CheckoutTransaction exists and source is not nftCheckout, the checkout-overlay is not open and the pending transaction not expired or complete and the source is not cartCheckout, this should never happen.', + '', + ); return; } } else { @@ -293,27 +325,27 @@ export class CartService { } private openModal(): void { - this.getCartItems().pipe(take(1)).subscribe(cartItems => { - if (cartItems.length > 0) { - this.checkoutOverlayModalRef = this.modalService.create({ - nzTitle: 'Checkout', - nzContent: CheckoutOverlayComponent, - nzComponentParams: { items: cartItems }, - nzFooter: null, - nzWidth: '80%', - }); + this.getCartItems() + .pipe(take(1)) + .subscribe((cartItems) => { + if (cartItems.length > 0) { + this.checkoutOverlayModalRef = this.modalService.create({ + nzTitle: 'Checkout', + nzContent: CheckoutOverlayComponent, + nzComponentParams: { items: cartItems }, + nzFooter: null, + nzWidth: '80%', + }); - this.checkoutOverlayModalRef.afterClose.subscribe(() => { - this.closeCheckoutOverlay(); - }); + this.checkoutOverlayModalRef.afterClose.subscribe(() => { + this.closeCheckoutOverlay(); + }); - this.checkoutOverlayOpenSubject$.next(true); - } - }); + this.checkoutOverlayOpenSubject$.next(true); + } + }); } - - public closeCheckoutOverlay(): void { const checkoutTransaction = getCheckoutTransaction(); if (checkoutTransaction && checkoutTransaction.transactionId) { @@ -403,18 +435,17 @@ export class CartService { } public cartItemStatus(item: CartItem): Observable<{ status: string; message: string }> { - return this.isCartItemAvailableForSale(item) - .pipe( - map(availabilityResult => ({ - status: availabilityResult.isAvailable ? 'Available' : 'Not Available', - message: availabilityResult.message - })) - ); + return this.isCartItemAvailableForSale(item).pipe( + map((availabilityResult) => ({ + status: availabilityResult.isAvailable ? 'Available' : 'Not Available', + message: availabilityResult.message, + })), + ); } - public addToCart(nft: Nft, collection: Collection, quantity: number = 1): void { + public addToCart(nft: Nft, collection: Collection, quantity = 1): void { const currentItems = this.cartItemsSubject$.getValue(); - const existingItemIndex = currentItems.findIndex(item => item.nft.uid === nft.uid); + const existingItemIndex = currentItems.findIndex((item) => item.nft.uid === nft.uid); if (existingItemIndex > -1) { this.notification.error('This NFT already exists in your cart.', ''); @@ -424,7 +455,9 @@ export class CartService { const discountRate = this.discount(collection, nft); const originalPrice = this.calcPrice(nft, 1); const discountedPrice = this.calcPrice(nft, discountRate); - const tokenSymbol = (nft.placeholderNft ? collection.mintingData?.network : nft.mintingData?.network) || DEFAULT_NETWORK; + const tokenSymbol = + (nft.placeholderNft ? collection.mintingData?.network : nft.mintingData?.network) || + DEFAULT_NETWORK; const cartItem: CartItem = { nft: nft, @@ -442,10 +475,12 @@ export class CartService { this.cartItemsSubject$.next(updatedCartItems); this.saveCartItems(); - this.notification.success(`NFT ${nft.name} from collection ${collection.name} has been added to your cart.`, ''); + this.notification.success( + `NFT ${nft.name} from collection ${collection.name} has been added to your cart.`, + '', + ); } - public discount(collection?: Collection | null, nft?: Nft | null): number { if (!collection?.space || !this.auth.member$.value || nft?.owner) { return 1; @@ -514,21 +549,23 @@ export class CartService { } public updateCartItemQuantity(itemId: string, newQuantity: number): void { - this.cartItemsSubject$.pipe( - take(1), - tap(cartItems => { - const updatedCartItems = cartItems.map(item => { - if (item.nft.uid === itemId) { - return { ...item, quantity: newQuantity }; - } - return item; - }); + this.cartItemsSubject$ + .pipe( + take(1), + tap((cartItems) => { + const updatedCartItems = cartItems.map((item) => { + if (item.nft.uid === itemId) { + return { ...item, quantity: newQuantity }; + } + return item; + }); - this.cartItemsSubject$.next(updatedCartItems); + this.cartItemsSubject$.next(updatedCartItems); - this.saveCartItems(); - }) - ).subscribe(); + this.saveCartItems(); + }), + ) + .subscribe(); } public getSelectedNetwork(): any { @@ -538,7 +575,7 @@ export class CartService { public isNftAvailableForSale( nft: Nft, collection: Collection, - checkCartPresence: boolean = false + checkCartPresence = false, ): Observable<{ isAvailable: boolean; message: string }> { let message = 'NFT is available for sale.'; const conditions: string[] = []; @@ -550,13 +587,15 @@ export class CartService { const memberAwards = this.memberAwardsSubject$.getValue(); if (checkCartPresence) { - const isNftInCart = this.cartItemsSubject$.getValue().some(cartItem => cartItem.nft.uid === nft.uid); + const isNftInCart = this.cartItemsSubject$ + .getValue() + .some((cartItem) => cartItem.nft.uid === nft.uid); if (isNftInCart) { - message = 'This NFT is already in your cart.'; - return of({ - isAvailable, - message - }); + message = 'This NFT is already in your cart.'; + return of({ + isAvailable, + message, + }); } } @@ -564,7 +603,7 @@ export class CartService { message = 'Internal Error: Collection data is null or undefined.'; return of({ isAvailable, - message + message, }); } @@ -572,7 +611,7 @@ export class CartService { message = 'Internal Error: Nft and/or NFT Available From date is null or undefined.'; return of({ isAvailable, - message + message, }); } @@ -607,7 +646,11 @@ export class CartService { if (isOwner) conditions.push('You are the owner of this NFT.'); const availableValue = +nft?.available; - const nftAvailable = availableValue === 1 || availableValue === 3 || nft?.available === null || nft?.available === undefined; + const nftAvailable = + availableValue === 1 || + availableValue === 3 || + nft?.available === null || + nft?.available === undefined; if (!nftAvailable) conditions.push('NFT is not marked as available.'); const spaceMemberAccess = @@ -645,20 +688,22 @@ export class CartService { return of({ isAvailable, - message + message, }); } - public isCartItemAvailableForSale(cartItem: CartItem, checkCartPresence: boolean = false): Observable<{ isAvailable: boolean; message: string }> { - return this.isNftAvailableForSale(cartItem.nft, cartItem.collection, checkCartPresence) - .pipe( - map(result => { - return { - isAvailable: result.isAvailable, - message: result.message - }; - }) - ); + public isCartItemAvailableForSale( + cartItem: CartItem, + checkCartPresence = false, + ): Observable<{ isAvailable: boolean; message: string }> { + return this.isNftAvailableForSale(cartItem.nft, cartItem.collection, checkCartPresence).pipe( + map((result) => { + return { + isAvailable: result.isAvailable, + message: result.message, + }; + }), + ); } public clearCart(): void { @@ -667,17 +712,16 @@ export class CartService { this.notification.success($localize`All items have been removed from your cart.`, ''); } - public getAvailableNftQuantity(cartItem: CartItem): Observable { return this.isCartItemAvailableForSale(cartItem).pipe( - map(result => { + map((result) => { if (result.isAvailable) { - return cartItem.nft.placeholderNft ? (cartItem.collection.availableNfts || 0) : 1; + return cartItem.nft.placeholderNft ? cartItem.collection.availableNfts || 0 : 1; } else { return 0; } }), - map(quantity => quantity === null ? 0 : quantity) + map((quantity) => (quantity === null ? 0 : quantity)), ); } @@ -701,5 +745,4 @@ export class CartService { public getDefaultNetworkDecimals(): number { return DEFAULT_NETWORK_DECIMALS; } - } diff --git a/src/app/components/nft/components/nft-card/nft-card.component.html b/src/app/components/nft/components/nft-card/nft-card.component.html index 7302f3b..a4665c1 100644 --- a/src/app/components/nft/components/nft-card/nft-card.component.html +++ b/src/app/components/nft/components/nft-card/nft-card.component.html @@ -240,7 +240,12 @@ - +