From 1bdd18adb4f342194f3fbb51a63baa9cb9eb0706 Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Thu, 2 Mar 2023 18:55:50 -0500 Subject: [PATCH] Start working on unifying interface --- web-frontend/package.json | 5 +- web-frontend/src/lib/AddressInput.svelte | 35 +++++++++++++ web-frontend/src/lib/common.js | 30 +++++++++-- web-frontend/src/routes/+layout.svelte | 5 +- web-frontend/src/routes/decode/+page.svelte | 49 ++++++++++++++++++ web-frontend/src/routes/encode/+page.svelte | 57 +++++++++++++-------- web-frontend/yarn.lock | 12 +++++ 7 files changed, 166 insertions(+), 27 deletions(-) create mode 100644 web-frontend/src/lib/AddressInput.svelte diff --git a/web-frontend/package.json b/web-frontend/package.json index 6afbeda..5cc5dad 100644 --- a/web-frontend/package.json +++ b/web-frontend/package.json @@ -31,5 +31,8 @@ "vite-plugin-pwa": "^0.14.4", "vite-plugin-wasm-pack": "^0.1.12" }, - "type": "module" + "type": "module", + "dependencies": { + "svelecte": "^4.0.0-alpha.7" + } } diff --git a/web-frontend/src/lib/AddressInput.svelte b/web-frontend/src/lib/AddressInput.svelte new file mode 100644 index 0000000..6117cc5 --- /dev/null +++ b/web-frontend/src/lib/AddressInput.svelte @@ -0,0 +1,35 @@ + + + +
+ + +
diff --git a/web-frontend/src/lib/common.js b/web-frontend/src/lib/common.js index 2694b7d..7ecc046 100644 --- a/web-frontend/src/lib/common.js +++ b/web-frontend/src/lib/common.js @@ -1,5 +1,29 @@ +import init, { address_from_lat_lon } from 'xpin-wasm'; +import * as xpinWasm from 'xpin-wasm'; + export const WasmStatus = { - NotLoaded: 0, - Loaded: 1, - Errored: 2 + NotLoaded: -1, + Loaded: 0, + Errored: 1 }; + +export async function getWasm() { + let wasmStatus = WasmStatus.NotLoaded; + let wasmError; + + await init() + .then(() => { + wasmStatus = WasmStatus.Loaded; + }) + .catch((e) => { + console.error('Error loading wasm module', e); + wasmError = e; + wasmStatus = WasmStatus.Errored; + }); + + return { + status: wasmStatus, + error: wasmError, + call: xpinWasm + }; +} diff --git a/web-frontend/src/routes/+layout.svelte b/web-frontend/src/routes/+layout.svelte index 4356678..dd748ec 100644 --- a/web-frontend/src/routes/+layout.svelte +++ b/web-frontend/src/routes/+layout.svelte @@ -37,7 +37,10 @@ > Encode - + Decode diff --git a/web-frontend/src/routes/decode/+page.svelte b/web-frontend/src/routes/decode/+page.svelte index eb28667..eecd672 100644 --- a/web-frontend/src/routes/decode/+page.svelte +++ b/web-frontend/src/routes/decode/+page.svelte @@ -1,4 +1,53 @@

Decode

+ +

Status: {wasm.status}

+

WasmError: {wasm.error}

+

OutputValue: {outputValue}

+

Input value: {inputValue}

+ + + + diff --git a/web-frontend/src/routes/encode/+page.svelte b/web-frontend/src/routes/encode/+page.svelte index 427f2fe..e44049c 100644 --- a/web-frontend/src/routes/encode/+page.svelte +++ b/web-frontend/src/routes/encode/+page.svelte @@ -1,8 +1,10 @@

Encode

-{#if wasmStatus == WasmStatus.Loaded || wasmStatus == WasmStatus.NotLoaded} +

{outputValue}

+{#if wasm.status == WasmStatus.Loaded || wasm.status == WasmStatus.NotLoaded}

Current cursor: {addr} => ({latlng.lat}, {latlng.lng})

+ + -{:else if wasmStatus == WasmStatus.Errored} +{:else if wasm.status == WasmStatus.Errored}