diff --git a/src/frontend/src/btc/schedulers/btc-wallet.scheduler.ts b/src/frontend/src/btc/schedulers/btc-wallet.scheduler.ts index 17a396c3d9..c7bff73ecd 100644 --- a/src/frontend/src/btc/schedulers/btc-wallet.scheduler.ts +++ b/src/frontend/src/btc/schedulers/btc-wallet.scheduler.ts @@ -1,11 +1,12 @@ import { getBtcBalance } from '$lib/api/signer.api'; import { WALLET_TIMER_INTERVAL_MILLIS } from '$lib/constants/app.constants'; import { SchedulerTimer, type Scheduler, type SchedulerJobData } from '$lib/schedulers/scheduler'; +import type { BitcoinTransaction } from '$lib/types/blockchain'; import type { PostMessageDataRequestBtc, - PostMessageDataResponseBtcWallet + PostMessageDataResponseWallet } from '$lib/types/post-message'; -import { assertNonNullish } from '@dfinity/utils'; +import { assertNonNullish, jsonReplacer } from '@dfinity/utils'; export class BtcWalletScheduler implements Scheduler { private timer = new SchedulerTimer('syncBtcWalletStatus'); @@ -44,18 +45,22 @@ export class BtcWalletScheduler implements Scheduler network: bitcoinNetwork }); + // TODO: Fetch and parse transactions + const transactions: BitcoinTransaction[] = []; + this.postMessageWallet({ wallet: { balance: { data: balance, certified: true - } + }, + newTransactions: JSON.stringify(transactions, jsonReplacer) } }); }; - 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; }