import { isPlatformBrowser } from '@angular/common' ; import { Component , Inject , OnInit , PLATFORM_ID } from '@angular/core' ; import { BehaviorSubject } from 'rxjs' ; import { WalletOnchainTransfersSummaryService } from './onchain-transfers.service' ; import { Withdrawal } from './onchain-transfers.types' ; /**
 * Displays a summary of a users withdrawals
 */ @ Component ( { selector : 'm-walletTransactions--onchainTransfers' , templateUrl : 'onchain-transfers.component.html' , styleUrls : [ './onchain-transfers.component.ng.scss' ] , } ) export class WalletOnchainTransfersSummaryComponent implements OnInit { public readonly withdrawals$ : BehaviorSubject < Withdrawal [ ] > = new BehaviorSubject < Withdrawal [ ] > ( [ ] ) ; public readonly inProgress$ : BehaviorSubject < boolean > = new BehaviorSubject < boolean > ( true ) ; public pagingToken : string = '' ; constructor ( private service , @ Inject ( PLATFORM_ID ) private platformId ) { } ngOnInit ( ) { this . load ( ) ; } returns { Promise < void > } public async load ( ) { this . inProgress$ . next ( true ) ; try { const response = await this . service . getWithdrawals$ ( this . pagingToken ) . toPromise ( ) ; if ( response && response . withdrawals ) { this . withdrawals$ . next ( [ ... this . withdrawals$ . getValue ( ) , ... response . withdrawals , ] ) ; } this . pagingToken = response [ 'load-next' ] ; } catch ( e ) { } this . inProgress$ . next ( false ) ; } param { string } txid returns { Promise < void > } public async openExplorer ( txid ) { if ( isPlatformBrowser ( this . platformId ) ) { ( window as any ) . open ( `https://etherscan.com/tx/${ txid }` , '_blank' ) ; } } param { string } address returns { string } public truncateAddress ( address ) { if ( ! address ) { return '' ; } return address . substr ( 0 , 4 ) + '...' + address . substr ( - 4 ) ; } }