From 34d90330b72c7b4541135ee995f0510d6db6e20a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren?= Date: Thu, 23 Nov 2023 11:30:49 -0600 Subject: [PATCH] Avoid using 1.0 Nimiq lib for transaction handling --- public/index.html | 14 ++++---- src/lib/BufferUtils.ts | 15 +++++++++ src/lib/NetworkClient.ts | 15 +++------ src/views/SignStakingSuccess.vue | 50 ++++++++++++++++------------ src/views/SignTransactionSuccess.vue | 43 ++++++++++++++++-------- 5 files changed, 85 insertions(+), 52 deletions(-) create mode 100644 src/lib/BufferUtils.ts diff --git a/public/index.html b/public/index.html index 5ddf43bd..5eb74fe5 100644 --- a/public/index.html +++ b/public/index.html @@ -23,14 +23,16 @@ diff --git a/src/lib/BufferUtils.ts b/src/lib/BufferUtils.ts new file mode 100644 index 00000000..a16d0ed0 --- /dev/null +++ b/src/lib/BufferUtils.ts @@ -0,0 +1,15 @@ +export function hexToBytes(hex: string) { + return new Uint8Array((hex.match(/.{2}/g) || []).map(byte => parseInt(byte, 16))); +} + +export function bytesToHex(bytes: Uint8Array) { + const HEX_ALPHABET = '0123456789abcdef'; + + let hex = ''; + for (let i = 0; i < bytes.length; i++) { + const code = bytes[i]; + hex += HEX_ALPHABET[code >>> 4]; + hex += HEX_ALPHABET[code & 0x0F]; + } + return hex; +} diff --git a/src/lib/NetworkClient.ts b/src/lib/NetworkClient.ts index 9c311526..3371acb0 100644 --- a/src/lib/NetworkClient.ts +++ b/src/lib/NetworkClient.ts @@ -1,16 +1,9 @@ -import type { - Client as AlbatrossClient, - ClientConfiguration as AlbatrossClientConfiguration, - PlainVestingContract, -} from '@nimiq/albatross-wasm'; +import type * as Nimiq from '@nimiq/albatross-wasm'; import Config from 'config'; declare global { interface Window { - loadAlbatross: () => Promise<{ - Client: typeof AlbatrossClient, - ClientConfiguration: typeof AlbatrossClientConfiguration, - }>; + loadAlbatross: () => Promise; } } @@ -22,7 +15,7 @@ export class NetworkClient { return this._instance; } - private _clientPromise?: Promise; + private _clientPromise?: Promise; // constructor() {} @@ -62,7 +55,7 @@ export class NetworkClient { } public async getGenesisVestingContracts() { - return [] as Array; // TODO + return [] as Array; // TODO } public get innerClient() { diff --git a/src/views/SignStakingSuccess.vue b/src/views/SignStakingSuccess.vue index d350a579..2047f6b4 100644 --- a/src/views/SignStakingSuccess.vue +++ b/src/views/SignStakingSuccess.vue @@ -1,35 +1,43 @@ - -