diff --git a/src/components/app-main/AppMainElement.ts b/src/components/app-main/AppMainElement.ts index 5628263..a8a5720 100644 --- a/src/components/app-main/AppMainElement.ts +++ b/src/components/app-main/AppMainElement.ts @@ -5,6 +5,7 @@ import { closest, controller, target } from 'core/utils'; import { AppLoaderElement } from 'components/app-loader/AppLoaderElement'; import { ToastPortalElement } from 'components/toast-portal/ToastPortalElement'; import { BasePageElement } from 'common/'; +import { TransactionsService } from 'services/'; @controller('app-main') class AppMainElement extends HTMLElement { @@ -12,6 +13,8 @@ class AppMainElement extends HTMLElement { public authStore: AuthStore; private httpClient: HttpClient; public appService: AppService; + private transactionsService: TransactionsService; + private subscriptionChecked: boolean = false; //public shadow: any; @target appModal: AppModalElement; @target mainRoot: AppRootElement; @@ -36,6 +39,7 @@ class AppMainElement extends HTMLElement { this.httpClient = new HttpClient(); this.appService = new AppService(this, this.httpClient); this.routerService = new RouterService(this, mainRoot); + this.transactionsService = new TransactionsService(this.appService); this.authStore = new AuthStore(this, this.appService); this.routerService.setRoutes([ { @@ -113,6 +117,8 @@ class AppMainElement extends HTMLElement { this.routerService.init(); this.addEventListener('mousedown', this.setActiveElement, false); this.addEventListener('tokenchange', this.closeOffToken); + this.addEventListener('routechanged', this.checkSubscriptions); + this.checkSubscriptions(); } closeOffToken = () => { @@ -121,9 +127,19 @@ class AppMainElement extends HTMLElement { } }; + checkSubscriptions = async () => { + if (this.isAuth && !this.subscriptionChecked) { + const checked = await this.transactionsService.check(); + console.log(checked); + this.subscriptionChecked = true; + this.removeEventListener('routechanged', this.checkSubscriptions); + } + }; + disconnectedCallback = () => { this.removeEventListener('mousedown', this.setActiveElement); this.removeEventListener('tokenchange', this.closeOffToken); + this.removeEventListener('routechanged', this.checkSubscriptions); }; setActiveElement = (e) => { diff --git a/src/pages/history-page/HistoryPageElement.ts b/src/pages/history-page/HistoryPageElement.ts index 7be7d33..e54913a 100644 --- a/src/pages/history-page/HistoryPageElement.ts +++ b/src/pages/history-page/HistoryPageElement.ts @@ -41,6 +41,7 @@ class HistoryPageElement extends BasePageElement { } options.embed = 'TransactionType'; options.sortBy = 'transactionDate|desc'; + options.noPending = true; const response = await this.transactionsService.getAll(options); return response; } catch (err) { diff --git a/src/pages/wallet-page/WalletPageElement.ts b/src/pages/wallet-page/WalletPageElement.ts index bf17dd4..5082c1f 100644 --- a/src/pages/wallet-page/WalletPageElement.ts +++ b/src/pages/wallet-page/WalletPageElement.ts @@ -70,6 +70,7 @@ class WalletPageElement extends BasePageElement { } options.embed = 'TransactionType'; options.sortBy = 'transactionDate|desc'; + options.noPending = true; const response = await this.transactionsService.getAll(options); return response; } catch (err) { diff --git a/src/services/TransactionsService.ts b/src/services/TransactionsService.ts index 4874668..5e1c521 100644 --- a/src/services/TransactionsService.ts +++ b/src/services/TransactionsService.ts @@ -4,6 +4,10 @@ class TransactionsService extends BaseService { constructor(appService: AppService) { super('/transaction', appService); } + + check = (params?: Object, headers?: HeadersInit) => { + return this.appService.get(this.endpoint + '/check', params, headers); + }; } export default TransactionsService;