From 54a9afd2610e2f8c1dcb4d8ad41fa5fd6994cfbc Mon Sep 17 00:00:00 2001 From: DenysKarmazynDFINITY Date: Thu, 26 Sep 2024 19:13:23 +0200 Subject: [PATCH] feat(frontend): use PostMessageDataResponseWallet for BTC wallet --- .../src/btc/schedulers/btc-wallet.scheduler.ts | 10 ++++++---- src/frontend/src/btc/services/btc-listener.services.ts | 4 ++-- .../src/btc/services/worker.btc-wallet.services.ts | 8 +++----- src/frontend/src/lib/types/post-message.ts | 9 ++------- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/frontend/src/btc/schedulers/btc-wallet.scheduler.ts b/src/frontend/src/btc/schedulers/btc-wallet.scheduler.ts index 17a396c3d9..2b4a943d02 100644 --- a/src/frontend/src/btc/schedulers/btc-wallet.scheduler.ts +++ b/src/frontend/src/btc/schedulers/btc-wallet.scheduler.ts @@ -3,7 +3,7 @@ import { WALLET_TIMER_INTERVAL_MILLIS } from '$lib/constants/app.constants'; import { SchedulerTimer, type Scheduler, type SchedulerJobData } from '$lib/schedulers/scheduler'; import type { PostMessageDataRequestBtc, - PostMessageDataResponseBtcWallet + PostMessageDataResponseWallet } from '$lib/types/post-message'; import { assertNonNullish } from '@dfinity/utils'; @@ -49,13 +49,15 @@ export class BtcWalletScheduler implements Scheduler balance: { data: balance, certified: true - } + }, + // TODO: Send parsed transactions + newTransactions: '' } }); }; - private postMessageWallet(data: PostMessageDataResponseBtcWallet) { - this.timer.postMsg({ + private postMessageWallet(data: PostMessageDataResponseWallet) { + this.timer.postMsg({ msg: 'syncBtcWallet', data }); diff --git a/src/frontend/src/btc/services/btc-listener.services.ts b/src/frontend/src/btc/services/btc-listener.services.ts index 8ed48bcc6c..072437ed36 100644 --- a/src/frontend/src/btc/services/btc-listener.services.ts +++ b/src/frontend/src/btc/services/btc-listener.services.ts @@ -1,5 +1,5 @@ import { balancesStore } from '$lib/stores/balances.store'; -import type { PostMessageDataResponseBtcWallet } from '$lib/types/post-message'; +import type { PostMessageDataResponseWallet } from '$lib/types/post-message'; import type { TokenId } from '$lib/types/token'; import { BigNumber } from '@ethersproject/bignumber'; @@ -7,7 +7,7 @@ export const syncWallet = ({ data, tokenId }: { - data: PostMessageDataResponseBtcWallet; + data: PostMessageDataResponseWallet; tokenId: TokenId; }) => { const { diff --git a/src/frontend/src/btc/services/worker.btc-wallet.services.ts b/src/frontend/src/btc/services/worker.btc-wallet.services.ts index c69e9b42b1..9ecf44fd53 100644 --- a/src/frontend/src/btc/services/worker.btc-wallet.services.ts +++ b/src/frontend/src/btc/services/worker.btc-wallet.services.ts @@ -1,7 +1,7 @@ import { syncWallet } from '$btc/services/btc-listener.services'; import { isNetworkIdBTCRegtest, isNetworkIdBTCTestnet } from '$icp/utils/ic-send.utils'; import type { WalletWorker } from '$lib/types/listener'; -import type { PostMessage, PostMessageDataResponseBtcWallet } from '$lib/types/post-message'; +import type { PostMessage, PostMessageDataResponseWallet } from '$lib/types/post-message'; import type { Token } from '$lib/types/token'; import { mapToSignerBitcoinNetwork } from '$lib/utils/network.utils'; @@ -12,16 +12,14 @@ export const initBtcWalletWorker = async ({ const WalletWorker = await import('$btc/workers/btc-wallet.worker?worker'); const worker: Worker = new WalletWorker.default(); - worker.onmessage = async ({ - data - }: MessageEvent>) => { + worker.onmessage = async ({ data }: MessageEvent>) => { const { msg } = data; switch (msg) { case 'syncBtcWallet': syncWallet({ tokenId, - data: data.data as PostMessageDataResponseBtcWallet + data: data.data as PostMessageDataResponseWallet }); return; } diff --git a/src/frontend/src/lib/types/post-message.ts b/src/frontend/src/lib/types/post-message.ts index 46fffe37dc..557bd36c9c 100644 --- a/src/frontend/src/lib/types/post-message.ts +++ b/src/frontend/src/lib/types/post-message.ts @@ -107,20 +107,15 @@ export interface PostMessageDataResponseExchangeError extends PostMessageDataRes // Transactions & {certified: boolean} type JsonTransactionsText = string; -type PostMessageWalletData = Omit & { +type PostMessageWalletData = Omit & { balance: CertifiedData; newTransactions: JsonTransactionsText; }; -export interface PostMessageDataResponseWallet extends PostMessageDataResponse { +export interface PostMessageDataResponseWallet extends PostMessageDataResponse { wallet: PostMessageWalletData; } -// TODO: use common PostMessageDataResponseWallet interface after BTC transactions added to the worker -export interface PostMessageDataResponseBtcWallet extends PostMessageDataResponse { - wallet: Omit; -} - export interface PostMessageDataResponseError extends PostMessageDataResponse { error: unknown; }