From b109111e78790ee10dddbca43f6bfc9f3bf712db Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Sat, 21 May 2022 19:04:55 +0100 Subject: [PATCH] Responsive tables on index and block view --- frontend/package-lock.json | 1 + frontend/package.json | 5 +++-- frontend/src/_table.scss | 7 +++++++ frontend/src/lib/Time.svelte | 34 ++++++++++++++++++++++++++++++++++ frontend/src/lib/bitcoinScript.ts | 2 ++ frontend/src/lib/dayjs.ts | 12 ++++++++++++ frontend/src/routes/__layout.svelte | 8 +++++++- frontend/src/routes/block/[id].svelte | 64 ++++++++++++++++++++++++++++++++++++++++++++-------------------- frontend/src/routes/index.svelte | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------- package-lock.json | 6 ------ web-api/src/methods/block.rs | 22 +++++++++++++--------- 11 files changed, 179 insertions(+), 79 deletions(-) create mode 100644 frontend/src/lib/Time.svelte create mode 100644 frontend/src/lib/dayjs.ts delete mode 100644 package-lock.json diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 2a0987e..c72fc46 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -9,6 +9,7 @@ "version": "0.0.1", "dependencies": { "buffer": "^6.0.3", + "dayjs": "^1.11.2", "svelte-time": "^0.7.0", "sveltekit-i18n": "^2.2.1" }, diff --git a/frontend/package.json b/frontend/package.json index b52575c..d43546e 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -35,7 +35,8 @@ "type": "module", "dependencies": { "buffer": "^6.0.3", - "sveltekit-i18n": "^2.2.1", - "svelte-time": "^0.7.0" + "svelte-time": "^0.7.0", + "dayjs": "^1.11.2", + "sveltekit-i18n": "^2.2.1" } } diff --git a/frontend/src/_table.scss b/frontend/src/_table.scss index f664391..454543f 100644 --- a/frontend/src/_table.scss +++ b/frontend/src/_table.scss @@ -1,3 +1,10 @@ +.table-responsive { + @apply block w-full overflow-x-auto; + + -webkit-overflow-scrolling: touch; + -ms-overflow-style: -ms-autohiding-scrollbar; +} + table { @apply border-collapse table-auto w-full; diff --git a/frontend/src/lib/Time.svelte b/frontend/src/lib/Time.svelte new file mode 100644 index 0000000..3d99465 --- /dev/null +++ b/frontend/src/lib/Time.svelte @@ -0,0 +1,34 @@ + + + diff --git a/frontend/src/lib/bitcoinScript.ts b/frontend/src/lib/bitcoinScript.ts index 8f8adb5..0a73125 100644 --- a/frontend/src/lib/bitcoinScript.ts +++ b/frontend/src/lib/bitcoinScript.ts @@ -20,8 +20,10 @@ export function hexToAsm(hex: string) { } if(byte >= 0x02 && byte <= 0x4b) { + out.push("OP_PUSHBYTES_" + byte); out.push(bytes.slice(i + 1, i + 1 + byte).toString("hex")); i += byte; + continue; } out.push(Operation[byte] || byte.toString(16)) diff --git a/frontend/src/lib/dayjs.ts b/frontend/src/lib/dayjs.ts new file mode 100644 index 0000000..82466c0 --- /dev/null +++ b/frontend/src/lib/dayjs.ts @@ -0,0 +1,12 @@ +import dayjs from "dayjs"; +import relativeTime from "dayjs/plugin/relativeTime.js"; +import localizedFormat from "dayjs/plugin/localizedFormat.js"; + +import 'dayjs/locale/en-gb'; + +dayjs.locale('en-gb'); + +dayjs.extend(relativeTime); +dayjs.extend(localizedFormat); + +export { dayjs }; diff --git a/frontend/src/routes/__layout.svelte b/frontend/src/routes/__layout.svelte index aa16b20..a0aadb4 100644 --- a/frontend/src/routes/__layout.svelte +++ b/frontend/src/routes/__layout.svelte @@ -36,7 +36,9 @@ - +
+ +
diff --git a/frontend/src/routes/block/[id].svelte b/frontend/src/routes/block/[id].svelte index 2daf05f..3d0474b 100644 --- a/frontend/src/routes/block/[id].svelte +++ b/frontend/src/routes/block/[id].svelte @@ -40,10 +40,10 @@

Block {block.height}

-

{block.hash}

+

{block.hash}

-
+
@@ -64,12 +64,12 @@ {#each block.transactions as transaction}
-

+

§ {transaction.hash}

-
+
{#if transaction.coinbase}
@@ -78,33 +78,53 @@ {:else} {#each transaction.inputs as input}
-
- {input.previous_output?.address || briefHexToAsm(input.script).join('\n')} -
- - {#if input.previous_output} -
- {(input.previous_output.value / scale).toFixed(8)} BTC +
+
+ {#if input.previous_output?.address} + + {input.previous_output?.address} + + {:else} + {briefHexToAsm(input.script).join('\n') || 'WITNESS (TODO)'} + {/if}
- {/if} + + {#if input.previous_output} +
+ {(input.previous_output.value / scale).toFixed(8)} BTC +
+ {/if} +
{/each} {/if}
-
+ +
+ ↓ +
+
{#each transaction.outputs as output}
-
- {output.address || briefHexToAsm(output.script).join(' ').trim() || output.script} -
+
+
+ {#if output.address} + + {output.address} + + {:else} + {briefHexToAsm(output.script).join(' ').trim() || output.script} + {/if} +
-
- {(output.value / scale).toFixed(8)} BTC +
+ {(output.value / scale).toFixed(8)} BTC +
{/each} @@ -147,11 +167,11 @@ } .amount { - @apply whitespace-nowrap ml-4; + @apply whitespace-nowrap ml-0 mt-2 md:mt-0 md:ml-4; } div.item { - @apply bg-gray-900/40 p-4 rounded-lg flex mb-2; + @apply bg-gray-900/40 p-4 rounded-lg flex flex mb-2; counter-increment: inout; &:last-of-type { @@ -162,5 +182,9 @@ @apply inline-block w-6 mr-2 select-none text-zinc-500; content: counter(inout); } + + .item-inner { + @apply flex flex-col md:flex-row w-full; + } } diff --git a/frontend/src/routes/index.svelte b/frontend/src/routes/index.svelte index ffe2de5..a4eb572 100644 --- a/frontend/src/routes/index.svelte +++ b/frontend/src/routes/index.svelte @@ -18,11 +18,14 @@