Browse Source

Show loading indicator while publishing public key

Carsten Porth 5 years ago
parent
commit
2e2b8f1cc1
1 changed files with 24 additions and 7 deletions
  1. 24 7
      app/src/pages/settings/settings.ts

+ 24 - 7
app/src/pages/settings/settings.ts

@@ -1,5 +1,9 @@
 import { Component } from "@angular/core";
-import { NavController, ToastController } from "ionic-angular";
+import {
+  NavController,
+  ToastController,
+  LoadingController
+} from "ionic-angular";
 import { Storage } from "@ionic/storage";
 import { CryptoProvider } from "../../providers/crypto/crypto";
 
@@ -16,7 +20,8 @@ export class SettingsPage {
     public navCtrl: NavController,
     public toastCtrl: ToastController,
     private cryptoUtils: CryptoProvider,
-    private storage: Storage
+    private storage: Storage,
+    private loadingCtrl: LoadingController
   ) {
     this.loadValuesFromStorage();
   }
@@ -39,15 +44,27 @@ export class SettingsPage {
     this.storage.set("privateKey", this.privateKey);
     this.storage.set("keywords", this.keywords);
 
+    this.showToast("Successfully saved!");
+  }
+
+  async publishPublicKey() {
+    if (this.publicKey.length) {
+      const loading = this.loadingCtrl.create();
+      loading.present();
+
+      await this.cryptoUtils.publishPublicKey(this.publicKey);
+
+      loading.dismiss();
+      this.showToast("Public key has been published!");
+    }
+  }
+
+  private showToast(message: string) {
     const toast = this.toastCtrl.create({
-      message: "Successfully saved!",
+      message: message,
       position: "bottom",
       duration: 3000
     });
     toast.present();
   }
-
-  publishPublicKey() {
-    this.cryptoUtils.publishPublicKey(this.publicKey);
-  }
 }