From a29db952e2f5f6fa178af3beb37f201ad855b654 Mon Sep 17 00:00:00 2001 From: Laurin Weger Date: Tue, 9 Jul 2024 13:59:19 +0200 Subject: [PATCH] feat/ng-app: ask for device name svelte part --- ng-app/src/lib/Login.svelte | 37 +++++++++++++++++++++++---- ng-app/src/locales/en.json | 4 +++ ng-app/src/routes/WalletCreate.svelte | 27 ++++++++++++++++++- ng-app/src/store.ts | 2 +- 4 files changed, 63 insertions(+), 7 deletions(-) diff --git a/ng-app/src/lib/Login.svelte b/ng-app/src/lib/Login.svelte index 765df6b..0f7f7fa 100644 --- a/ng-app/src/lib/Login.svelte +++ b/ng-app/src/lib/Login.svelte @@ -27,7 +27,6 @@ Backspace, ArrowPath, LockOpen, - Key, CheckCircle, ArrowLeft, } from "svelte-heros-v2"; @@ -122,6 +121,11 @@ let unlockWith: "pazzle" | "mnemonic" | undefined; + let device_name; + + // TODO: @niko Implement API + // ng.get_device_name().then((name) => (device_name = name)); + function order() { step = "order"; ordered = []; @@ -168,6 +172,7 @@ // open the wallet try { if (tauri_platform) { + // TODO @niko: Add device_name as param to open_with_* APIs let opened_wallet = unlockWith === "pazzle" ? await ng.wallet_open_with_pazzle(wallet, pazzle, pin_code) @@ -191,6 +196,7 @@ wallet: opened_wallet, id: opened_wallet.V0.wallet_id, trusted, + device_name, }); } else { let worker_import = await import("../worker.js?worker&inline"); @@ -211,9 +217,14 @@ //console.log("Message received from worker", msg.data); if (msg.data.loaded) { if (unlockWith === "pazzle") { - myWorker.postMessage({ wallet, pazzle, pin_code }); + myWorker.postMessage({ wallet, pazzle, pin_code, device_name }); } else { - myWorker.postMessage({ wallet, mnemonic_words, pin_code }); + myWorker.postMessage({ + wallet, + mnemonic_words, + pin_code, + device_name, + }); } //console.log("postMessage"); } else if (msg.data.success) { @@ -233,6 +244,7 @@ wallet: msg.data.success, id: msg.data.success.V0.wallet_id, trusted, + device_name, }); } else { console.error(msg.data.error); @@ -387,13 +399,28 @@ {$t("pages.login.trust_device_yes")} - {/if} -
+
+ + {#if for_import} + + + {/if} + {#if !loaded} {$t("pages.login.loading_pazzle")}... diff --git a/ng-app/src/locales/en.json b/ng-app/src/locales/en.json index 5e60d09..630f122 100644 --- a/ng-app/src/locales/en.json +++ b/ng-app/src/locales/en.json @@ -84,6 +84,8 @@ }, "trust_device_allow_cookies": "By selecting this option, you agree to saving some cookies on your browser.", "trust_device_yes": "Yes, save my wallet on this device", + "device_name_label": "Name of device as seen on your other devices", + "device_name_placeholder": "Display name of this device", "loading_pazzle": "Loading Pazzle", "open_with_pazzle": "Open With Pazzle", "login_cancel": "Cancel Login", @@ -191,6 +193,8 @@ "trust": "Do you trust this device?", "trust_description": "If you do, if this device is yours, or it is used by a few trusted persons of your family or workplace, and you would like to login again from this device in the future, then you can save your wallet on this device. To the contrary, if this device is public and shared by strangers, do not save your wallet here.", "trust_toggle": "Save my wallet on this device?", + "device_name_description": "To see which devices you are connected with, every device should have a name (e.g. Bob's laptop). Please enter it here.", + "device_name_placeholder": "Display name of this device", "cloud": "Keep a copy in the cloud?", "cloud_description": "Are you afraid that you will loose the file containing your wallet? If this would happen, your wallet would be lost forever, together with all your documents. We can keep an encrypted copy of your wallet in our cloud. Only you will be able to download it with a special link. You would have to keep this link safely though. By selecting this option, you agree to the", "cloud_toggle": "Save my wallet in the cloud?", diff --git a/ng-app/src/routes/WalletCreate.svelte b/ng-app/src/routes/WalletCreate.svelte index f2628d5..47f392a 100644 --- a/ng-app/src/routes/WalletCreate.svelte +++ b/ng-app/src/routes/WalletCreate.svelte @@ -139,6 +139,11 @@ /** The emojis for the newly created pazzle. */ let pazzle_emojis = []; let confirm_modal_open = false; + let device_name; + + // TODO @niko add API + // ng.get_device_name().then((name) => (device_name = name)); + function scrollToTop() { top.scrollIntoView(); } @@ -254,6 +259,7 @@ core_bootstrap: invitation.V0.bootstrap, core_registration, additional_bootstrap, + device_name, }; //console.log("do wallet with params", params); try { @@ -1424,8 +1430,27 @@ "pages.wallet_create.save_wallet_options.trust_toggle" )} -

+ + {#if options.trusted} +
+

+ {@html $t( + "pages.wallet_create.save_wallet_options.device_name_description" + )} +

+ + {/if}

{@html $t( diff --git a/ng-app/src/store.ts b/ng-app/src/store.ts index fd477dc..67cc08e 100644 --- a/ng-app/src/store.ts +++ b/ng-app/src/store.ts @@ -454,7 +454,7 @@ export const branch_subs = function(nuri) { }; let blob_cache = {}; -export async function get_blob(ref: { nuri: string | number; reference: { key: any; id: any; }; }) { +export async function get_blob(ref: { nuri: string; reference: { key: any; id: any; }; }) { if (!ref) return false; const cached = blob_cache[ref.nuri]; if (cached) {