import { Component } from '@angular/core' ; import { AlertController , PopoverController } from '@ionic/angular' ; import { TranslateService } from '@ngx-translate/core' ; import { first } from 'rxjs/operators' ; import { MnemonicSecret } from '../../../models/secret' ; import { ErrorCategory , handleErrorLocal } from '../../../services/error-handler/error-handler.service' ; import { SecretsService } from '../../../services/secrets/secrets.service' ; @ Component ( { selector : 'airgap-secret-edit-popover' , templateUrl : './secret-edit-popover.component.html' , styleUrls : [ './secret-edit-popover.component.scss' ] } ) export class SecretEditPopoverComponent { private readonly secret : MnemonicSecret ; private readonly onDelete : Function ; constructor ( private readonly alertCtrl , private readonly secretsService , private readonly popoverController , private readonly translateService ) { } public delete ( ) { this . translateService . get ( [ 'secret-edit-delete-popover.title' , 'secret-edit-delete-popover.text' , 'secret-edit-delete-popover.cancel_label' , 'secret-edit-delete-popover.delete_label' ] ) . pipe ( first ( ) ) . subscribe ( async ( values ) => { const title = values [ 'secret-edit-delete-popover.title' ] ; const message = values [ 'secret-edit-delete-popover.text' ] ; const cancelButton = values [ 'secret-edit-delete-popover.cancel_label' ] ; const deleteButton = values [ 'secret-edit-delete-popover.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_MODAL ) ) ; } } , { text : deleteButton , handler : ( ) : void => { this . secretsService . remove ( this . secret ) . catch ( handleErrorLocal ( ErrorCategory . SECURE_STORAGE ) ) ; this . popoverController . dismiss ( ) . catch ( handleErrorLocal ( ErrorCategory . IONIC_MODAL ) ) ; if ( this . onDelete ) { this . onDelete ( ) ; } } } ] } ) ; alert . present ( ) . catch ( handleErrorLocal ( ErrorCategory . IONIC_ALERT ) ) ; } ) ; } }