Browse Source

- remove redundant imports

- add timeouts to the TS' functons that interact with blockchain and key exchange server
develop
Kyrylo Stepanov 2 years ago
parent
commit
8f5a585cc0
1 changed files with 27 additions and 16 deletions
  1. 27
    16
      example/src/index.ts

+ 27
- 16
example/src/index.ts View File

@@ -1,8 +1,8 @@
1 1
 import "../assets/style.scss";
2 2
 import * as _ from "lodash";
3
-import { connect, Contract, WalletConnection, utils, providers, keyStores, ConnectConfig, Near } from 'near-api-js';
3
+import { connect, WalletConnection, keyStores, Near } from 'near-api-js';
4 4
 import { BrowserLocalStorageKeyStore } from "near-api-js/lib/key_stores";
5
-const { KeyProvisioner, ApiError, ErrorType, ProvisionerConfig } = await import("../../pkg/web_client");
5
+const { KeyProvisioner, ErrorType, ProvisionerConfig } = await import("../../pkg/web_client");
6 6
 
7 7
 async function ui() {
8 8
     let keyStore = new keyStores.BrowserLocalStorageKeyStore();
@@ -54,38 +54,49 @@ async function handle_wallet(wallet_connection: WalletConnection, near_connectio
54 54
     console.log("KeyPair: ", keypair.getPublicKey().toString());
55 55
     console.log("Account: ", account);
56 56
 
57
+    let timeout_ms: number = 7000;
58
+    // increase timeout to allow a moderator to add a user
59
+    let interaction_timeout_ms: number = 30000;
60
+
57 61
     document.getElementById("start_meeting_id").addEventListener("click", () => {
58 62
         let participants = (document.getElementById("inp_participants") as HTMLInputElement | null)?.value;
59 63
         if (participants.length > 0) {
60 64
             console.log("Participants: " + participants);
61
-            provisioner.init(new Set(participants.split(","))).then((id) => {
62
-                (document.getElementById("meeting_id_label") as HTMLSpanElement).textContent = id;
63
-                console.log("Meeting Id:", id);
64
-                provisioner.send_keys(id).then((secret_key) => {
65
-                    (document.getElementById("secret_id_label") as HTMLSpanElement).textContent = secret_key;
66
-                    console.log("Secret Key" + secret_key);
67
-                }).catch((err) => {
65
+            provisioner.init(new Set(participants.split(",")), timeout_ms)
66
+                .then((id: string) => {
67
+                    (document.getElementById("meeting_id_label") as HTMLSpanElement).textContent = id;
68
+                    console.log("Meeting Id:", id);
69
+                    provisioner.send_keys(id, interaction_timeout_ms)
70
+                        .then((secret_key) => {
71
+                            (document.getElementById("secret_id_label") as HTMLSpanElement).textContent = secret_key;
72
+                            console.log("Secret Key" + secret_key);
73
+                        })
74
+                        .then(() => console.log("Send keys is ok"))
75
+                        .catch((err) => {
76
+                            console.log("Error: " + err.err_msg());
77
+                        });
78
+                })
79
+                .then(() => console.log("Init is ok"))
80
+                .catch((err) => {
81
+                    console.log("ErrorType: " + ErrorType[err.err_type()]);
68 82
                     console.log("Error: " + err.err_msg());
69 83
                 });
70
-            }).catch((err) => {
71
-                console.log("ErrorType: " + ErrorType[err.err_type()]);
72
-                console.log("Error: " + err.err_msg());
73
-            });
74 84
         }
75 85
     });
76 86
 
77 87
     document.getElementById("join_meeting_id").addEventListener("click", () => {
78 88
         let meeting_id = (document.getElementById("inp_meeting_id") as HTMLInputElement | null)?.value;
79 89
         if (meeting_id.length > 0) {
80
-            provisioner.push_to_near(meeting_id).then((id) => {
81
-                provisioner.get_key(meeting_id).then((secret_key) => {
90
+            provisioner.push_to_near(meeting_id, timeout_ms).then((_id) => {
91
+                provisioner.get_key(meeting_id, timeout_ms).then((secret_key) => {
82 92
                     (document.getElementById("secret_id_label") as HTMLSpanElement).textContent = secret_key;
83 93
                     console.log("Secret Key" + secret_key);
84 94
                 }).catch((err) => {
85 95
                     console.log("ErrorType: " + ErrorType[err.err_type()]);
86 96
                     console.log("Error: " + err.err_msg());
87 97
                 });
88
-            }).catch((err) => {
98
+            })
99
+            .catch((err) => {
89 100
                 console.log("Error: " + err.err_msg());
90 101
             });
91 102
         }

Loading…
Cancel
Save