-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2001 from dusk-network/feature-1975
explorer: Fixed app failing to load on Safari
- Loading branch information
Showing
15 changed files
with
195 additions
and
296 deletions.
There are no files selected for viewing
80 changes: 0 additions & 80 deletions
80
explorer/src/lib/dusk/storage/__tests__/createStorage.spec.js
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
40
explorer/src/lib/market-data/__tests__/MarketDataInfo.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as MarketDataInfo } from "./MarketDataInfo"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 0 additions & 57 deletions
57
explorer/src/lib/services/__tests__/marketDataStorage.spec.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.