import { Component , OnInit } from '@angular/core' ; import { AlertController } from '@ionic/angular' ; import { TranslateService } from '@ngx-translate/core' ; import { NavigationService } from 'src/app/services/navigation/navigation.service' ; import { SecureStorageService } from 'src/app/services/secure-storage/secure-storage.service' ; import { VaultStorageService } from 'src/app/services/storage/storage.service' ; @ Component ( { selector : 'airgap-danger-zone' , templateUrl : './danger-zone.page.html' , styleUrls : [ './danger-zone.page.scss' ] } ) export class DangerZonePage implements OnInit { constructor ( private readonly alertCtrl , private readonly translateService , public readonly storageService , private readonly secureStorage , private readonly navigationService ) { } ngOnInit ( ) { } async resetVault ( ) { const alert = await this . alertCtrl . create ( { header : this . translateService . instant ( 'danger-zone.wipe.alert.title' ) , message : this . translateService . instant ( 'danger-zone.wipe.alert.message' ) , buttons : [ { text : this . translateService . instant ( 'danger-zone.wipe.alert.cancel' ) , role : 'cancel' } , { text : this . translateService . instant ( 'danger-zone.wipe.alert.ok' ) , handler : async ( ) => { try { await this . secureStorage . wipe ( ) ; await this . storageService . wipe ( ) ; } catch ( e ) { console . error ( 'Wiping failed' , e ) ; return this . resetVaultError ( ) ; } this . navigationService . route ( '/' ) . then ( ( ) => { location . reload ( ) ; } ) ; } } ] } ) ; alert . present ( ) ; } async resetVaultError ( ) { const alert = await this . alertCtrl . create ( { header : this . translateService . instant ( 'danger-zone.wipe-error.alert.title' ) , message : this . translateService . instant ( 'danger-zone.wipe-error.alert.message' ) , buttons : [ { text : this . translateService . instant ( 'danger-zone.wipe-error.alert.ok' ) } ] } ) ; alert . present ( ) ; } }