Skip to content

Commit

Permalink
Merge pull request #2001 from dusk-network/feature-1975
Browse files Browse the repository at this point in the history
explorer: Fixed app failing to load on Safari
  • Loading branch information
ascartabelli authored Jul 23, 2024
2 parents 6a2b047 + 8a345ec commit 1fd314e
Show file tree
Hide file tree
Showing 15 changed files with 195 additions and 296 deletions.
80 changes: 0 additions & 80 deletions explorer/src/lib/dusk/storage/__tests__/createStorage.spec.js

This file was deleted.

31 changes: 0 additions & 31 deletions explorer/src/lib/dusk/storage/createStorage.js

This file was deleted.

1 change: 0 additions & 1 deletion explorer/src/lib/dusk/storage/index.js

This file was deleted.

12 changes: 0 additions & 12 deletions explorer/src/lib/dusk/storage/storage.d.ts

This file was deleted.

53 changes: 53 additions & 0 deletions explorer/src/lib/market-data/MarketDataInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { compose, updateKey } from "lamb";

/** @returns {MarketData} */
const jsonToMarketData = compose(
updateKey("lastUpdate", (v) => new Date(v)),
JSON.parse
);

class MarketDataInfo {
/** @type {MarketData} */
#data;

/** @type {Date} */
#lastUpdate;

/** @param {string} json */
static parse(json) {
const { data, lastUpdate } = jsonToMarketData(json);

return new MarketDataInfo(data, lastUpdate);
}

/**
*
* @param {MarketData} data
* @param {Date} lastUpdate
*/
constructor(data, lastUpdate) {
this.#data = data;
this.#lastUpdate = lastUpdate;
}

get data() {
return this.#data;
}

get lastUpdate() {
return this.#lastUpdate;
}

toJSON() {
return JSON.stringify(this.toStorageData());
}

toStorageData() {
return {
data: this.#data,
lastUpdate: this.#lastUpdate,
};
}
}

export default MarketDataInfo;
40 changes: 40 additions & 0 deletions explorer/src/lib/market-data/__tests__/MarketDataInfo.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { describe, expect, it } from "vitest";

import { MarketDataInfo } from "..";

describe("MarketDataInfo", () => {
const marketData = {
currentPrice: {},
marketCap: {},
};
const now = new Date();
const marketDataInfo = new MarketDataInfo(marketData, now);

it("should expose the market data and the last update as read-only props", () => {
expect(() => {
// @ts-expect-error
marketDataInfo.data = {};
}).toThrow();

expect(() => {
// @ts-expect-error
marketDataInfo.lastUpdate = new Date(2010, 3, 4);
}).toThrow();

expect(marketDataInfo.data).toStrictEqual(marketData);
expect(marketDataInfo.lastUpdate).toBe(now);
});

it("should expose a method to convert the instance to JSON and a static method to parse it", () => {
const newMarketDataInfo = MarketDataInfo.parse(marketDataInfo.toJSON());

expect(newMarketDataInfo).toStrictEqual(marketDataInfo);
});

it("should expose a method to convert the data to the format used for storage", () => {
expect(marketDataInfo.toStorageData()).toStrictEqual({
data: marketData,
lastUpdate: now,
});
});
});
1 change: 1 addition & 0 deletions explorer/src/lib/market-data/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as MarketDataInfo } from "./MarketDataInfo";
5 changes: 5 additions & 0 deletions explorer/src/lib/market-data/market-data.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ type MarketData = {
currentPrice: Record<string, number>;
marketCap: Record<string, number>;
};

type MarketDataStorage = {
data: MarketData;
lastUpdate: Date;
};
57 changes: 0 additions & 57 deletions explorer/src/lib/services/__tests__/marketDataStorage.spec.js

This file was deleted.

1 change: 0 additions & 1 deletion explorer/src/lib/services/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export { default as duskAPI } from "./duskAPI";
export { default as marketDataStorage } from "./marketDataStorage";
46 changes: 0 additions & 46 deletions explorer/src/lib/services/marketDataStorage.js

This file was deleted.

4 changes: 0 additions & 4 deletions explorer/src/lib/services/services.d.ts

This file was deleted.

Loading

0 comments on commit 1fd314e

Please sign in to comment.