import {ChangeDetectionStrategy, Component, Input, OnInit} from '@angular/core'; import {Router} from '@angular/router'; import {TransactionService} from '@app/_services'; import {copyToClipboard} from '../../../_helpers'; import {MatSnackBar} from '@angular/material/snack-bar'; @Component({ selector: 'app-transaction-details', templateUrl: './transaction-details.component.html', styleUrls: ['./transaction-details.component.scss'], changeDetection: ChangeDetectionStrategy.OnPush }) export class TransactionDetailsComponent implements OnInit { @Input() transaction; senderBloxbergLink: string; recipientBloxbergLink: string; traderBloxbergLink: string; constructor( private router: Router, private transactionService: TransactionService, private snackBar: MatSnackBar, ) { } ngOnInit(): void { if (this.transaction?.type === 'conversion') { this.traderBloxbergLink = 'https://blockexplorer.bloxberg.org/address/' + this.transaction?.trader + '/transactions'; } else { this.senderBloxbergLink = 'https://blockexplorer.bloxberg.org/address/' + this.transaction?.from + '/transactions'; this.recipientBloxbergLink = 'https://blockexplorer.bloxberg.org/address/' + this.transaction?.to + '/transactions'; } } async viewSender(): Promise { await this.router.navigateByUrl(`/accounts/${this.transaction.from}`); } async viewRecipient(): Promise { await this.router.navigateByUrl(`/accounts/${this.transaction.to}`); } async viewTrader(): Promise { await this.router.navigateByUrl(`/accounts/${this.transaction.trader}`); } async reverseTransaction(): Promise { await this.transactionService.transferRequest( this.transaction.token.address, this.transaction.to, this.transaction.from, this.transaction.value ); } copyAddress(address: string): void { if (copyToClipboard(address)) { this.snackBar.open(address + ' copied successfully!', 'Close', { duration: 3000 }); } } }