-
- 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 @@
-
+
0) {
@@ -338,10 +334,6 @@ export class NftCheckoutComponent implements OnInit, OnDestroy {
);
if (expiresOn.isBefore(dayjs())) {
this.expiryTicker$.next(null);
- console.log(
- 'nft-checkout ngOnInit - expiresOn.isBefore(dayjs()) passed, remove CheckoutTransaction, expiresOn: ',
- expiresOn,
- );
removeItem(StorageItem.CheckoutTransaction);
int.unsubscribe();
this.reset();
diff --git a/src/app/pages/collection/pages/collection/nfts/collectionNfts.service.ts b/src/app/pages/collection/pages/collection/nfts/collectionNfts.service.ts
index f118c77..06fcbb5 100644
--- a/src/app/pages/collection/pages/collection/nfts/collectionNfts.service.ts
+++ b/src/app/pages/collection/pages/collection/nfts/collectionNfts.service.ts
@@ -20,17 +20,15 @@ export class CollectionNftStateService {
switchMap((nfts) =>
combineLatest(
nfts.map((nft) =>
- this.cartService.isNftAvailableForSale(nft, collection, true).pipe(
- map(availability => ({ nft, isAvailable: availability.isAvailable }))
- )
- )
- )
+ this.cartService
+ .isNftAvailableForSale(nft, collection, true)
+ .pipe(map((availability) => ({ nft, isAvailable: availability.isAvailable }))),
+ ),
+ ),
+ ),
+ map((nftsWithAvailability) =>
+ nftsWithAvailability.filter(({ isAvailable }) => isAvailable).map(({ nft }) => nft),
),
- map(nftsWithAvailability =>
- nftsWithAvailability
- .filter(({ isAvailable }) => isAvailable)
- .map(({ nft }) => nft)
- )
);
}
@@ -40,9 +38,11 @@ export class CollectionNftStateService {
}
private updateAvailableNftsCount(nfts: Nft[], collection: Collection) {
- this.getListedNftsObservable(collection).pipe(
- map(nftsForSale => nftsForSale.length),
- take(1),
- ).subscribe(count => this.availableNftsCountSubject$.next(count));
+ this.getListedNftsObservable(collection)
+ .pipe(
+ map((nftsForSale) => nftsForSale.length),
+ take(1),
+ )
+ .subscribe((count) => this.availableNftsCountSubject$.next(count));
}
}
diff --git a/src/app/pages/collection/pages/collection/nfts/nfts.page.ts b/src/app/pages/collection/pages/collection/nfts/nfts.page.ts
index 6464042..bddc459 100644
--- a/src/app/pages/collection/pages/collection/nfts/nfts.page.ts
+++ b/src/app/pages/collection/pages/collection/nfts/nfts.page.ts
@@ -109,21 +109,22 @@ export class CollectionNFTsPage implements OnInit, OnChanges, OnDestroy {
}
private loadCollection(collectionId: string): void {
- this.collectionApi.getCollectionById(collectionId).pipe(
- take(1)
- ).subscribe({
+ this.collectionApi
+ .getCollectionById(collectionId)
+ .pipe(take(1))
+ .subscribe({
next: (collectionData) => {
- if (collectionData) {
- this.collection = collectionData;
- this.initializeAlgoliaFilters(collectionId);
- } else {
- this.notification.error($localize`Error occurred while fetching collection.`, '');
- }
+ if (collectionData) {
+ this.collection = collectionData;
+ this.initializeAlgoliaFilters(collectionId);
+ } else {
+ this.notification.error($localize`Error occurred while fetching collection.`, '');
+ }
},
error: (err) => {
- this.notification.error($localize`Error occurred while fetching collection.`, '');
+ this.notification.error($localize`Error occurred while fetching collection.`, '');
},
- });
+ });
}
private initializeAlgoliaFilters(collectionId: string): void {
@@ -182,35 +183,40 @@ export class CollectionNFTsPage implements OnInit, OnChanges, OnDestroy {
public sweepToCart(count: number) {
if (!this.collectionId) {
- this.notification.error($localize`Collection ID is not available.`, '');
- return;
+ this.notification.error($localize`Collection ID is not available.`, '');
+ return;
}
- this.collectionApi.getCollectionById(this.collectionId)
- .pipe(
- take(1),
- filter((collection): collection is Collection => Boolean(collection)),
- switchMap((collection) => {
- // Ensure we're working with a defined collection
- if (!collection) {
- throw new Error('Collection is undefined after filtering');
- }
- return this.collectionNftStateService.getListedNftsObservable(collection).pipe(
- map(nftsForSale => nftsForSale.slice(0, Math.min(count, nftsForSale.length))),
- map(nftsToAdd => ({ nftsToAdd, collection }))
- );
- }),
- takeUntil(this.destroy$),
- )
- .subscribe({
- next: ({ nftsToAdd, collection }) => {
- nftsToAdd.forEach((nft) => {
- this.cartService.addToCart(nft, collection);
- });
- this.notification.success($localize`NFTs swept into your cart, open cart to review added items.`, '');
- },
- error: (error) => this.notification.error($localize`Error occurred while adding NFTs to cart.`, '')
- });
+ this.collectionApi
+ .getCollectionById(this.collectionId)
+ .pipe(
+ take(1),
+ filter((collection): collection is Collection => Boolean(collection)),
+ switchMap((collection) => {
+ // Ensure we're working with a defined collection
+ if (!collection) {
+ throw new Error('Collection is undefined after filtering');
+ }
+ return this.collectionNftStateService.getListedNftsObservable(collection).pipe(
+ map((nftsForSale) => nftsForSale.slice(0, Math.min(count, nftsForSale.length))),
+ map((nftsToAdd) => ({ nftsToAdd, collection })),
+ );
+ }),
+ takeUntil(this.destroy$),
+ )
+ .subscribe({
+ next: ({ nftsToAdd, collection }) => {
+ nftsToAdd.forEach((nft) => {
+ this.cartService.addToCart(nft, collection);
+ });
+ this.notification.success(
+ $localize`NFTs swept into your cart, open cart to review added items.`,
+ '',
+ );
+ },
+ error: (error) =>
+ this.notification.error($localize`Error occurred while adding NFTs to cart.`, ''),
+ });
}
public ngOnDestroy(): void {
diff --git a/src/app/pages/nft/pages/nft/nft.page.html b/src/app/pages/nft/pages/nft/nft.page.html
index 518857b..d7d9e7c 100644
--- a/src/app/pages/nft/pages/nft/nft.page.html
+++ b/src/app/pages/nft/pages/nft/nft.page.html
@@ -276,7 +276,9 @@ {{ getTitle(data.nft$ | async) }}
-
+
{{ getTitle(data.nft$ | async) }}
-
+
{
- if (collection) { this.cartService.addToCart(nft, collection); }
+ if (collection) {
+ this.cartService.addToCart(nft, collection);
+ }
});
}
}