import { Component } from '@angular/core' ; import { AlertController , App , IonicPage , LoadingController , NavController , NavParams } from 'ionic-angular' ; import { InAppBrowser } from '@ionic-native/in-app-browser' ; import { TranslateService } from '@ngx-translate/core' ; import { Wallet } from '../../providers/providers' ; @ IonicPage ( ) @ Component ( { selector : 'page-more' , templateUrl : 'more.html' , } ) export class MorePage { public isShowingAnnouncement : boolean = false ; public secretCounter : number = 0 ; constructor ( public alertCtrl , public app , public iab , public loadingCtrl , public navCtrl , public navParams , public translate , public wallet ) { } pushAddressesPage ( ) { this . navCtrl . push ( 'AddressesPage' ) ; } pushXpubPage ( ) { this . navCtrl . push ( 'XpubPage' ) ; } async promptForWIF ( ) { let wifAlert = this . alertCtrl . create ( { enableBackdropDismiss : false , cssClass : 'promptForWIFCSSClass' , title : 'WIF' , inputs : [ { name : 'wif' , type : 'password' } ] , buttons : [ { text : this . translate . instant ( 'CANCEL' ) } , { text : this . translate . instant ( 'OK' ) , handler : ( data ) => { let wif = data . wif ; let encrypted = false ; let isValid = false ; if ( ! wif ) { } else if ( this . wallet . validateWIF ( wif ) ) { isValid = true ; } else if ( this . wallet . validateEncryptedWIF ( wif ) ) { isValid = true ; encrypted = true ; } if ( isValid ) { wifAlert . dismiss ( ) . then ( ( ) => { this . navCtrl . push ( 'SweepPage' , { encrypted : encrypted , wif : wif } ) ; } ) ; } else { this . alertCtrl . create ( { enableBackdropDismiss : false , title : this . translate . instant ( 'ERROR' ) , buttons : [ this . translate . instant ( 'OK' ) ] } ) . present ( ) ; } return false ; } } ] } ) ; await wifAlert . present ( ) . then ( ( ) => { Array . from ( window . document . querySelectorAll ( '.promptForWIFCSSClass input' ) ) . forEach ( ( el ) => { el . setAttribute ( 'type' , 'text' ) ; el . setAttribute ( 'autocomplete' , 'off' ) ; el . setAttribute ( 'autocorrect' , 'off' ) ; } ) ; } ) ; } async showWRP ( ) { try { let m = await this . wallet . authorize ( ) ; let o = this . wallet . parseRecoveryString ( m ) ; let message ; if ( o . xprv ) { message = 'Account XPRV:<br>' + o . xprv ; } else { message = this . translate . instant ( 'RECOVERY_PHRASE' ) + ':<br>' + o . mnemonic + '<br><br>' ; if ( o . passphrase ) { o . passphrase = o . passphrase . replace ( /&/g , "&amp;" ) . replace ( /</g , "&lt;" ) . replace ( />/g , "&gt;" ) ; message += this . translate . instant ( 'RECOVERY_PASSPHRASE' ) + ':<br>' + o . passphrase + '<br><br>' ; } message += this . translate . instant ( 'DERIVATION_PATH' ) + ':<br>' + o . path ; } await this . alertCtrl . create ( { enableBackdropDismiss : false , title : this . translate . instant ( 'BACKUP_WALLET' ) , message : message , buttons : [ this . translate . instant ( 'OK' ) ] } ) . present ( ) ; } catch ( err ) { if ( err . message !== 'cancelled' ) { console . log ( err ) ; } } } async renameCurrentWallet ( ) { let walletName = this . wallet . getCurrentWalletName ( ) ; let renameAlert = this . alertCtrl . create ( { enableBackdropDismiss : false , title : this . translate . instant ( 'RENAME_WALLET' ) , inputs : [ { name : 'name' , value : walletName } ] , buttons : [ { text : this . translate . instant ( 'CANCEL' ) } , { text : this . translate . instant ( 'OK' ) , handler : data => { if ( walletName === data . name ) { return ; } if ( data . name && this . nameIsValid ( data . name ) ) { renameAlert . dismiss ( ) . then ( ( ) => { return this . wallet . renameWallet ( walletName , data . name ) ; } ) . catch ( ( err ) => { console . log ( err ) ; } ) ; } return false ; } } ] } ) ; await renameAlert . present ( ) ; } nameIsValid ( name ) { if ( this . wallet . getAllWalletNames ( ) . indexOf ( name ) !== - 1 ) { this . alertCtrl . create ( { enableBackdropDismiss : false , title : this . translate . instant ( 'ERROR' ) , message : this . translate . instant ( 'ERR_INVALID_WALLET_NAME' ) , buttons : [ this . translate . instant ( 'OK' ) ] } ) . present ( ) ; return false ; } else { return true ; } } async deleteCurrentWallet ( ) { try { await this . confirmDelete ( ) ; await this . wallet . deleteWallet ( this . wallet . getCurrentWalletName ( ) ) ; await this . navCtrl . popToRoot ( ) ; } catch ( err ) { if ( err . message !== 'cancelled' ) { console . log ( err ) ; } } } confirmDelete ( ) { return new Promise ( ( resolve , reject ) => { let confirmDeleteAlert = this . alertCtrl . create ( { enableBackdropDismiss : true , title : this . translate . instant ( 'WARN_DELETE_WALLET' ) , buttons : [ { role : 'cancel' , text : this . translate . instant ( 'CANCEL' ) , handler : data => { confirmDeleteAlert . dismiss ( ) . then ( ( ) => { reject ( new Error ( 'cancelled' ) ) ; } ) ; return false ; } } , { cssClass : 'confirmDeleteBtnCSSClass' , text : this . translate . instant ( 'DELETE' ) + '(5)' , handler : data => { confirmDeleteAlert . dismiss ( ) . then ( ( ) => { resolve ( ) ; } ) ; return false ; } } ] } ) ; confirmDeleteAlert . present ( ) . then ( ( ) => { let btn = window . document . querySelector ( '.confirmDeleteBtnCSSClass' ) ; let btnSpan = btn . querySelector ( 'span' ) ; btn . setAttribute ( 'disabled' , '' ) ; let text = this . translate . instant ( 'DELETE' ) ; let counter = 4 ; let timer = window . setInterval ( ( ) => { if ( counter > 0 ) { btnSpan . innerText = text + '(' + counter + ')' ; } else { window . clearInterval ( timer ) ; btnSpan . innerText = text ; btnSpan . setAttribute ( 'style' , 'color: red;' ) ; btn . removeAttribute ( 'disabled' ) ; } counter -- ; } , 1000 ) ; } ) ; } ) ; } async promptForNonCompliantRecovery ( ) { if ( this . secretCounter < 6 ) { this . secretCounter ++ ; return ; } await this . wallet . promptForRecovery ( undefined , false ) ; } async showColdWalletTutorial ( ) { await this . alertCtrl . create ( { enableBackdropDismiss : false , title : this . translate . instant ( 'COLD_WALLET_TUTORIAL' ) , message : this . translate . instant ( 'COLD_WALLET_TUTORIAL_CONTENT' ) , buttons : [ this . translate . instant ( 'OK' ) ] } ) . present ( ) ; } async showAnnouncement ( ) { if ( this . isShowingAnnouncement ) { return ; } this . isShowingAnnouncement = true ; await this . wallet . showAnnouncement ( true ) ; this . isShowingAnnouncement = false ; } async showDisclaimer ( ) { await this . alertCtrl . create ( { enableBackdropDismiss : false , title : this . translate . instant ( 'DISCLAIMER' ) , message : this . translate . instant ( 'DISCLAIMER_CONTENT' ) , buttons : [ this . translate . instant ( 'OK' ) ] } ) . present ( ) ; } launchTwitter ( ) { this . iab . create ( 'https://twitter.com/simplycashapp' , '_system' ) ; } launchTelegram ( ) { this . iab . create ( 'https://t.me/simplycashgroup' , '_system' ) ; } }