HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
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);
  }
}