Skip to content

Commit f925ee7

Browse files
authored
Merge da8c8f2 into 0247bda
2 parents 0247bda + da8c8f2 commit f925ee7

File tree

12 files changed

+543
-132
lines changed

12 files changed

+543
-132
lines changed

.changeset/silent-masks-dance.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"ledger-live-desktop": minor
3+
---
4+
5+
Adds MSW to LLD for MAD/DADA development

apps/ledger-live-desktop/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ pnpm i
5353
pnpm dev:lld
5454
```
5555

56+
```bash
57+
# launch the app in dev mode with MSW
58+
pnpm dev:lld:msw
59+
```
60+
5661
## Watch deps
5762

5863
In another terminal and in parallel to `pnpm dev:lld`, you can watch different libs from the monorepo

apps/ledger-live-desktop/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"scripts": {
1818
"start:prod": "electron ./.webpack/main.bundle.js",
1919
"start": "cross-env NODE_ENV=development node ./tools/main.js",
20+
"start:msw": "cross-env NODE_ENV=development ENABLE_MSW=true node ./tools/main.js",
2021
"build": "cross-env CSC_IDENTITY_AUTO_DISCOVERY=false STAGING=1 node ./tools/dist --nosign -v",
2122
"build:js": "cross-env NODE_ENV=production node ./tools/main.js build",
2223
"build:testing": "cross-env NODE_ENV=production TESTING=1 node ./tools/main.js build",
@@ -114,7 +115,6 @@
114115
"json-rpc-2.0": "0.2.19",
115116
"jsqr": "1.4.0",
116117
"lodash": "4.17.21",
117-
"msw": "2.3.4",
118118
"prando": "5.1.2",
119119
"prop-types": "15.8.1",
120120
"qrcode": "1.5.3",
@@ -228,6 +228,7 @@
228228
"jest-environment-jsdom": "29.7.0",
229229
"listr": "0.14.3",
230230
"listr-verbose-renderer": "0.6.0",
231+
"msw": "2.3.4",
231232
"nock": "13.5.4",
232233
"prebuild-install": "7.1.2",
233234
"react-refresh": "0.14.0",
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { setupWorker } from "msw/browser";
2+
import { http, HttpResponse } from "msw";
3+
import { mockAssets } from "./dada/mockAssets";
4+
5+
const handlers = [
6+
http.get("https://dada.api.ledger-test.com/v1/assets", () => {
7+
return HttpResponse.json(mockAssets);
8+
}),
9+
];
10+
11+
const mswWorker = setupWorker(...handlers);
12+
13+
export const startWorker = () =>
14+
mswWorker.start({
15+
onUnhandledRequest: "bypass",
16+
});
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
export const mockAssets = {
2+
cryptoAssets: {
3+
bitcoin: {
4+
id: "bitcoin",
5+
ticker: "BTC",
6+
name: "Bitcoin",
7+
assetsIds: {
8+
bitcoin: "bitcoin",
9+
},
10+
},
11+
},
12+
networks: {
13+
bitcoin: {
14+
id: "bitcoin",
15+
name: "Bitcoin",
16+
ticker: "BTC",
17+
},
18+
},
19+
cryptoOrTokenCurrencies: {
20+
bitcoin: {
21+
type: "crypto_currency",
22+
id: "bitcoin",
23+
name: "Bitcoin",
24+
ticker: "BTC",
25+
units: [
26+
{
27+
code: "sat",
28+
name: "satoshi",
29+
magnitude: 0,
30+
},
31+
{
32+
code: "bit",
33+
name: "bit",
34+
magnitude: 2,
35+
},
36+
{
37+
code: "mBTC",
38+
name: "mBTC",
39+
magnitude: 5,
40+
},
41+
{
42+
code: "BTC",
43+
name: "bitcoin",
44+
magnitude: 8,
45+
},
46+
],
47+
chainId: null,
48+
confirmationsNeeded: 6,
49+
symbol: "Ƀ",
50+
coinType: 0,
51+
family: "bitcoin",
52+
hasSegwit: false,
53+
hasTokens: false,
54+
hrp: null,
55+
disableCountervalue: false,
56+
},
57+
},
58+
interestRates: {},
59+
markets: {
60+
bitcoin: {
61+
currencyId: "bitcoin",
62+
marketCap: 2311255367617,
63+
fullyDilutedValuation: 2311255367617,
64+
totalVolume: 37329002918,
65+
high24h: 117596,
66+
low24h: 115979,
67+
price: 116155,
68+
priceChange24h: -495.931735560574,
69+
priceChangePercentage1h: -0.123056529685568,
70+
priceChangePercentage24h: -0.425143016739924,
71+
priceChangePercentage7d: 0.604189220603407,
72+
priceChangePercentage30d: 6.49600225510015,
73+
priceChangePercentage1y: 95.3416888544017,
74+
marketCapChange24h: -9795454917.64356,
75+
marketCapChangePercentage24h: -0.42203,
76+
circulatingSupply: 19903696,
77+
totalSupply: 19903696,
78+
allTimeHigh: 122838,
79+
allTimeLow: 67.81,
80+
allTimeHighDate: "2025-07-14T07:56:01.937Z",
81+
allTimeLowDate: "2013-07-06T00:00:00Z",
82+
sparkline: [
83+
115457.055, 113789.06, 113069.94, 113673.75, 113655.07, 113556.14, 113019.516, 112296.38,
84+
112869.4, 113457.52, 113567.17, 113912.57, 113782.64, 114347.945, 114319.44, 114776.26,
85+
114449.12, 114292.16, 114761.914, 114928.08, 115291.22, 114717.484, 114149.64, 114783.83,
86+
112866.555, 113385.8, 113954.92, 113604.5, 114083.75, 114036.836, 114949.54, 115487.57,
87+
115132.55, 114559.35, 114733.26, 116385.94, 116351.84, 116575.81, 117596.49, 116755.37,
88+
116691.76, 116600.516,
89+
],
90+
fetchAt: "2025-08-11T12:21:27.696160Z",
91+
},
92+
},
93+
currenciesOrder: {
94+
key: "marketCap",
95+
order: "desc",
96+
currenciesIds: ["bitcoin"],
97+
metaCurrencyIds: ["bitcoin"],
98+
},
99+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
async function enableMocking() {
2+
const mswEnabled = process.env.ENABLE_MSW === "true";
3+
4+
if (mswEnabled) {
5+
try {
6+
const { startWorker } = await import("~/mocks/browser");
7+
8+
await startWorker();
9+
} catch (error) {
10+
console.error("MSW: Failed to start Mock Service Worker:", error);
11+
}
12+
return;
13+
}
14+
15+
const registrations = await navigator.serviceWorker.getRegistrations();
16+
const mswRegistrations = registrations.filter(registration =>
17+
registration.active?.scriptURL.includes("mockServiceWorker"),
18+
);
19+
await Promise.all(
20+
mswRegistrations.map(async registration => {
21+
await registration.unregister();
22+
}),
23+
);
24+
}
25+
26+
enableMocking();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import "./pre";
22
import "~/renderer/env";
33
import "~/renderer/experimental"; // NB we need to load this first because it loads things from process.env and will setEnv properly at boot
4+
import "~/mocks/init"; // Initialize MSW (Mock Service Worker) for API mocking
45
import "~/renderer/init";

0 commit comments

Comments
 (0)