Skip to content

Commit

Permalink
Successful NFT transaction send notification and removes bought NFTs …
Browse files Browse the repository at this point in the history
…from cart when checkout modal is closed.
amenconi committed Mar 19, 2024
1 parent 66a6781 commit 625eafd
Showing 3 changed files with 48 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -185,6 +185,7 @@ export class CheckoutOverlayComponent implements OnInit, OnDestroy {
(<any>val).payload?.chainReference,
);

this.removePurchasedGroupItems();
this.currentStep = StepType.COMPLETE;
this.updateStep(this.currentStep);
this.cd.markForCheck();
@@ -493,7 +494,8 @@ export class CheckoutOverlayComponent implements OnInit, OnDestroy {
private removePurchasedGroupItems(): void {
if (this.selectedNetwork) {
this.cartService.removeGroupItemsFromCart(this.selectedNetwork);
this.cartService.clearNetworkSelection();
} else {
this.cartService.removeGroupItemsFromCart();
}
}

48 changes: 42 additions & 6 deletions src/app/components/cart/services/cart.service.ts
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ import {
Nft,
Collection,
Transaction,
TransactionType,
MIN_AMOUNT_TO_TRANSFER,
TRANSACTION_AUTO_EXPIRY_MS,
DEFAULT_NETWORK,
@@ -172,13 +173,33 @@ export class CartService {
transaction.payload?.void ||
transaction.payload?.reconciled
) {
removeItem(StorageItem.CheckoutTransaction);
this.pendingTransaction$.next(undefined);
this.triggerChangeDetectionSubject$.next();
clearInterval(this.transactionCheckInterval);
this.transactionCheckInterval = null;
if (transaction.payload?.reconciled) {
this.removeGroupItemsFromCart();
this.notification.success($localize`NFT(s) successfully purchased.`, '');
this.setCurrentStep(StepType.CONFIRM);
removeItem(StorageItem.CheckoutTransaction);
this.pendingTransaction$.next(undefined);
this.triggerChangeDetectionSubject$.next();
clearInterval(this.transactionCheckInterval);
this.transactionCheckInterval = null;
}
else if (transaction.payload?.void && !transaction.payload?.reconciled) {
this.notification.error($localize`NFT purchase transaction expired.`, '');
this.setCurrentStep(StepType.CONFIRM);
removeItem(StorageItem.CheckoutTransaction);
this.pendingTransaction$.next(undefined);
this.triggerChangeDetectionSubject$.next();
clearInterval(this.transactionCheckInterval);
this.transactionCheckInterval = null;
}
else {
removeItem(StorageItem.CheckoutTransaction);
this.pendingTransaction$.next(undefined);
this.triggerChangeDetectionSubject$.next();
}
}
} else {
this.setCurrentStep(StepType.CONFIRM);
removeItem(StorageItem.CheckoutTransaction);
this.pendingTransaction$.next(undefined);
this.triggerChangeDetectionSubject$.next();
@@ -688,8 +709,23 @@ export class CartService {
return this.calc(itemPrice, discount);
}

public removeGroupItemsFromCart(tokenSymbol: string): void {
public removeGroupItemsFromCart(tokenSymbol?: string): void {
if (!tokenSymbol) {
this.selectedNetwork$.pipe(take(1)).subscribe((defaultTokenSymbol) => {
if (defaultTokenSymbol == null) {
console.warn('No default token symbol found, no updates performed.');
} else {
this.performCartUpdate(defaultTokenSymbol);
}
});
} else {
this.performCartUpdate(tokenSymbol);
}
}

private performCartUpdate(tokenSymbol: string): void {
const updatedCartItems = this.cartItemsSubject$.value.filter((item) => {

const itemTokenSymbol =
(item.nft?.placeholderNft
? item.collection?.mintingData?.network
Original file line number Diff line number Diff line change
@@ -556,6 +556,9 @@ <h3 class="mb-1 text-2xl font-bold truncate">{{ getTitle() }}</h3>
>
</wen-send-funds>

<div>
network print: {{ collection?.mintingData?.network }}
</div>
<wen-wallet-deeplink
*ngIf="!helper.isExpired(transaction$ | async)"
class="mt-6"

0 comments on commit 625eafd

Please sign in to comment.