002bb3b0f8
- Wallet no longer forces fullscreen on launch - auth and main windows keep the same size and position when switching. - Sign-in and balance loading feel smoother, with less layout jump on the home screen. - Saving a node hostname shows the transaction fee upfront, warns when funds are low, and surfaces clear errors on failure. - Operator unbond confirmation shows pledge plus compounded operator rewards (delegator stake stays separate).
71 lines
1.9 KiB
TypeScript
71 lines
1.9 KiB
TypeScript
import { fetchNymPriceDeduped, clearNymPriceCacheForTests } from './networkOverview';
|
|
|
|
const sampleTokenomics = {
|
|
quotes: {
|
|
USD: {
|
|
price: 0.0331,
|
|
market_cap: 26_000_000,
|
|
volume_24h: 1_200_000,
|
|
},
|
|
},
|
|
};
|
|
|
|
describe('fetchNymPriceDeduped', () => {
|
|
afterEach(() => {
|
|
jest.restoreAllMocks();
|
|
clearNymPriceCacheForTests();
|
|
});
|
|
|
|
it('coalesces concurrent requests for the same URL', async () => {
|
|
let callCount = 0;
|
|
global.fetch = jest.fn(() => {
|
|
callCount += 1;
|
|
return Promise.resolve({
|
|
ok: true,
|
|
json: () => Promise.resolve(sampleTokenomics),
|
|
} as Response);
|
|
});
|
|
|
|
const url = 'https://api.example.test/v1/nym-price';
|
|
const p1 = fetchNymPriceDeduped(url);
|
|
const p2 = fetchNymPriceDeduped(url);
|
|
const [a, b] = await Promise.all([p1, p2]);
|
|
|
|
expect(a).toStrictEqual(sampleTokenomics);
|
|
expect(b).toStrictEqual(sampleTokenomics);
|
|
expect(callCount).toBe(1);
|
|
});
|
|
|
|
it('does not coalesce different URLs', async () => {
|
|
let callCount = 0;
|
|
global.fetch = jest.fn(() => {
|
|
callCount += 1;
|
|
return Promise.resolve({
|
|
ok: true,
|
|
json: () => Promise.resolve(sampleTokenomics),
|
|
} as Response);
|
|
});
|
|
|
|
await Promise.all([fetchNymPriceDeduped('https://a.test/p'), fetchNymPriceDeduped('https://b.test/p')]);
|
|
expect(callCount).toBe(2);
|
|
});
|
|
|
|
it('returns cached result without a second fetch', async () => {
|
|
let callCount = 0;
|
|
global.fetch = jest.fn(() => {
|
|
callCount += 1;
|
|
return Promise.resolve({
|
|
ok: true,
|
|
json: () => Promise.resolve(sampleTokenomics),
|
|
} as Response);
|
|
});
|
|
|
|
const url = 'https://api.example.test/v1/nym-price-cached';
|
|
await fetchNymPriceDeduped(url);
|
|
const second = await fetchNymPriceDeduped(url);
|
|
|
|
expect(second).toStrictEqual(sampleTokenomics);
|
|
expect(callCount).toBe(1);
|
|
});
|
|
});
|