import { Component } from '@angular/core' ; import { AlertController , ToastController } from '@ionic/angular' ; import { Observable } from 'rxjs' ; import { MnemonicSecret } from '../../models/secret' ; import { ErrorCategory , handleErrorLocal } from '../../services/error-handler/error-handler.service' ; import { NavigationService } from '../../services/navigation/navigation.service' ; import { SecretsService } from '../../services/secrets/secrets.service' ; import { ClipboardService , IACMessageTransport , SerializerService } from '@airgap/angular-core' ; import { IACService } from 'src/app/services/iac/iac.service' ; @ Component ( { selector : 'airgap-tab-settings' , templateUrl : './tab-settings.page.html' , styleUrls : [ './tab-settings.page.scss' ] } ) export class TabSettingsPage { public readonly secrets : Observable < MnemonicSecret [ ] > ; constructor ( public readonly serializerService , private readonly secretsService , private readonly alertController , private readonly toastController , private readonly iacService , private readonly clipboardService , private readonly navigationService ) { this . secrets = this . secretsService . getSecretsObservable ( ) ; } public goToNewSecret ( ) { this . navigationService . route ( '/secret-setup' ) . catch ( handleErrorLocal ( ErrorCategory . IONIC_NAVIGATION ) ) ; } public goToEditSecret ( secret ) { this . navigationService . routeWithState ( '/secret-edit' , { secret } ) . catch ( handleErrorLocal ( ErrorCategory . IONIC_NAVIGATION ) ) ; } public goToInteractionSettings ( ) { this . navigationService . route ( '/interaction-selection-settings' ) . catch ( handleErrorLocal ( ErrorCategory . IONIC_NAVIGATION ) ) ; } public goToErrorHistory ( ) { this . navigationService . route ( '/error-history' ) . catch ( handleErrorLocal ( ErrorCategory . IONIC_NAVIGATION ) ) ; } public async deleteSecret ( secret ) { const alert = await this . alertController . create ( { header : 'Delete ' + secret . label , subHeader : 'Are you sure you want to delete ' + secret . label + '?' , buttons : [ { text : 'Delete' , handler : async ( ) => { this . secretsService . remove ( secret ) . catch ( handleErrorLocal ( ErrorCategory . SECURE_STORAGE ) ) ; const toast = await this . toastController . create ( { message : 'Secret deleted' , duration : 5000 , buttons : [ { text : 'Undo' , role : 'cancel' } ] } ) ; toast . onDidDismiss ( ) . then ( ( role ) => { if ( role === 'close' ) { this . secretsService . addOrUpdateSecret ( secret ) . catch ( handleErrorLocal ( ErrorCategory . SECURE_STORAGE ) ) ; } } ) ; toast . present ( ) . catch ( handleErrorLocal ( ErrorCategory . IONIC_ALERT ) ) ; } } , { text : 'Cancel' } ] } ) ; alert . present ( ) . catch ( handleErrorLocal ( ErrorCategory . IONIC_ALERT ) ) ; } public goToAbout ( ) { this . navigationService . route ( '/about' ) . catch ( handleErrorLocal ( ErrorCategory . IONIC_NAVIGATION ) ) ; } public goToInteractionHistory ( ) { this . navigationService . route ( '/interaction-history' ) . catch ( handleErrorLocal ( ErrorCategory . IONIC_NAVIGATION ) ) ; } public goToQrSettings ( ) { this . navigationService . route ( '/qr-settings' ) . catch ( handleErrorLocal ( ErrorCategory . IONIC_NAVIGATION ) ) ; } public goToBip39Wordlist ( ) { this . navigationService . route ( '/wordlist' ) . catch ( handleErrorLocal ( ErrorCategory . IONIC_NAVIGATION ) ) ; } public goToDangerZone ( ) { this . navigationService . route ( '/danger-zone' ) . catch ( handleErrorLocal ( ErrorCategory . IONIC_NAVIGATION ) ) ; } public pasteClipboard ( ) { this . clipboardService . paste ( ) . then ( ( text ) => { console . log ( 'pasteClipboard' , text ) ; this . iacService . handleRequest ( text , IACMessageTransport . PASTE ) . catch ( ( err ) => console . error ( err ) ) ; } , ( err ) => { console . error ( 'Error: ' + err ) ; } ) ; } }