check for pending transactions

This commit is contained in:
Fran Jurmanović
2021-11-07 15:16:03 +01:00
parent 2a3bdb925b
commit db25f78a84
4 changed files with 22 additions and 0 deletions

View File

@@ -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) => {

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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;