mempool/frontend/src/app/components/about/about.component.ts

70 lines
2.2 KiB
TypeScript
Raw Normal View History

import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
import { WebsocketService } from '../../services/websocket.service';
2020-03-23 18:52:08 +01:00
import { SeoService } from 'src/app/services/seo.service';
import { StateService } from 'src/app/services/state.service';
import { Observable } from 'rxjs';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { ApiService } from 'src/app/services/api.service';
import { env } from '../../app.constants';
2020-10-09 08:56:43 +02:00
import { DomSanitizer, SafeUrl } from '@angular/platform-browser';
2019-07-21 16:59:47 +02:00
@Component({
selector: 'app-about',
templateUrl: './about.component.html',
styleUrls: ['./about.component.scss'],
2019-07-21 16:59:47 +02:00
})
export class AboutComponent implements OnInit {
gitCommit$: Observable<string>;
donationForm: FormGroup;
donationStatus = 1;
sponsors$: Observable<any>;
donationObj: any;
sponsorsEnabled = env.SPONSORS_ENABLED;
sponsors = null;
2020-10-09 08:56:43 +02:00
bitcoinUrl: SafeUrl;
2019-07-21 16:59:47 +02:00
constructor(
private websocketService: WebsocketService,
2020-03-23 18:52:08 +01:00
private seoService: SeoService,
private stateService: StateService,
private formBuilder: FormBuilder,
private apiService: ApiService,
2020-10-09 08:56:43 +02:00
private sanitizer: DomSanitizer,
) { }
2019-07-21 16:59:47 +02:00
ngOnInit() {
this.gitCommit$ = this.stateService.gitCommit$;
2020-09-28 11:32:48 +02:00
this.seoService.setTitle('About');
2020-02-17 14:39:20 +01:00
this.websocketService.want(['blocks']);
this.donationForm = this.formBuilder.group({
amount: [0.01],
handle: [''],
});
(this.sponsorsEnabled ? this.apiService.getDonation$() : this.apiService.getDonationRemote$())
.subscribe((sponsors) => {
this.sponsors = sponsors;
});
this.apiService.getDonation$()
this.stateService.donationConfirmed$.subscribe(() => this.donationStatus = 4);
}
submitDonation() {
if (this.donationForm.invalid) {
return;
}
this.apiService.requestDonation$(
this.donationForm.get('amount').value,
this.donationForm.get('handle').value
)
.subscribe((response) => {
this.websocketService.trackDonation(response.id);
this.donationObj = response;
2020-10-09 08:56:43 +02:00
this.bitcoinUrl = this.sanitizer.bypassSecurityTrustUrl('bitcoin:' + this.donationObj.address + '?amount=' + this.donationObj.amount);
this.donationStatus = 3;
});
}
2019-07-21 16:59:47 +02:00
}