Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { AfterViewInit, Component, Injector, OnDestroy, OnInit, ViewContainerRef } from '@angular/core';
- import { User } from '../../model/user.model';
- import { ActivatedRoute, Params, Router } from '@angular/router';
- import { ToastsManager } from 'ng2-toastr';
- import { AppComponent } from '../../app.component';
- import { SimpleTimer } from 'ng2-simple-timer';
- import { TranslateService } from '@ngx-translate/core';
- import { environment } from '../../../environments/environment';
- import { JwtService, UserService } from '../../service/index';
- declare const ga: Function;
- @Component({
- selector: 'app-profile',
- templateUrl: './profile.component.html',
- })
- export class ProfileComponent implements OnInit, OnDestroy, AfterViewInit {
- public userModel: User;
- public steamImageUrl: string = 'https://steamcommunity-a.akamaihd.net/economy/image/';
- private appComponent: any;
- public steamPostImageUrl: string = '/130fx97f/image.png';
- private isSendingProcessed: boolean = false;
- private isMessageShowed: boolean = false;
- public isAuthenticated: boolean;
- public facebookAuthUrl: string = `${environment.api_url}/social/facebook/authorize?token=${this.jwtService.getToken()}`;
- constructor(private inj: Injector,
- vcr: ViewContainerRef,
- public toastr: ToastsManager,
- private st: SimpleTimer,
- private userService: UserService,
- private router: Router,
- private jwtService: JwtService,
- private route: ActivatedRoute,
- private translate: TranslateService) {
- this.toastr.setRootViewContainerRef(vcr);
- }
- ngOnInit() {
- this.userService.currentUser.subscribe(user => {
- if (user) {
- this.userModel = user;
- this.route.queryParams.subscribe((params: Params) => {
- if (!this.isMessageShowed && Object.keys(params).length) {
- if (!this.userModel.isTwitterClaimed) {
- this.sendTwitterTokens(params);
- }
- if (params.isFacebookClaimed) {
- this.showFreeCreditsMessage(params);
- }
- if (params.isEmailClailmed) {
- this.confirmEmail(params);
- }
- this.isMessageShowed = true;
- }
- });
- }
- });
- }
- ngAfterViewInit() {
- setTimeout(() => {
- if (this.userModel && this.userModel.orders) {
- this.userModel.orders.forEach((orderSingle: any) => {
- if (orderSingle.status === 'undefined') {
- orderSingle.timer = 1000 * 60 * 60 - (Date.now() - new Date(orderSingle.createdAt).getTime());
- this.st.newTimer(orderSingle.createdAt, 1);
- orderSingle.timerInstance = this.st.subscribe(orderSingle.createdAt, () => {
- orderSingle.timer -= 1000;
- this.millisToMinutesAndSeconds(orderSingle.timer);
- });
- }
- });
- }
- }, 0);
- }
- millisToMinutesAndSeconds(millis: number) {
- if (millis <= 1) return '00:00';
- const minutes = Math.floor(millis / 60000);
- const seconds = ((millis % 60000) / 1000).toFixed(0);
- return minutes + ':' + (parseInt(seconds) < 10 ? '0' : '') + seconds;
- }
- ngOnDestroy() {
- if (this.userModel && this.userModel.orders)
- this.userModel.orders.forEach((orderSingle: any) => {
- if (orderSingle.timerInstance) {
- this.st.unsubscribe(orderSingle.timerInstance);
- orderSingle.timerInstance = undefined;
- }
- });
- }
- displayPaymentDialog(): void {
- ga('send', 'event', 'PROFILE_COMPONENT', 'DIALOG_ADD_FUNDS', 'OPEN');
- if (!this.appComponent)
- this.appComponent = this.inj.get(AppComponent);
- this.appComponent.showAddFunds();
- }
- displayNoFundsDialog(): void {
- ga('send', 'event', 'PROFILE_COMPONENT', 'DIALOG_NO_FUNDS', 'OPEN');
- if (!this.appComponent)
- this.appComponent = this.inj.get(AppComponent);
- this.appComponent.showNoFunds();
- }
- getProfileUrl(): string {
- return 'https://steamcommunity.com/profiles/' + this.userModel.steamId;
- }
- directToMain() {
- this.router.navigateByUrl('/');
- }
- saveTradeUrl(tradeUrl: string): void {
- ga('send', 'event', 'PROFILE_COMPONENT', 'SAVE_TRADE_URL', 'CLICK');
- this.userService.updateTradeUrl(tradeUrl).subscribe(response => {
- if (response.status == 202) {
- this.translate.get(['profile_msg_saved', 'profile_msg_success']).subscribe(str => {
- this.toastr.success(str.profile_msg_saved, str.profile_msg_success);
- });
- } else {
- this.translate.get(['profile_msg_invalid_url', 'profile_msg_failed']).subscribe(str => {
- this.toastr.error(str.profile_msg_invalid_url, str.profile_msg_failed);
- });
- }
- }, e => {
- this.translate.get(['profile_msg_invalid_url', 'profile_msg_failed']).subscribe(str => {
- this.toastr.error(str.profile_msg_invalid_url, str.profile_msg_failed);
- });
- });
- }
- performSendItem(item: any): void {
- ga('send', 'event', 'PROFILE_COMPONENT', 'WITHDRAW_ITEM', 'CLICK');
- this.isSendingProcessed = true;
- this.userService.sendItem(item.id)
- .subscribe(response => {
- this.isSendingProcessed = false;
- switch (response.status) {
- case 200:
- item.status = 'processed';
- this.translate.get(['profile_msg_check_offers', 'profile_msg_success']).subscribe(str => {
- this.toastr.success(str.profile_msg_check_offers, str.profile_msg_success);
- });
- break;
- case 406:
- this.translate.get(['profile_msg_define_url', 'profile_msg_failed']).subscribe(str => {
- this.toastr.error(str.profile_msg_define_url, str.profile_msg_failed);
- });
- break;
- case 429:
- this.translate.get(['profile_msg_have_offer', 'profile_msg_failed']).subscribe(str => {
- this.toastr.error(str.profile_msg_have_offer, str.profile_msg_failed);
- });
- break;
- case 404:
- this.translate.get(['profile_msg_no_item', 'profile_msg_failed']).subscribe(str => {
- this.toastr.error(str.profile_msg_no_item, str.profile_msg_failed);
- });
- break;
- case 402:
- this.translate.get(['profile_msg_make_deposit', 'profile_msg_failed']).subscribe(str => {
- this.toastr.error(str.profile_msg_make_deposit, str.profile_msg_failed);
- });
- this.displayNoFundsDialog();
- break;
- case 403:
- this.translate.get(['withdraw_modal_condition', 'profile_msg_failed']).subscribe(str => {
- this.toastr.error(str.withdraw_modal_condition, str.profile_msg_failed);
- });
- this.displayNoFundsDialog();
- break;
- case 451:
- this.translate.get(['profile_msg_no_game', 'profile_msg_failed']).subscribe(str => {
- this.toastr.error(str.profile_msg_no_game, str.profile_msg_failed);
- });
- break;
- default:
- this.translate.get(['profile_msg_failed_send', 'profile_msg_failed']).subscribe(str => {
- this.toastr.error(str.profile_msg_failed_send, str.profile_msg_failed);
- });
- }
- }, e => {
- this.isSendingProcessed = false;
- this.translate.get(['profile_msg_failed_send', 'profile_msg_failed']).subscribe(str => {
- this.toastr.error(str.profile_msg_failed_send, str.profile_msg_failed);
- });
- });
- }
- performSellItem(item: any): void {
- ga('send', 'event', 'PROFILE_COMPONENT', 'SELL_ITEM', 'CLICK');
- let itemsToSell: Array<any> = [];
- itemsToSell.push(item.id);
- this.userService.sellItem(itemsToSell)
- .subscribe(response => {
- if (response.status == 202) {
- item.status = 'sold';
- this.userModel.balance = response.result.balance;
- this.translate.get(['profile_msg_item_sold', 'profile_msg_success']).subscribe(str => {
- this.toastr.success(str.profile_msg_item_sold, str.profile_msg_success);
- });
- } else {
- this.translate.get(['prize_modal_failed_sell', 'profile_msg_failed']).subscribe(str => {
- this.toastr.error(str.prize_modal_failed_sell, str.profile_msg_failed);
- });
- }
- }, e => {
- this.translate.get(['prize_modal_failed_sell', 'profile_msg_failed']).subscribe(str => {
- this.toastr.error(str.prize_modal_failed_sell, str.profile_msg_failed);
- });
- });
- }
- checkFacebookAccount() {
- return this.userService.checkFacebookAccount()
- .subscribe(response => {
- if (response.result) {
- window.location.href = response.result;
- }
- });
- }
- sendTwitterTokens(params) {
- const twitterOauthToken = params.oauth_token;
- const twitterOauthVerifier = params.oauth_verifier;
- if (twitterOauthToken && twitterOauthVerifier) {
- return this.userService.sendTwitterTokens(twitterOauthToken, twitterOauthVerifier)
- .subscribe(response => {
- this.showFreeCreditsMessage(response);
- });
- }
- }
- confirmEmail(params) {
- this.userService.confirmEmail()
- .subscribe(response => {
- this.showFreeCreditsMessage(params);
- });
- }
- showTwitterConfirmation() {
- ga('send', 'event', 'PROFILE', 'TWITTER_CONFIRM', 'OPEN');
- if (!this.appComponent) {
- this.appComponent = this.inj.get(AppComponent);
- }
- this.appComponent.showTwitterConfirmation();
- }
- showEmailConfirmation() {
- ga('send', 'event', 'PROFILE', 'EMAIL_CONFIRM', 'OPEN');
- if (!this.appComponent) {
- this.appComponent = this.inj.get(AppComponent);
- }
- this.appComponent.showEmailConfirmation();
- }
- showFreeCreditsMessage(response) {
- if (response.isFollower) {
- this.userService.populate();
- this.translate.get(['profile_msg_free_credits_added', 'profile_msg_success']).subscribe(str => {
- this.toastr.success(str.profile_msg_free_credits_added, str.profile_msg_success);
- });
- } else {
- this.translate.get(['profile_msg_fail_subscribe', 'profile_msg_failed']).subscribe(str => {
- this.toastr.error(str.profile_msg_fail_subscribe, str.profile_msg_failed);
- });
- }
- }
- onMouseWinItem( order: any )
- {
- if( order.caseName!="giveaway" ) {
- order.onItemTarget=true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement