From 625eafd2352e5c3410b0b0632bacad2504af042d Mon Sep 17 00:00:00 2001 From: Alec Menconi Date: Tue, 19 Mar 2024 00:03:38 -0400 Subject: [PATCH 1/2] Successful NFT transaction send notification and removes bought NFTs from cart when checkout modal is closed. --- .../checkout/checkout-overlay.component.ts | 4 +- .../components/cart/services/cart.service.ts | 48 ++++++++++++++++--- .../nft-checkout/nft-checkout.component.html | 3 ++ 3 files changed, 48 insertions(+), 7 deletions(-) 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 4b78109..b21c476 100644 --- a/src/app/components/cart/components/checkout/checkout-overlay.component.ts +++ b/src/app/components/cart/components/checkout/checkout-overlay.component.ts @@ -185,6 +185,7 @@ export class CheckoutOverlayComponent implements OnInit, OnDestroy { (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(); } } diff --git a/src/app/components/cart/services/cart.service.ts b/src/app/components/cart/services/cart.service.ts index b3eaee4..1f7501e 100644 --- a/src/app/components/cart/services/cart.service.ts +++ b/src/app/components/cart/services/cart.service.ts @@ -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 diff --git a/src/app/components/nft/components/nft-checkout/nft-checkout.component.html b/src/app/components/nft/components/nft-checkout/nft-checkout.component.html index 3c7e742..a3fedba 100644 --- a/src/app/components/nft/components/nft-checkout/nft-checkout.component.html +++ b/src/app/components/nft/components/nft-checkout/nft-checkout.component.html @@ -556,6 +556,9 @@

{{ getTitle() }}

> +
+ network print: {{ collection?.mintingData?.network }} +
Date: Tue, 19 Mar 2024 00:18:07 -0400 Subject: [PATCH 2/2] lint/prettier commit --- src/app/components/cart/services/cart.service.ts | 7 ++----- .../components/nft-checkout/nft-checkout.component.html | 4 +--- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/app/components/cart/services/cart.service.ts b/src/app/components/cart/services/cart.service.ts index 1f7501e..3ebe16b 100644 --- a/src/app/components/cart/services/cart.service.ts +++ b/src/app/components/cart/services/cart.service.ts @@ -182,8 +182,7 @@ export class CartService { this.triggerChangeDetectionSubject$.next(); clearInterval(this.transactionCheckInterval); this.transactionCheckInterval = null; - } - else if (transaction.payload?.void && !transaction.payload?.reconciled) { + } else if (transaction.payload?.void && !transaction.payload?.reconciled) { this.notification.error($localize`NFT purchase transaction expired.`, ''); this.setCurrentStep(StepType.CONFIRM); removeItem(StorageItem.CheckoutTransaction); @@ -191,8 +190,7 @@ export class CartService { this.triggerChangeDetectionSubject$.next(); clearInterval(this.transactionCheckInterval); this.transactionCheckInterval = null; - } - else { + } else { removeItem(StorageItem.CheckoutTransaction); this.pendingTransaction$.next(undefined); this.triggerChangeDetectionSubject$.next(); @@ -725,7 +723,6 @@ export class CartService { private performCartUpdate(tokenSymbol: string): void { const updatedCartItems = this.cartItemsSubject$.value.filter((item) => { - const itemTokenSymbol = (item.nft?.placeholderNft ? item.collection?.mintingData?.network diff --git a/src/app/components/nft/components/nft-checkout/nft-checkout.component.html b/src/app/components/nft/components/nft-checkout/nft-checkout.component.html index a3fedba..2108834 100644 --- a/src/app/components/nft/components/nft-checkout/nft-checkout.component.html +++ b/src/app/components/nft/components/nft-checkout/nft-checkout.component.html @@ -556,9 +556,7 @@

{{ getTitle() }}

> -
- network print: {{ collection?.mintingData?.network }} -
+
network print: {{ collection?.mintingData?.network }}