Skip to content

Commit d0dd373

Browse files
authored
Add block notification sound selector (#6)
Features: Add block notification sound selector; Design fixes: Bold font for tabs; Other changes; Refactoring; Improve typing; Remove unnecessary comments
1 parent 923d9f5 commit d0dd373

24 files changed

+360
-79
lines changed

package-lock.json

+81-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mempool-space-block-tracker-chrome-extenstion",
3-
"version": "1.0.2",
3+
"version": "1.1.0-beta.2",
44
"description": "Chrome extension to track new bitcoin blocks via Mempool Space",
55
"scripts": {
66
"dev": "webpack --watch --progress --mode=development",
@@ -17,6 +17,7 @@
1717
"author": "Savoskin Ivan",
1818
"license": "MIT",
1919
"dependencies": {
20+
"axios": "1.7.2",
2021
"classnames": "2.5.1",
2122
"react": "18.3.1",
2223
"react-dom": "18.3.1"

public/files/manifest.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
"name": "Bitcoin blocks tracker",
66
"description": "Extension for Bitcoin blocks tracking via Mempool space",
7-
"version": "1.0.2",
8-
"version_name": "1.1.0 alpha 1",
7+
"version": "1.0.1",
8+
"version_name": "1.1.0-beta.2",
99

1010
"icons": {
1111
"16":"icons/16.png",

src/background/index.ts

+30-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { sendMessage } from "@coreUtils/utils";
2-
import { BackgroundMessage, Fees } from "@models/types";
2+
import {
3+
BackgroundMessage,
4+
BlockPopupMessage,
5+
Fees,
6+
FeesPopupMessage,
7+
PlayBlockNotificationSoundOffscreenMessage
8+
} from "@models/types";
39

410
import { getSocketUrl } from "./utils/utils";
511

@@ -13,6 +19,7 @@ let fees: Fees | null;
1319
let lastBlockTime: number | null;
1420
let lastBlockHeight: number | null;
1521
let blockNotificationVolume: number = 100;
22+
let blockNotificationSound: string | null = null;
1623

1724
async function checkOffscreenDocumentExist(): Promise<boolean> {
1825
// Check all windows controlled by the service worker to see if one
@@ -50,8 +57,9 @@ function onOpenSocketHandler(): void {
5057
socket?.send(JSON.stringify({ action: "init" }));
5158
socket?.send(JSON.stringify({ action: "want", data: ["blocks", "stats"] }));
5259

53-
chrome.storage.local.get(["blockNotificationVolume"]).then((result) => {
60+
chrome.storage.local.get(["blockNotificationVolume", "blockNotificationSound"]).then((result) => {
5461
blockNotificationVolume = result.blockNotificationVolume ?? 100;
62+
blockNotificationSound = result.blockNotificationSound;
5563
});
5664
}
5765

@@ -93,15 +101,19 @@ function onBlockMessageHandler(eventData: any): void {
93101
console.info("New block");
94102
setupOffscreenDocument().then(() => {
95103
console.debug("Send block notification method to offscreen");
96-
sendMessage({ data: { volume: blockNotificationVolume }, target: "offscreen", type: "playBlockNotificationSound" });
104+
sendMessage<PlayBlockNotificationSoundOffscreenMessage>({
105+
data: { volume: blockNotificationVolume, sound: blockNotificationSound },
106+
target: "offscreen",
107+
type: "playBlockNotificationSound"
108+
});
97109
});
98110

99111
lastBlockTime = eventData.block.timestamp * 1000;
100112
lastBlockHeight = eventData.block.height;
101113

102114
console.debug("Update blocks info with new block");
103115

104-
sendMessage({
116+
sendMessage<BlockPopupMessage>({
105117
target: "popup",
106118
data: { blockInfo: { lastBlockTime, lastBlockHeight } },
107119
type: "blockInfo"
@@ -116,7 +128,7 @@ function onFeesMessageHandler(eventData: any): void {
116128
if ("fees" in eventData) {
117129
console.debug("Fee updated");
118130
fees = eventData.fees;
119-
sendMessage({ target: "popup", data: { fees }, type: "fees" });
131+
sendMessage<FeesPopupMessage>({ target: "popup", data: { fees }, type: "fees" });
120132

121133
console.info(`Current fees: slow: ${fees?.hourFee}, medium: ${fees?.halfHourFee}, fast: ${fees?.fastestFee}`);
122134
}
@@ -129,7 +141,7 @@ function onBlocksMessageHandler(eventData: any): void {
129141
const lastBlock = eventData.blocks.at(-1);
130142
lastBlockHeight = lastBlock.height;
131143
lastBlockTime = lastBlock.timestamp * 1000;
132-
sendMessage({
144+
sendMessage<BlockPopupMessage>({
133145
target: "popup",
134146
data: { blockInfo: { lastBlockTime, lastBlockHeight } },
135147
type: "blockInfo"
@@ -197,12 +209,12 @@ function disableBlocksTracking(): void {
197209
lastBlockTime = null;
198210
lastBlockHeight = null;
199211

200-
sendMessage({
212+
sendMessage<BlockPopupMessage>({
201213
target: "popup",
202214
data: { blockInfo: { lastBlockTime, lastBlockHeight } },
203215
type: "blockInfo"
204216
});
205-
sendMessage({ target: "popup", data: { fees }, type: "fees" });
217+
sendMessage<FeesPopupMessage>({ target: "popup", data: { fees }, type: "fees" });
206218
}
207219

208220
chrome.storage.local.get(["isTrackingEnabled", "isMainnet"]).then((result) => {
@@ -231,15 +243,15 @@ chrome.runtime.onMessage.addListener((message: BackgroundMessage) => {
231243
}
232244
});
233245

234-
chrome.runtime.onMessage.addListener((message: BackgroundMessage, sender, sendResponse) => {
246+
chrome.runtime.onMessage.addListener((message: BackgroundMessage, _, sendResponse) => {
235247
if (message.target === "background" && message.type === "requestFees") {
236248
console.debug("Send initial fees info");
237249

238250
sendResponse({ target: "popup", data: { fees }, type: "initialFees" });
239251
}
240252
});
241253

242-
chrome.runtime.onMessage.addListener((message: BackgroundMessage, sender, sendResponse) => {
254+
chrome.runtime.onMessage.addListener((message: BackgroundMessage, _, sendResponse) => {
243255
if (message.target === "background" && message.type === "requestLastBlockInfo") {
244256
console.debug("Send initial last block info");
245257

@@ -258,3 +270,11 @@ chrome.runtime.onMessage.addListener((message: BackgroundMessage) => {
258270
blockNotificationVolume = message.data.volume;
259271
}
260272
});
273+
274+
chrome.runtime.onMessage.addListener((message: BackgroundMessage) => {
275+
if (message.target === "background" && message.type === "changeBlockNotificationSound") {
276+
console.debug("Change block notification sound");
277+
278+
blockNotificationSound = message.data.sound;
279+
}
280+
});

src/models/types.ts

+15-5
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,33 @@ export interface RequestLastBlockInfoBackgroundMessage extends Message {
2323
type: "requestLastBlockInfo";
2424
}
2525

26-
export interface ChangeBlockNotificationSoundVolumeOffscreenMessage extends Message {
26+
export interface ChangeBlockNotificationSoundVolumeBackgroundMessage extends Message {
2727
data: {
2828
volume: number;
2929
};
3030
target: "background";
3131
type: "changeBlockNotificationSoundVolume";
3232
}
3333

34+
export interface ChangeBlockNotificationSoundBackgroundMessage extends Message {
35+
data: {
36+
sound: string | null;
37+
};
38+
target: "background";
39+
type: "changeBlockNotificationSound";
40+
}
41+
3442
export type BackgroundMessage =
3543
| BaseBackgroundMessage
3644
| RequestFeesBackgroundMessage
3745
| RequestLastBlockInfoBackgroundMessage
38-
| ChangeBlockNotificationSoundVolumeOffscreenMessage;
46+
| ChangeBlockNotificationSoundVolumeBackgroundMessage
47+
| ChangeBlockNotificationSoundBackgroundMessage;
3948

4049
export interface PlayBlockNotificationSoundOffscreenMessage extends Message {
4150
data: {
4251
volume: number;
52+
sound: string | null;
4353
};
4454
target: "offscreen";
4555
type: "playBlockNotificationSound";
@@ -49,7 +59,7 @@ export type OffscreenMessage = PlayBlockNotificationSoundOffscreenMessage;
4959

5060
export interface FeesPopupMessage extends Message {
5161
data: {
52-
fees: Fees;
62+
fees: Fees | null;
5363
};
5464
target: "popup";
5565
type: "fees" | "initialFees";
@@ -74,6 +84,6 @@ export interface Fees {
7484
}
7585

7686
export interface BlockInfo {
77-
lastBlockHeight: number;
78-
lastBlockTime: number;
87+
lastBlockHeight: number | null;
88+
lastBlockTime: number | null;
7989
}

src/offScreen/index.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@ import notification from "@static/sounds/notification.m4a";
33

44
console.debug("Initialize offscreen");
55

6-
const sound = new Audio(notification);
7-
86
chrome.runtime.onMessage.addListener((message: OffscreenMessage) => {
97
if (message.target === "offscreen" && message.type === "playBlockNotificationSound") {
8+
const sound = new Audio(message.data.sound ?? notification);
9+
1010
console.debug("Play block notification sound");
1111
sound.volume = message.data.volume / 100;
12-
console.log(sound);
13-
console.log(message.data.volume, message.data.volume / 100);
14-
console.log(sound.volume);
1512
sound.play();
1613
}
1714
});

src/popup/components/Main/ChangeBlockchainRadioButtonGroup.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { sendMessage } from "@coreUtils/utils";
2+
import { BaseBackgroundMessage } from "@models/types";
23

34
import mainStyles from "./styles/Main.module.scss";
45
import styles from "./styles/RadioButtons.module.scss";
@@ -16,7 +17,7 @@ export default function ChangeBlockchainRadioButtonGroup({
1617
}: Readonly<TrackingRadioButtonGroupProps>) {
1718
const changeBlockchain = (_isMainnet: boolean) => {
1819
setIsMainnet(_isMainnet);
19-
sendMessage({
20+
sendMessage<BaseBackgroundMessage>({
2021
target: "background",
2122
data: {
2223
enabled: isTrackingEnabled,

0 commit comments

Comments
 (0)