import { Component } from '@angular/core' ; import { AlertController , IonicPage , NavController , NavParams , ViewController } from 'ionic-angular' ; import { TranslateService } from '@ngx-translate/core' ; import { Wallet } from '../../providers/providers' ; @ IonicPage ( ) @ Component ( { selector : 'page-contacts' , templateUrl : 'contacts.html' , } ) export class ContactsPage { public contacts : string [ ] ; constructor ( public alertCtrl , public navCtrl , public navParams , public viewCtrl , public translate , public wallet ) { this . contacts = this . wallet . getContacts ( ) ; } selectContact ( contact ) { let cb = this . navParams . get ( 'cb' ) ; cb ( contact ) ; this . viewCtrl . dismiss ( ) ; } async deleteContact ( contact ) { let confirm = await new Promise ( ( resolve , reject ) => { let ans = false ; let deleteContactAlert = this . alertCtrl . create ( { enableBackdropDismiss : true , title : this . translate . instant ( 'DELETE' ) , message : contact , buttons : [ { role : 'cancel' , text : this . translate . instant ( 'CANCEL' ) } , { text : this . translate . instant ( 'OK' ) , handler : ( ) => { ans = true ; } } ] } ) ; deleteContactAlert . onDidDismiss ( ( ) => { resolve ( ans ) ; } ) ; deleteContactAlert . present ( ) ; } ) ; if ( ! confirm ) { return ; } await this . wallet . removeContact ( contact ) ; this . contacts = this . wallet . getContacts ( ) ; } }