File: /var/www/vhost/disk-apps/pwa.sports-crowd.com/src/app/pages/coins/coins.page.ts
import { Component, OnInit } from '@angular/core';
import { StorageService } from '../../services/storage.service';
import { LealService } from '../../services/leal.service';
import { UtilsService } from '../../services/utils.service';
import { TranslateService } from '@ngx-translate/core';
import { UserService } from "../../services/user.service";
import { AlertController } from '@ionic/angular';
@Component({
selector: 'app-coins',
templateUrl: './coins.page.html',
styleUrls: ['./coins.page.scss'],
})
export class CoinsPage implements OnInit {
coins: number;
external_coins: number;
credit_coins: number;
transactions: any = [];
viewTransactions: any = [];
creditTransactions: any = [];
selectedIndexShopping = -1;
selectedIndexPoints = -1;
selectedIndexCredit = 1;
messageText: any;
constructor(private storage: StorageService,
private lealService: LealService,
private utilsService: UtilsService,
private translateService: TranslateService,
public userProvider: UserService,
public alertController: AlertController) {
this.translateService
.get([
"INFO_TITLE_COINS",
"INFO_DETAIL_COINS",
])
.subscribe((values) => {
this.messageText = {
titleHelpCoins: values.INFO_TITLE_COINS,
textHelpCoins: values.INFO_DETAIL_COINS,
};
});
}
ngOnInit() {
this.loadCoins();
}
loadCoins() {
this.storage.get("infoUser").then((infoUser) => {
if (infoUser) {
this.storage.get("token").then(async (token) => {
if (token) {
this.utilsService.presentLoading(this.translateService.instant("all.loading"));
(await this.lealService.coins(token.access_token, infoUser.coin_uid ? infoUser.coin_uid : 0)).subscribe(
(resp) => {
this.external_coins = resp['external_coins'] ? parseInt(resp['external_coins']) : 0;
this.credit_coins = resp['credit_coins'] ? parseInt(resp['credit_coins']) : 0;
this.coins = this.external_coins + this.credit_coins;
this.transactions = resp["external_transactions"];
this.viewTransactions = resp["external_transactions"];
this.creditTransactions = resp["credit_transactions"];
this.utilsService.dismissLoading();
},
(error) => {
console.log("Error coins", error);
this.utilsService.dismissLoading();
}
);
}
});
}
});
}
filterCredit(sign: number) {
this.selectedIndexCredit = sign;
}
doRefresh(event) {
setTimeout(() => {
this.loadCoins();
event.target.complete();
}, 500);
}
async presentAlert() {
const alert = await this.alertController.create({
cssClass: 'my-custom-class',
header: this.messageText.titleHelpCoins,
message: this.messageText.textHelpCoins,
buttons: ['OK'],
});
await alert.present();
const { role } = await alert.onDidDismiss();
console.log('onDidDismiss resolved with role', role);
}
}