File: /var/www/vhost/disk-apps/pwa.sports-crowd.com/src/app/pages/wallet/wallet.page.ts
import { Component, OnInit } from '@angular/core';
import { StorageService } from '../../services/storage.service';
import { UtilsService } from "../../services/utils.service";
import { WalletService } from "../../services/wallet.service";
import { CityService } from "../../services/city.service";
import { TranslateService } from "@ngx-translate/core";
import { Clipboard } from '@capacitor/clipboard';
@Component({
selector: 'app-wallet',
templateUrl: './wallet.page.html',
styleUrls: ['./wallet.page.scss'],
})
export class WalletPage implements OnInit {
coupons: any;
wallet = "coupons";
emptySettingsSlide: any;
codeCoupon: any;
linkCoupon: any;
isSubscriber: boolean = false;
constructor(
private storage: StorageService,
private utilsService: UtilsService,
public walletService: WalletService,
public translateService: TranslateService,
public cityProvider: CityService
) { }
ngOnInit() {
this.storage.get("infoUser").then((info) => {
if (info && info.is_subscriber == 1)
this.isSubscriber = true;
});
this.emptySettingsSlide = {
showImage: false,
urlImage: "",
showText: true,
text: this.translateService.instant("NOT_WALLET"),
};
this.getCoupons();
}
validateCoupon(item) {
let show = true;
if (item.isSubscriber && !this.isSubscriber) {
show = false;
}
return show;
}
getCoupons() {
this.storage.get("token").then(async (token) => {
if (token) {
(await this.walletService.getCoupons(token.access_token)).subscribe(
(resp: any) => {
if (!this.coupons) {
this.coupons = [];
}
this.coupons.push(...resp);
},
(error) => {
this.coupons = null;
console.log("error getCoupons: ", error);
}
);
}
});
}
getCouponCode(codeCoupon) {
Clipboard.write({
string: codeCoupon
});
this.utilsService.presentToast(3000, "success", "top", this.translateService.instant("COPY_COUPON", {
code: codeCoupon,
}));
}
openTermsSI(link) {
this.utilsService.openLink(link);
}
openLinkRedeem(link) {
this.utilsService.openLink(link);
}
}