From 14b554d0989944df2640c011385fd43d5b1c9bda Mon Sep 17 00:00:00 2001 From: Andrew Vivash Date: Thu, 5 Jan 2023 12:24:51 -0800 Subject: [PATCH] Avivash/update old username format in init (#106) --- src/lib/init.ts | 13 +++++++++++-- src/routes/delegate-account/+page.svelte | 3 ++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/lib/init.ts b/src/lib/init.ts index 1b543b6..4889e35 100644 --- a/src/lib/init.ts +++ b/src/lib/init.ts @@ -3,7 +3,7 @@ import * as webnative from 'webnative' import { dev } from '$app/environment' import { filesystemStore, sessionStore } from '../stores' import { getBackupStatus, type BackupStatus } from '$lib/auth/backup' -import { USERNAME_STORAGE_KEY } from '$lib/auth/account' +import { USERNAME_STORAGE_KEY, createDID } from '$lib/auth/account' import { webnativeNamespace } from '$lib/app-info' export const initialize = async (): Promise => { @@ -19,7 +19,16 @@ export const initialize = async (): Promise => { // Authed backupStatus = await getBackupStatus(program.session.fs) - const fullUsername = await program.components.storage.getItem(USERNAME_STORAGE_KEY) as string + let fullUsername = await program.components.storage.getItem(USERNAME_STORAGE_KEY) as string + + // If the user is migrating from a version webnative-app-template before https://github.com/webnative-examples/webnative-app-template/pull/97/files#diff-a180510e798b8f833ebfdbe691c5ec4a1095076980d3e2388de29c849b2b8361R44, + // their username won't contain a did, so we will need to manually append a DID and add it storage here + if (!fullUsername) { + const did = await createDID(program.components.crypto) + fullUsername = `${program.session.username}#${did}` + await program.components.storage.setItem(USERNAME_STORAGE_KEY, fullUsername) + window.location.reload() + } sessionStore.set({ username: { diff --git a/src/routes/delegate-account/+page.svelte b/src/routes/delegate-account/+page.svelte index 75eef84..f808192 100644 --- a/src/routes/delegate-account/+page.svelte +++ b/src/routes/delegate-account/+page.svelte @@ -56,7 +56,8 @@ $themeStore.selectedTheme === 'light' ? '#FAFAFA' : '#171717', padding: 0, width: 250, - height: 250 + height: 250, + join: true }).svg() initAccountLinkingProducer(hashedUsername)