2021-05-26 11:21:25 +02:00
|
|
|
import {
|
|
|
|
ChangeDetectionStrategy,
|
|
|
|
Component,
|
|
|
|
EventEmitter,
|
|
|
|
Input,
|
|
|
|
OnInit,
|
|
|
|
Output,
|
|
|
|
} from '@angular/core';
|
2021-05-10 18:15:25 +02:00
|
|
|
import { Router } from '@angular/router';
|
2021-06-09 17:04:29 +02:00
|
|
|
import { TokenService, TransactionService } from '@app/_services';
|
2021-05-10 18:15:25 +02:00
|
|
|
import { copyToClipboard } from '@app/_helpers';
|
|
|
|
import { MatSnackBar } from '@angular/material/snack-bar';
|
|
|
|
import { strip0x } from '@src/assets/js/ethtx/dist/hex';
|
2020-11-04 13:36:30 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-transaction-details',
|
|
|
|
templateUrl: './transaction-details.component.html',
|
2021-03-14 09:23:20 +01:00
|
|
|
styleUrls: ['./transaction-details.component.scss'],
|
2021-05-10 18:15:25 +02:00
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
2020-11-04 13:36:30 +01:00
|
|
|
})
|
|
|
|
export class TransactionDetailsComponent implements OnInit {
|
2020-12-05 07:30:30 +01:00
|
|
|
@Input() transaction;
|
2021-05-26 11:21:25 +02:00
|
|
|
|
|
|
|
@Output() closeWindow: EventEmitter<any> = new EventEmitter<any>();
|
|
|
|
|
2021-03-15 12:58:18 +01:00
|
|
|
senderBloxbergLink: string;
|
|
|
|
recipientBloxbergLink: string;
|
2021-04-26 12:14:36 +02:00
|
|
|
traderBloxbergLink: string;
|
2021-06-09 17:04:29 +02:00
|
|
|
tokenName: string;
|
|
|
|
tokenSymbol: string;
|
2020-11-04 13:36:30 +01:00
|
|
|
|
2021-03-19 15:40:45 +01:00
|
|
|
constructor(
|
|
|
|
private router: Router,
|
2021-04-26 12:14:36 +02:00
|
|
|
private transactionService: TransactionService,
|
2021-06-09 17:04:29 +02:00
|
|
|
private snackBar: MatSnackBar,
|
|
|
|
private tokenService: TokenService
|
2021-05-10 18:15:25 +02:00
|
|
|
) {}
|
2020-11-04 13:36:30 +01:00
|
|
|
|
2021-07-13 18:57:28 +02:00
|
|
|
ngOnInit(): void {
|
2021-04-26 13:47:18 +02:00
|
|
|
if (this.transaction?.type === 'conversion') {
|
2021-05-10 18:15:25 +02:00
|
|
|
this.traderBloxbergLink =
|
|
|
|
'https://blockexplorer.bloxberg.org/address/' + this.transaction?.trader + '/transactions';
|
2021-04-26 12:14:36 +02:00
|
|
|
} else {
|
2021-05-10 18:15:25 +02:00
|
|
|
this.senderBloxbergLink =
|
|
|
|
'https://blockexplorer.bloxberg.org/address/' + this.transaction?.from + '/transactions';
|
|
|
|
this.recipientBloxbergLink =
|
|
|
|
'https://blockexplorer.bloxberg.org/address/' + this.transaction?.to + '/transactions';
|
2021-04-26 12:14:36 +02:00
|
|
|
}
|
2021-06-09 17:52:59 +02:00
|
|
|
this.tokenService.load.subscribe(async (status: boolean) => {
|
2021-06-09 17:04:29 +02:00
|
|
|
if (status) {
|
|
|
|
this.tokenSymbol = await this.tokenService.getTokenSymbol();
|
|
|
|
this.tokenName = await this.tokenService.getTokenName();
|
|
|
|
}
|
|
|
|
});
|
2020-11-04 13:36:30 +01:00
|
|
|
}
|
|
|
|
|
2021-03-18 10:10:55 +01:00
|
|
|
async viewSender(): Promise<void> {
|
2021-04-28 11:09:51 +02:00
|
|
|
await this.router.navigateByUrl(`/accounts/${strip0x(this.transaction.from)}`);
|
2021-03-10 10:47:01 +01:00
|
|
|
}
|
|
|
|
|
2021-03-18 10:10:55 +01:00
|
|
|
async viewRecipient(): Promise<void> {
|
2021-04-28 11:09:51 +02:00
|
|
|
await this.router.navigateByUrl(`/accounts/${strip0x(this.transaction.to)}`);
|
2021-03-10 10:47:01 +01:00
|
|
|
}
|
2021-03-19 15:40:45 +01:00
|
|
|
|
2021-04-26 12:14:36 +02:00
|
|
|
async viewTrader(): Promise<void> {
|
2021-04-28 11:09:51 +02:00
|
|
|
await this.router.navigateByUrl(`/accounts/${strip0x(this.transaction.trader)}`);
|
2021-04-26 12:14:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-19 15:40:45 +01:00
|
|
|
async reverseTransaction(): Promise<void> {
|
|
|
|
await this.transactionService.transferRequest(
|
|
|
|
this.transaction.token.address,
|
|
|
|
this.transaction.to,
|
|
|
|
this.transaction.from,
|
|
|
|
this.transaction.value
|
|
|
|
);
|
|
|
|
}
|
2021-04-26 12:14:36 +02:00
|
|
|
|
|
|
|
copyAddress(address: string): void {
|
|
|
|
if (copyToClipboard(address)) {
|
|
|
|
this.snackBar.open(address + ' copied successfully!', 'Close', { duration: 3000 });
|
|
|
|
}
|
|
|
|
}
|
2021-05-26 11:21:25 +02:00
|
|
|
|
|
|
|
close(): void {
|
|
|
|
this.transaction = null;
|
|
|
|
this.closeWindow.emit(this.transaction);
|
|
|
|
}
|
2020-11-04 13:36:30 +01:00
|
|
|
}
|