Skip to content

Commit

Permalink
lint/prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
amenconi committed Mar 3, 2024
1 parent 5d984e4 commit 3ab2ab3
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ <h4 class="modal-title">Your Cart</h4>
nzType="default"
[disabled]="
((cartService.pendingTransaction$ | async) &&
!helper.isExpired(cartService.pendingTransaction$ | async) &&
(cartService.selectedNetwork$ | async) === item.pricing.tokenSymbol) ||
!helper.isExpired(cartService.pendingTransaction$ | async) &&
(cartService.selectedNetwork$ | async) === item.pricing.tokenSymbol) ||
(isLoading$ | async)
"
(click)="removeFromCart(item)"
Expand All @@ -384,7 +384,7 @@ <h4 class="modal-title">Your Cart</h4>
</div>
<ng-template #emptyCart>Your cart is empty.</ng-template>
<div class="tester">
Pending Transaction: {{ (cartService.pendingTransaction$ | async) }}
Pending Transaction: {{ cartService.pendingTransaction$ | async }}
<br />
Transaction Expired: {{ helper.isExpired(cartService.pendingTransaction$ | async) }}
</div>
Expand All @@ -407,7 +407,11 @@ <h4 class="modal-title">Your Cart</h4>
nz-button
nzType="default"
(click)="clearCart()"
[disabled]="(cartService.pendingTransaction$ | async) && !helper.isExpired(cartService.pendingTransaction$ | async) || (isLoading$ | async)"
[disabled]="
((cartService.pendingTransaction$ | async) &&
!helper.isExpired(cartService.pendingTransaction$ | async)) ||
(isLoading$ | async)
"
nz-tooltip
[nzTooltipTitle]="(isLoading$ | async) ? 'Waiting for cart items to finish loading' : ''"
class="text-red-600 hover:text-red-800"
Expand All @@ -425,7 +429,6 @@ <h4 class="modal-title">Your Cart</h4>
Checkout
</button>
</div>

</div>
</nz-modal>
</ng-container>
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { Component, OnDestroy, ChangeDetectorRef, ChangeDetectionStrategy, OnInit } from '@angular/core';
import {
Component,
OnDestroy,
ChangeDetectorRef,
ChangeDetectionStrategy,
OnInit,
} from '@angular/core';
import { Network, Transaction } from '@build-5/interfaces';
import { Subscription, take, of, Observable, BehaviorSubject, Subject } from 'rxjs';
import { CartService, CartItem } from '@components/cart/services/cart.service';
Expand All @@ -9,7 +15,7 @@ import { UnitsService } from '@core/services/units/units.service';
import { map, switchMap, tap } from 'rxjs/operators';
import { DeviceService } from '@core/services/device';
import { HelperService } from '@pages/nft/services/helper.service';
import { } from '@angular/core';
import {} from '@angular/core';

export enum StepType {
CONFIRM = 'Confirm',
Expand Down Expand Up @@ -52,7 +58,7 @@ export class CartModalComponent implements OnInit, OnDestroy {
public currentStep: StepType | null = null;
public isTransactionExpired: boolean | null = null;
public selectedNetwork: string | null = null;
public isLoading: boolean = false;
public isLoading = false;
public pendingTransaction: Transaction | undefined = undefined;

constructor(
Expand All @@ -67,43 +73,43 @@ export class CartModalComponent implements OnInit, OnDestroy {

ngOnInit() {
this.subscriptions$.add(
this.cartService.currentStep$.subscribe(step => {
this.currentStep = step;
this.triggerChangeDetection();
})
this.cartService.currentStep$.subscribe((step) => {
this.currentStep = step;
this.triggerChangeDetection();
}),
);

this.subscriptions$.add(
this.cartService.selectedNetwork$.subscribe(network => {
this.selectedNetwork = network;
this.triggerChangeDetection();
})
this.cartService.selectedNetwork$.subscribe((network) => {
this.selectedNetwork = network;
this.triggerChangeDetection();
}),
);

this.subscriptions$.add(
this.cartService.pendingTransaction$.subscribe(transaction => {
this.cartService.pendingTransaction$.subscribe((transaction) => {
this.pendingTransaction = transaction;
this.triggerChangeDetection();
})
}),
);

this.subscriptions$.add(
this.cartService.isLoading$.subscribe(loading => {
this.isLoading = loading;
this.triggerChangeDetection();
})
this.cartService.isLoading$.subscribe((loading) => {
this.isLoading = loading;
this.triggerChangeDetection();
}),
);

this.subscriptions$.add(
this.cartService.cartUpdateObservable$.subscribe(() => {
this.triggerChangeDetection();
})
this.cartService.cartUpdateObservable$.subscribe(() => {
this.triggerChangeDetection();
}),
);

this.subscriptions$.add(
this.cartService.triggerChangeDetectionSubject$.subscribe(() => {
this.triggerChangeDetection();
})
this.triggerChangeDetection();
}),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
<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.totalQuantity }}</span> NFTs in network group
with total Price of
<span class="font-bold">{{ group.totalQuantity }}</span> NFTs in network group with
total Price of
{{ group.totalPrice | formatToken : group.network : true : true | async }} ({{
unitsService.getUsd(
cartService.valueDivideExponent({
Expand Down
53 changes: 28 additions & 25 deletions src/app/components/cart/services/cart.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,39 +121,42 @@ export class CartService {

private listenToStorageChanges(): void {
window.addEventListener('storage', (event) => {
if (event.storageArea === localStorage) {
this.zone.run(() => {
switch (event.key) {
case CART_STORAGE_KEY:
const updatedCartItems = JSON.parse(event.newValue || '[]');
this.cartItemsSubject$.next(updatedCartItems);
break;
case NETWORK_STORAGE_KEY:
const updatedNetwork = JSON.parse(event.newValue || 'null');
this.selectedNetworkSubject$.next(updatedNetwork);
break;
case STEP_STORAGE_KEY:
const newStep = JSON.parse(event.newValue || 'null');
this.currentStepSubject$.next(newStep);
break;
case TRAN_STORAGE_KEY:
const newTran = JSON.parse(event.newValue || 'null');
this.pendingTransaction$.next(newTran);
break;
}
this.cartUpdateSubject$.next();
});
}
if (event.storageArea === localStorage) {
this.zone.run(() => {
switch (event.key) {
case CART_STORAGE_KEY: {
const updatedCartItems = JSON.parse(event.newValue || '[]');
this.cartItemsSubject$.next(updatedCartItems);
break;
}
case NETWORK_STORAGE_KEY: {
const updatedNetwork = JSON.parse(event.newValue || 'null');
this.selectedNetworkSubject$.next(updatedNetwork);
break;
}
case STEP_STORAGE_KEY: {
const newStep = JSON.parse(event.newValue || 'null');
this.currentStepSubject$.next(newStep);
break;
}
case TRAN_STORAGE_KEY: {
const newTran = JSON.parse(event.newValue || 'null');
this.pendingTransaction$.next(newTran);
break;
}
}
this.cartUpdateSubject$.next();
});
}
});
}

public startTransactionExpiryCheck(): void {
if (this.transactionCheckInterval) {
clearInterval(this.transactionCheckInterval);
clearInterval(this.transactionCheckInterval);
}

this.transactionCheckInterval = setInterval(() => {

const transaction = this.pendingTransaction$.getValue();
const currentStep = this.getCurrentStep();
if (currentStep === StepType.TRANSACTION || currentStep === StepType.WAIT) {
Expand Down

0 comments on commit 3ab2ab3

Please sign in to comment.