Skip to content

Commit

Permalink
prettier/lint commit
Browse files Browse the repository at this point in the history
  • Loading branch information
amenconi committed Feb 17, 2024
1 parent a4b79ab commit 6f1a25b
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 56 deletions.
4 changes: 2 additions & 2 deletions src/app/@shell/ui/header/header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class HeaderComponent implements OnInit, OnDestroy {
this.cartItemsSubscription$ = this.cartService.getCartItems().subscribe((items) => {
let count = 0;
items.forEach((nft) => {
count += nft.quantity
count += nft.quantity;
});
this.cartItemCount = count;
});
Expand Down Expand Up @@ -247,7 +247,7 @@ export class HeaderComponent implements OnInit, OnDestroy {
this.cartItemsSubscription$ = this.cartService.getCartItems().subscribe((items) => {
let count = 0;
items.forEach((nft) => {
count += nft.quantity
count += nft.quantity;
});
this.cartItemCount = count;
});
Expand Down
29 changes: 16 additions & 13 deletions src/app/components/algolia/services/algolia.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,22 @@ export class AlgoliaService {

return new Promise((resolve, reject) => {
const fetchPage = () => {
index.search('', {
filters: `owner:${memberId}`,
hitsPerPage,
page,
}).then(response => {
allHits.push(...response.hits);
if (page < response.nbPages - 1) {
page++;
fetchPage();
} else {
resolve(allHits);
}
}).catch(reject);
index
.search('', {
filters: `owner:${memberId}`,
hitsPerPage,
page,
})
.then((response) => {
allHits.push(...response.hits);
if (page < response.nbPages - 1) {
page++;
fetchPage();
} else {
resolve(allHits);
}
})
.catch(reject);
};

fetchPage();
Expand Down
8 changes: 4 additions & 4 deletions src/app/components/cart/cart.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import { NzRadioModule } from 'ng-zorro-antd/radio';
import { UsdBelowTwoDecimalsModule } from '@core/pipes/usd-below-two-decimals/usd-below-two-decimals.module';
import { NzToolTipModule } from 'ng-zorro-antd/tooltip';
import { ConnectWalletModule } from '@components/connect-wallet/connect-wallet.module';
//import { DataService } from '@pages/member/services/data.service';
//import { AlgoliaModule } from '@components/algolia/algolia.module';
// import { DataService } from '@pages/member/services/data.service';
// import { AlgoliaModule } from '@components/algolia/algolia.module';

@NgModule({
declarations: [CartModalComponent, CheckoutOverlayComponent],
Expand Down Expand Up @@ -58,8 +58,8 @@ import { ConnectWalletModule } from '@components/connect-wallet/connect-wallet.m
UsdBelowTwoDecimalsModule,
NzToolTipModule,
ConnectWalletModule,
//DataService,
//AlgoliaModule,
// DataService,
// AlgoliaModule,
],
exports: [CartModalComponent, CheckoutOverlayComponent],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,13 @@ export class CartModalComponent implements OnDestroy {
switchMap((cartItems) => {
const item = cartItems.find((item) => item.nft.uid === itemId);
if (item) {
return this.cartService
.getAvailableNftQuantity(item)
.pipe(
map((maxQuantity) => ({ item, maxQuantity })),
tap(({ maxQuantity }) => {
newQuantity = Math.min(newQuantity, maxQuantity);
inputElement.value = String(newQuantity);
})
);
return this.cartService.getAvailableNftQuantity(item).pipe(
map((maxQuantity) => ({ item, maxQuantity })),
tap(({ maxQuantity }) => {
newQuantity = Math.min(newQuantity, maxQuantity);
inputElement.value = String(newQuantity);
}),
);
} else {
return of(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,21 @@
<div nz-col nzSpan="20">
<h3 nz-typography nzTitle level="4" class="mb-2">
Network: <span class="uppercase">{{ group.tokenSymbol }}</span> -
<span class="font-bold">{{ group.items.length }}</span> unique NFTs in network group with total Price of {{ group.totalPrice | formatToken : group.network : true : true | async }} ({{ unitsService.getUsd(cartService.valueDivideExponent({ value: group.totalPrice || 0, exponents: cartService.getDefaultNetworkDecimals() }), group.network) | async | currency : 'USD' | UsdBelowTwoDecimals }} USD)
<span class="font-bold">{{ group.items.length }}</span> unique NFTs in network group
with total Price of
{{ group.totalPrice | formatToken : group.network : true : true | async }} ({{
unitsService.getUsd(
cartService.valueDivideExponent({
value: group.totalPrice || 0,
exponents: cartService.getDefaultNetworkDecimals()
}),
group.network
)
| async
| currency : 'USD'
| UsdBelowTwoDecimals
}}
USD)
</h3>
</div>
<div nz-col nzSpan="4" *ngIf="currentStep !== stepType.CONFIRM">
Expand Down Expand Up @@ -270,7 +284,19 @@ <h3 nz-typography nzTitle level="4" class="mb-2">
<td>
<strong>
{{ group.totalPrice | formatToken : group.network : true : true | async }}
&nbsp; ({{ unitsService.getUsd(cartService.valueDivideExponent({ value: group.totalPrice || 0, exponents: cartService.getDefaultNetworkDecimals() }), group.network) | async | currency : 'USD' | UsdBelowTwoDecimals }} USD)
&nbsp; ({{
unitsService.getUsd(
cartService.valueDivideExponent({
value: group.totalPrice || 0,
exponents: cartService.getDefaultNetworkDecimals()
}),
group.network
)
| async
| currency : 'USD'
| UsdBelowTwoDecimals
}}
USD)
</strong>
</td>
</tr>
Expand Down
59 changes: 36 additions & 23 deletions src/app/components/cart/services/cart.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ export class CartService {
private refreshMemberData() {
const memberId = this.auth.member$.value?.uid;
if (memberId) {
this.loadMemberSpaces(memberId);
this.loadMemberAwards(memberId);
this.loadMemberNfts(memberId);
this.loadMemberSpaces(memberId);
this.loadMemberAwards(memberId);
this.loadMemberNfts(memberId);
} else {
this.resetMemberData();
this.resetMemberData();
}
}

Expand Down Expand Up @@ -175,18 +175,21 @@ export class CartService {
}

private loadMemberNfts(memberId: string): void {
this.algoliaService.fetchAllOwnedNfts(memberId, COL.NFT).then(nfts => {
const results = this.convertAllToSoonaverseModel(nfts);

const collectionIds = results.map(hit => hit.collection)
.filter((value, index, self) => self.indexOf(value) === index);
const currentIds = this.memberNftCollectionIdsSubject$.getValue();
const allIds = [...new Set([...currentIds, ...collectionIds])];
this.memberNftCollectionIdsSubject$.next(allIds);
}).catch(error => {
console.error('Error fetching owned NFTs:', error);
});

this.algoliaService
.fetchAllOwnedNfts(memberId, COL.NFT)
.then((nfts) => {
const results = this.convertAllToSoonaverseModel(nfts);

const collectionIds = results
.map((hit) => hit.collection)
.filter((value, index, self) => self.indexOf(value) === index);
const currentIds = this.memberNftCollectionIdsSubject$.getValue();
const allIds = [...new Set([...currentIds, ...collectionIds])];
this.memberNftCollectionIdsSubject$.next(allIds);
})
.catch((error) => {
console.error('Error fetching owned NFTs:', error);
});
}

public convertAllToSoonaverseModel(algoliaItems: any[]) {
Expand Down Expand Up @@ -629,7 +632,8 @@ export class CartService {
if (checkPendingTransaction) {
const pendingTrx = this.hasPendingTransaction();
if (pendingTrx) {
message = 'Finish pending cart checkout transaction or wait for it to expire before adding more items to cart.';
message =
'Finish pending cart checkout transaction or wait for it to expire before adding more items to cart.';
return of({
isAvailable,
message,
Expand Down Expand Up @@ -724,13 +728,17 @@ export class CartService {
collection?.access !== 3 ||
(collection?.access === 3 &&
collection?.accessAwards?.some((award) => memberAwards.includes(award)));
if (!spaceAwardAccess) conditions.push('Member does not have the required awards for access.');
if (!spaceAwardAccess)
conditions.push('Member does not have the required awards for access.');

nftOwnedAccess =
collection?.access !== 4 ||
(collection?.access === 4 &&
collection?.accessCollections?.every((coll) => memberNftCollectionIds.includes(coll)));
if (!nftOwnedAccess) conditions.push('Member does not own at least one NFT from each of the required access collections.');
collection?.access !== 4 ||
(collection?.access === 4 &&
collection?.accessCollections?.every((coll) => memberNftCollectionIds.includes(coll)));
if (!nftOwnedAccess)
conditions.push(
'Member does not own at least one NFT from each of the required access collections.',
);
}

isAvailable =
Expand Down Expand Up @@ -761,7 +769,12 @@ export class CartService {
cartItem: CartItem,
checkCartPresence = false,
): Observable<{ isAvailable: boolean; message: string }> {
return this.isNftAvailableForSale(cartItem.nft, cartItem.collection, checkCartPresence, false).pipe(
return this.isNftAvailableForSale(
cartItem.nft,
cartItem.collection,
checkCartPresence,
false,
).pipe(
map((result) => {
return {
isAvailable: result.isAvailable,
Expand Down
10 changes: 8 additions & 2 deletions src/app/components/nft/components/nft-card/nft-card.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnDestroy, OnInit } from '@angular/core';
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
Input,
OnDestroy,
OnInit,
} from '@angular/core';
import { Router } from '@angular/router';
import { FileApi } from '@api/file.api';
import { MemberApi } from '@api/member.api';
Expand Down Expand Up @@ -100,7 +107,6 @@ export class NftCardComponent implements OnInit, OnDestroy {
});
}


public onBuy(event: MouseEvent): void {
event.stopPropagation();
event.preventDefault();
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/member/pages/nfts/nfts.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class NFTsPage implements OnInit {
}

public convertAllToSoonaverseModel(algoliaItems: any[]) {
return algoliaItems.map((algolia) => ({
return algoliaItems.map((algolia) => ({
...algolia,
availableFrom: Timestamp.fromMillis(+algolia.availableFrom),
}));
Expand Down

0 comments on commit 6f1a25b

Please sign in to comment.