From 4dc7e8c6d6f24dd050227c5d2752fe66ce1e0da7 Mon Sep 17 00:00:00 2001 From: Brian Ginsburg Date: Mon, 29 Aug 2022 08:51:49 -0700 Subject: [PATCH 1/3] Upgrade webnative to 0.34.1 --- package-lock.json | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 717bc25..736d557 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "dependencies": { "clipboard-copy": "^4.0.1", "qrcode-svg": "^1.1.0", - "webnative": "0.34.0" + "webnative": "0.34.1" }, "devDependencies": { "@sveltejs/adapter-static": "1.0.0-next.36", @@ -5501,9 +5501,9 @@ } }, "node_modules/webnative": { - "version": "0.34.0", - "resolved": "https://registry.npmjs.org/webnative/-/webnative-0.34.0.tgz", - "integrity": "sha512-BS5pgHx9+sIzZ3NYA9Q76QQOctHFuyZ9p/LC4U4+gWTjycj0efWl0Z2jlsaUyGfqBkFLReyDeTb3ldHkD2PgbA==", + "version": "0.34.1", + "resolved": "https://registry.npmjs.org/webnative/-/webnative-0.34.1.tgz", + "integrity": "sha512-FCY00dBUUHWEdabkLV3INTxnkNVlRQfmiNfe4M+Pg85rppLTHP0WU/MAbPHan5NMdH2j09KPeFmxLD2qbqszHQ==", "dependencies": { "@ipld/dag-cbor": "^7.0.2", "@ipld/dag-pb": "^2.1.17", @@ -9506,9 +9506,9 @@ "peer": true }, "webnative": { - "version": "0.34.0", - "resolved": "https://registry.npmjs.org/webnative/-/webnative-0.34.0.tgz", - "integrity": "sha512-BS5pgHx9+sIzZ3NYA9Q76QQOctHFuyZ9p/LC4U4+gWTjycj0efWl0Z2jlsaUyGfqBkFLReyDeTb3ldHkD2PgbA==", + "version": "0.34.1", + "resolved": "https://registry.npmjs.org/webnative/-/webnative-0.34.1.tgz", + "integrity": "sha512-FCY00dBUUHWEdabkLV3INTxnkNVlRQfmiNfe4M+Pg85rppLTHP0WU/MAbPHan5NMdH2j09KPeFmxLD2qbqszHQ==", "requires": { "@ipld/dag-cbor": "^7.0.2", "@ipld/dag-pb": "^2.1.17", diff --git a/package.json b/package.json index f5f81a3..1294345 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,6 @@ "dependencies": { "clipboard-copy": "^4.0.1", "qrcode-svg": "^1.1.0", - "webnative": "0.34.0" + "webnative": "0.34.1" } } From 837613ca54fc9267ca6e7715962721eaf63e5058 Mon Sep 17 00:00:00 2001 From: Brian Ginsburg Date: Mon, 29 Aug 2022 08:52:27 -0700 Subject: [PATCH 2/3] Wait for data root before loading filesystem --- src/lib/common/webnative.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/lib/common/webnative.ts b/src/lib/common/webnative.ts index 08e8d77..5563990 100644 --- a/src/lib/common/webnative.ts +++ b/src/lib/common/webnative.ts @@ -106,6 +106,8 @@ export const register = async (username: string): Promise => { } export const loadAccount = async (username: string): Promise => { + await checkDataRoot(username) + const fs = await webnative.loadRootFileSystem() filesystemStore.set(fs) @@ -115,3 +117,28 @@ export const loadAccount = async (username: string): Promise => { authed: true })) } + +const checkDataRoot = async (username: string): Promise => { + let dataRoot = await webnative.dataRoot.lookup(username) + + if (dataRoot) return + + return new Promise((resolve) => { + const maxRetries = 20 + let attempt = 0 + + const dataRootInterval = setInterval(async () => { + console.warn('Could not fetch filesystem data root. Retrying.') + + dataRoot = await webnative.dataRoot.lookup(username) + + if (!dataRoot && attempt < maxRetries) { + attempt++ + return + } + + clearInterval(dataRootInterval) + resolve() + }, 500) + }) +} \ No newline at end of file From d9fe786ccc79f10a70b06f23dac1fe0a45a6c636 Mon Sep 17 00:00:00 2001 From: Brian Ginsburg Date: Mon, 29 Aug 2022 08:53:07 -0700 Subject: [PATCH 3/3] Add loading filesystem modal --- src/components/auth/link/LinkDevice.svelte | 76 ++++++++++++++-------- 1 file changed, 49 insertions(+), 27 deletions(-) diff --git a/src/components/auth/link/LinkDevice.svelte b/src/components/auth/link/LinkDevice.svelte index 02c0b78..fab91da 100644 --- a/src/components/auth/link/LinkDevice.svelte +++ b/src/components/auth/link/LinkDevice.svelte @@ -2,10 +2,11 @@ import { goto } from '$app/navigation' import { page } from '$app/stores' - import { appName } from '$lib/app-name' import { createAccountLinkingConsumer } from '$lib/auth/linking' import { loadAccount } from '$lib/common/webnative' + let loadingFilesystem = false + let displayPin: string = '' let url = $page.url const username = url.searchParams.get('username') @@ -23,6 +24,8 @@ accountLinkingConsumer.on('link', async ({ approved, username }) => { if (approved) { + loadingFilesystem = true + await loadAccount(username) goto('/') // Send up a toast on '/' @@ -34,35 +37,54 @@ -