import { Component } from '@angular/core' ; import * as bip39 from 'bip39' ; import { MnemonicSecret } from '../../models/secret' ; import { DeviceService } from '../../services/device/device.service' ; import { ErrorCategory , handleErrorLocal } from '../../services/error-handler/error-handler.service' ; import { NavigationService } from '../../services/navigation/navigation.service' ; import { SecretsService } from '../../services/secrets/secrets.service' ; @ Component ( { selector : 'airgap-social-recovery-setup' , templateUrl : './social-recovery-setup.page.html' , styleUrls : [ './social-recovery-setup.page.scss' ] } ) export class SocialRecoverySetupPage { public numberOfShares : number = 3 ; public numberOfRequiredShares : number = 2 ; private readonly secret : MnemonicSecret ; constructor ( private readonly secretService , private readonly deviceService , private readonly navigationService ) { this . secret = this . navigationService . getState ( ) . secret ; } public ionViewDidEnter ( ) { this . deviceService . setSecureWindow ( ) ; } public ionViewWillLeave ( ) { this . deviceService . clearSecureWindow ( ) ; } public setNumberOfShares ( i ) { this . numberOfShares = i ; if ( this . numberOfRequiredShares > this . numberOfShares ) { this . numberOfRequiredShares = this . numberOfShares ; } } public setNumberOfRequiredShares ( i ) { this . numberOfRequiredShares = i ; } public back ( ) { this . navigationService . back ( ) ; } public next ( ) { this . secretService . retrieveEntropyForSecret ( this . secret ) . then ( ( entropy ) => { const shares = MnemonicSecret . generateSocialRecover ( bip39 . entropyToMnemonic ( entropy ) , this . numberOfShares , this . numberOfRequiredShares ) ; this . navigationService . routeWithState ( '/social-recovery-show-share' , { shares , currentShare : 0 , secret : this . secret } ) . catch ( handleErrorLocal ( ErrorCategory . IONIC_NAVIGATION ) ) ; } ) . catch ( ( error ) => { console . warn ( error ) ; } ) ; } }