Skip to content

Commit

Permalink
Implemented single nft bulk buy
Browse files Browse the repository at this point in the history
  • Loading branch information
amenconi committed Jan 26, 2024
1 parent 8a9e7df commit 9b50b49
Show file tree
Hide file tree
Showing 9 changed files with 467 additions and 78 deletions.
5 changes: 5 additions & 0 deletions src/app/@api/order.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
WEN_FUNC,
Build5Request,
NftPurchaseRequest,
NftPurchaseBulkRequest,
OrderTokenRequest,
AddressValidationRequest,
NftBidRequest,
Expand All @@ -27,6 +28,10 @@ export class OrderApi extends BaseApi<Transaction> {
public orderNft = (req: Build5Request<NftPurchaseRequest>): Observable<Transaction | undefined> =>
this.request(WEN_FUNC.orderNft, req);

public orderNfts = (
req: Build5Request<NftPurchaseBulkRequest>,
): Observable<Transaction | undefined> => this.request(WEN_FUNC.orderNftBulk, req);

public orderToken = (
req: Build5Request<OrderTokenRequest>,
): Observable<Transaction | undefined> => this.request(WEN_FUNC.orderToken, req);
Expand Down
1 change: 1 addition & 0 deletions src/app/@shell/ui/header/header.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
[isOpen]="isCheckoutOpen"
[nft]="currentCheckoutNft"
[collection]="currentCheckoutCollection"
[nftQuantity]="nftQty ?? 1"
(wenOnClose)="closeCheckout()"
></wen-nft-checkout>

Expand Down
37 changes: 30 additions & 7 deletions src/app/@shell/ui/header/header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { ROUTER_UTILS } from '@core/utils/router.utils';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import {
Collection,
CollectionType,
FILE_SIZES,
Member,
Nft,
Expand Down Expand Up @@ -78,6 +79,7 @@ export class HeaderComponent implements OnInit, OnDestroy {
public isCheckoutOpen = false;
public currentCheckoutNft?: Nft;
public currentCheckoutCollection?: Collection;
public nftQty?: number;
public notifications$: BehaviorSubject<Notification[]> = new BehaviorSubject<Notification[]>([]);
private notificationRef?: NzNotificationRef;
public expiryTicker$: BehaviorSubject<dayjs.Dayjs | null> =
Expand Down Expand Up @@ -221,26 +223,47 @@ export class HeaderComponent implements OnInit, OnDestroy {
}

public async onOpenCheckout(): Promise<void> {
// console.log('Open Checkout clicked');
const t = this.transaction$.getValue();
if (!t?.payload.nft || !t.payload.collection) {
return;
let colId = '';
let nftId = '';
// console.log('open checkout transaction value: ', t);

if (t?.payload.nftOrders && t?.payload.nftOrders?.length > 0) {
// console.log('open checkout passed if test for bulk order. bool (t?.payload.nftOrders) and t?.payload.nftOrders?.length (bulk count): ', t?.payload.nftOrders, t?.payload.nftOrders?.length);
colId = t?.payload.nftOrders[0].collection;
nftId = t?.payload.nftOrders[0].nft;
this.nftQty = t?.payload.nftOrders.length;
} else {
// console.log('open checkout failed if test for bulk order and will use nft, collection (colId, nftId): ', t?.payload.collection, t?.payload?.nft);
if (!t?.payload.nft || !t.payload.collection) {
return;
}
colId = t?.payload.collection;
nftId = t?.payload?.nft;
this.nftQty = 1;
}

const collection: Collection | undefined = await firstValueFrom(
this.collectionApi.listen(t?.payload.collection),
this.collectionApi.listen(colId),
);
let nft: Nft | undefined = undefined;
try {
nft = await firstValueFrom(this.nftApi.listen(t?.payload?.nft));
} catch (_e) {
// If it's not classic or re-sale we're using placeholder NFT
nft = await firstValueFrom(this.nftApi.listen(nftId));
// console.log('open checkout collection and nft value set (colId, collection, nftId, nft): ', colId, collection, nftId, nft);

if (!nft) {
// console.log('open checkout try nft failed, previous nft value (nftId, nft): ', nftId, nft);
if (collection?.placeholderNft) {
nft = await firstValueFrom(this.nftApi.listen(collection?.placeholderNft));
// console.log('open checkout try nft failed, will attempt to set nft based on collection placeholer (collection?.placeholderNft): ', collection?.placeholderNft);
}
}

if (nft && collection) {
this.currentCheckoutCollection = collection;
this.currentCheckoutNft = nft;
this.isCheckoutOpen = true;
// console.log('Checkout Open initiated with the following values (collection, nft, bulk order bool, bulk order count, transaction', collection, nft, (t?.payload.nftOrders && t?.payload.nftOrders.length > 0), t?.payload.nftOrders?.length, t)
this.cd.markForCheck();
}
}
Expand Down
Loading

0 comments on commit 9b50b49

Please sign in to comment.