import { Component } from '@angular/core' ; import { AlertController , PopoverController } from '@ionic/angular' ; import { TranslateService } from '@ngx-translate/core' ; import { AirGapWallet } from '@airgap/coinlib-core' ; import { first } from 'rxjs/operators' ; import { ClipboardService } from '@airgap/angular-core' ; import { ErrorCategory , handleErrorLocal } from '../../../services/error-handler/error-handler.service' ; import { SecretsService } from '../../../services/secrets/secrets.service' ; import { NavigationService } from 'src/app/services/navigation/navigation.service' ; @ Component ( { selector : 'airgap-account-edit-popover' , templateUrl : 'account-edit-popover.component.html' , styleUrls : [ './account-edit-popover.component.scss' ] } ) export class AccountEditPopoverComponent { public readonly wallet : AirGapWallet ; private readonly onDelete : Function ; private readonly getWalletShareUrl : ( ) => Promise < string > ; constructor ( private readonly alertCtrl , private readonly clipboardService , private readonly secretsService , private readonly popoverController , private readonly translateService , private readonly navigationService ) { } public async copyAddressToClipboard ( ) { await this . clipboardService . copyAndShowToast ( this . wallet . receivingPublicAddress , this . translateService . instant ( 'wallet-edit-delete-popover.confirm_address_copy' ) ) ; await this . popoverController . dismiss ( ) ; } public async copyShareUrlToClipboard ( ) { await this . clipboardService . copyAndShowToast ( await this . getWalletShareUrl ( ) , this . translateService . instant ( 'wallet-edit-delete-popover.confirm_sync_code_copy' ) ) ; await this . popoverController . dismiss ( ) ; } public async openAddressExplorer ( ) { this . navigationService . routeWithState ( '/address-explorer' , { wallet : this . wallet } ) ; await this . popoverController . dismiss ( ) ; } public delete ( ) { this . translateService . get ( [ 'wallet-edit-delete-popover.account-removal_alert.title' , 'wallet-edit-delete-popover.account-removal_alert.text' , 'wallet-edit-delete-popover.account-removal_alert.cancel_label' , 'wallet-edit-delete-popover.account-removal_alert.delete_label' ] ) . pipe ( first ( ) ) . subscribe ( async ( values ) => { const title = values [ 'wallet-edit-delete-popover.account-removal_alert.title' ] ; const message = values [ 'wallet-edit-delete-popover.account-removal_alert.text' ] ; const cancelButton = values [ 'wallet-edit-delete-popover.account-removal_alert.cancel_label' ] ; const deleteButton = values [ 'wallet-edit-delete-popover.account-removal_alert.delete_label' ] ; const alert = await this . alertCtrl . create ( { header : title , message , buttons : [ { text : cancelButton , role : 'cancel' , handler : ( ) : void => { this . popoverController . dismiss ( ) . catch ( handleErrorLocal ( ErrorCategory . IONIC_ALERT ) ) ; } } , { text : deleteButton , handler : ( ) : void => { alert . present ( ) . catch ( handleErrorLocal ( ErrorCategory . IONIC_ALERT ) ) ; this . secretsService . removeWallet ( this . wallet ) . then ( ( ) => { this . popoverController . dismiss ( ) . catch ( handleErrorLocal ( ErrorCategory . IONIC_ALERT ) ) ; if ( this . onDelete ) { this . onDelete ( ) ; } } ) . catch ( handleErrorLocal ( ErrorCategory . SECURE_STORAGE ) ) ; } } ] } ) ; alert . present ( ) . catch ( handleErrorLocal ( ErrorCategory . IONIC_ALERT ) ) ; } ) ; } }