From b7c5f72ccadc08649eeed73999fd4b72d95a4ad4 Mon Sep 17 00:00:00 2001 From: Nico Krause Date: Sat, 16 Mar 2024 17:33:38 +0800 Subject: [PATCH] added contact form to onboarding --- src/lib/components/ContactForm.svelte | 7 ++++--- src/lib/components/OnBoarding.svelte | 19 +++++++++++-------- src/operations.js | 17 +++++++++++------ src/routes/+layout.svelte | 14 +++++--------- src/routes/handleSeedphrase.js | 10 ++++++++-- 5 files changed, 39 insertions(+), 28 deletions(-) diff --git a/src/lib/components/ContactForm.svelte b/src/lib/components/ContactForm.svelte index 20cfe2e..072e16e 100644 --- a/src/lib/components/ContactForm.svelte +++ b/src/lib/components/ContactForm.svelte @@ -1,7 +1,8 @@
@@ -56,7 +57,7 @@ {:else} - + {/if} diff --git a/src/lib/components/OnBoarding.svelte b/src/lib/components/OnBoarding.svelte index 9429dcb..8c6a63d 100644 --- a/src/lib/components/OnBoarding.svelte +++ b/src/lib/components/OnBoarding.svelte @@ -46,18 +46,21 @@ }
-
  • loading did: {$did}
  • -
  • - {scannedContact && scannedContact.length>0?scannedContact[0].firstName:''} - {scannedContact && scannedContact.length>0?scannedContact[0].lastName:''} added to our address book please - add your name and email -
  • - + {#if !scannedContact} +
  • loading did: {$did}
  • + {:else} +
  • + {scannedContact && scannedContact.length>0?scannedContact[0].firstName:''} + {scannedContact && scannedContact.length>0?scannedContact[0].lastName:''} added to our address book please + add your name and email +
  • + {/if} + +
    \ No newline at end of file diff --git a/src/operations.js b/src/operations.js index 79e44d1..216af96 100644 --- a/src/operations.js +++ b/src/operations.js @@ -1,5 +1,4 @@ import {notify, sha256} from "./utils/utils.js"; - import { myAddressBook, selectedAddr, @@ -10,8 +9,7 @@ import { myDal, dbMyAddressBook, followList } from "./stores.js"; - - +import {goto} from "$app/navigation"; /** * Loading a contact from memory into the contactForm @@ -33,13 +31,20 @@ export async function loadContact(id) { * At the end we switch back to ContactList Tab * @returns {Promise} */ -export async function addContact() { +export async function addContact(isOnBoarding) { + console.log("isOnBoarding",isOnBoarding) _selectedAddr.owner = _orbitdb?.identity?.id _selectedAddr.sharedAddress = _dbMyAddressBook?.address _selectedAddr._id = await sha256(JSON.stringify(_selectedAddr)) //TODO this hash is staying so far until the end of life const hash = await _dbMyAddressBook.put(_selectedAddr) - selectedAddr.set({}) - selectedTab.set(0) + if(!isOnBoarding){ + selectedAddr.set({}) + selectedTab.set(0) + } + else{ + console.log("going to root now") + goto("/") + } notify(`Contact added successfully to ipfs/orbitdb! ${hash}`); } diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 478bfc2..f79e7c8 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -36,8 +36,11 @@ } onMount(async ()=>{ - await confirmExperimentalUse(); - await handleSeedphrase(); + if($hash!=='/onboarding'){ + await confirmExperimentalUse(); + await handleSeedphrase(); + } + await handleSeedphrase(true); await startNetwork(); }) @@ -74,13 +77,6 @@  {$connectedPeers} {/if} - diff --git a/src/routes/handleSeedphrase.js b/src/routes/handleSeedphrase.js index 77148c2..52febd0 100644 --- a/src/routes/handleSeedphrase.js +++ b/src/routes/handleSeedphrase.js @@ -20,9 +20,9 @@ seedPhrase.subscribe((val) => { * * @returns {Promise} */ -export const handleSeedphrase = async () => { +export const handleSeedphrase = async (skip) => { - if(!localStorage.getItem("seedPhrase")) { + if(!localStorage.getItem("seedPhrase") && !skip) { const result = await generateSeed({ data: { text: "We couldn't find a master seed phrase inside your browser storage. " + @@ -42,6 +42,12 @@ export const handleSeedphrase = async () => { break; } } + + if(skip){ //we are in onboarding mode + _seedPhrase = generateMnemonic(); + seedPhrase.set(_seedPhrase) + localStorage.setItem("seedPhrase",_seedPhrase) + } _masterSeed = generateMasterSeed(_seedPhrase,"password") masterSeed.set(_masterSeed) }