diff --git a/misc/bin/linux-sh b/misc/bin/linux-sh index 938bccf..7f17fd6 100755 --- a/misc/bin/linux-sh +++ b/misc/bin/linux-sh @@ -2,7 +2,7 @@ if [[ "$1" == *.env ]] then echo "Loading environment file $1..." - if [[ -f "$FILE" ]] + if [[ -f "$1" ]] then export $(cat $1) bash -c "$2" diff --git a/packages/js/shared/web2-common/src/api/http.ts b/packages/js/shared/web2-common/src/api/http.ts index 095e101..6317735 100644 --- a/packages/js/shared/web2-common/src/api/http.ts +++ b/packages/js/shared/web2-common/src/api/http.ts @@ -1,9 +1,9 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import axios, { AxiosResponse } from "axios"; import { getRightOrFail } from "../io-ts-utils"; +import { ApiResponse } from "../types/api-response.type"; import { Logger } from "../utils"; import { HttpInstance } from "./http.types"; -import { ApiResponse } from "../types/api-response.type"; let baseUrl: string | undefined; let jwtToken: string | undefined; @@ -42,5 +42,6 @@ export function setJwtToken(token: string) { } export function setBaseUrl(url: string) { + debug("Base URL set to", url); baseUrl = url; } diff --git a/packages/js/shared/web2-common/src/utils/format-bytes.ts b/packages/js/shared/web2-common/src/utils/format-bytes.ts new file mode 100644 index 0000000..4d65f44 --- /dev/null +++ b/packages/js/shared/web2-common/src/utils/format-bytes.ts @@ -0,0 +1,11 @@ +const units = ["bytes", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"]; + +export function formatBytes(x: number) { + let l = 0, n = x || 0; + + while (n >= 1024 && ++l) { + n = n / 1024; + } + + return (n.toFixed(n < 10 && l > 0 ? 1 : 0) + " " + units[l]); +} diff --git a/packages/js/shared/web2-common/src/utils/index.ts b/packages/js/shared/web2-common/src/utils/index.ts index 60f0017..2bd9087 100644 --- a/packages/js/shared/web2-common/src/utils/index.ts +++ b/packages/js/shared/web2-common/src/utils/index.ts @@ -1,5 +1,6 @@ export * from "./async-action"; export * from "./error"; +export * from "./format-bytes"; export * from "./friendly-error"; export * from "./logger"; export * from "./temporal"; diff --git a/packages/js/web3/frontend/src/App2.tsx b/packages/js/web3/frontend/src/App2.tsx index 645ca1b..40016f6 100644 --- a/packages/js/web3/frontend/src/App2.tsx +++ b/packages/js/web3/frontend/src/App2.tsx @@ -73,12 +73,12 @@ export const AppRoot = observer(function App() { dbService.on("ready", () => setIsDbLoading(false)); }, []); - if (isDbLoading || !hasWalletsListEverLoaded) + /* if (isDbLoading || !hasWalletsListEverLoaded) return ( - ); + ); */ if (!hasWallets && !isWalletsListLoading) return ; diff --git a/packages/js/web3/frontend/src/services/db.service.ts b/packages/js/web3/frontend/src/services/db.service.ts index 55b387c..5cc0f5a 100644 --- a/packages/js/web3/frontend/src/services/db.service.ts +++ b/packages/js/web3/frontend/src/services/db.service.ts @@ -1,4 +1,4 @@ -import { Logger } from "@hdapp/shared/web2-common/utils"; +import { Logger, formatBytes } from "@hdapp/shared/web2-common/utils"; import EventEmitter from "events"; const dbName = "hdapp-pwa-frontend"; @@ -32,7 +32,14 @@ export class DbService { this._consumers.push(consumer); } + private async _calculateStorage() { + const storageSize = await navigator.storage.estimate(); + debug("Using", formatBytes(storageSize.usage ?? -1), "out of", formatBytes(storageSize.quota ?? -1)); + } + private _requestDb() { + void this._calculateStorage(); + debug("Opening IndexedDB"); const request = indexedDB.open(dbName, 3); request.addEventListener( "success", @@ -42,6 +49,12 @@ export class DbService { this._emit("ready"); } ); + request.addEventListener( + "error", + err => { + error("IndexedDB initialization failed.", err); + } + ); request.addEventListener( "upgradeneeded", event => {