Skip to content

Commit

Permalink
added contact form to onboarding
Browse files Browse the repository at this point in the history
  • Loading branch information
silkroadnomad committed Mar 16, 2024
1 parent 66e96c6 commit b7c5f72
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 28 deletions.
7 changes: 4 additions & 3 deletions src/lib/components/ContactForm.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<script>
import { selectedAddr, orbitdb } from "../../stores.js";
import {addContact, deleteContact, updateContact} from "../../operations.js";
import {Button, Checkbox, Column, Dropdown, Grid, Row, TextInput} from "carbon-components-svelte";
import { addContact, deleteContact, updateContact } from "../../operations.js";
import { Button, Checkbox, Column, Dropdown, Grid, Row, TextInput } from "carbon-components-svelte";
export let isOnBoarding = false
</script>

<section>
Expand Down Expand Up @@ -56,7 +57,7 @@
<Button data-cy="deleteContact" size="sm" on:click={() => deleteContact()}>Delete</Button>

{:else}
<Button data-cy="addContact" size="sm" on:click={() => addContact()}>Add</Button>
<Button data-cy="addContact" size="sm" on:click={() => addContact(isOnBoarding)}>Add</Button>
{/if}
</Column>
</Row>
Expand Down
19 changes: 11 additions & 8 deletions src/lib/components/OnBoarding.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,21 @@
}
</script>
<div class="content">
<li>loading did: {$did} </li>
<li>
{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
</li>
<ContactForm/>
{#if !scannedContact}
<li>loading did: {$did} </li>
{:else}
<li>
{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
</li>
{/if}
<ContactForm isOnBoarding={true}/>
</div>
<style>
:global(.content) {
margin: 3rem;
}
</style>
17 changes: 11 additions & 6 deletions src/operations.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {notify, sha256} from "./utils/utils.js";

import {
myAddressBook,
selectedAddr,
Expand All @@ -10,8 +9,7 @@ import {
myDal,
dbMyAddressBook, followList
} from "./stores.js";


import {goto} from "$app/navigation";

/**
* Loading a contact from memory into the contactForm
Expand All @@ -33,13 +31,20 @@ export async function loadContact(id) {
* At the end we switch back to ContactList Tab
* @returns {Promise<void>}
*/
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}`);
}

Expand Down
14 changes: 5 additions & 9 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@
}
onMount(async ()=>{
await confirmExperimentalUse();
await handleSeedphrase();
if($hash!=='/onboarding'){
await confirmExperimentalUse();
await handleSeedphrase();
}
await handleSeedphrase(true);
await startNetwork();
})
Expand Down Expand Up @@ -74,13 +77,6 @@
<ConnectionSignal title="Swarm connected" class="statusGreen" />&nbsp;{$connectedPeers}
{/if}
</div>
<!-- <div class="flags">
{#if $synced===true}
<WatsonHealthAiStatusComplete title="Storage Protocol synced messages" class="statusGreen"/>&nbsp;{$recordsSynced.length | 0}
{:else}
<WatsonHealthAiStatus title="Storage Protocol syncing..." class="statusYellow" />&nbsp;{$recordsSynced.length | 0}
{/if}
</div>-->
</HeaderNav>

<HeaderUtilities>
Expand Down
10 changes: 8 additions & 2 deletions src/routes/handleSeedphrase.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ seedPhrase.subscribe((val) => {
*
* @returns {Promise<void>}
*/
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. " +
Expand All @@ -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)
}

0 comments on commit b7c5f72

Please sign in to comment.