-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontend): check if exchange enabled for initialization (#3363)
# Motivation The derived store `exchangeInitialized` should be considered `true` when the exchange is disabled. This mainly happens for test environments (like E2E) where we don't provide API keys and we forcibly turn off the exchanges via env variable `VITE_EXCHANGE_DISABLED`: it is mostly used for loading states, so just for visual changes. # Changes - Extract parsed env variable `EXCHANGE_DISABLED` and export it globally. - Include it in the logic of `exchangeInitialized`: it is true if either `exchangeInitialized` data is non-nullish or if exchange is disabled. # Tests Created some tests for the derived. --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
42d7c66
commit ca05ca0
Showing
4 changed files
with
44 additions
and
4 deletions.
There are no files selected for viewing
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,2 @@ | ||
export const EXCHANGE_DISABLED = | ||
JSON.parse(import.meta.env.VITE_EXCHANGE_DISABLED ?? false) === true; |
3 changes: 1 addition & 2 deletions
3
src/frontend/src/lib/components/exchange/ExchangeWorker.svelte
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
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
36 changes: 36 additions & 0 deletions
36
src/frontend/src/tests/lib/derived/exchange.derived.spec.ts
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,36 @@ | ||
import * as exchangeEnv from '$env/exchange.env'; | ||
import { exchangeInitialized } from '$lib/derived/exchange.derived'; | ||
import { exchangeStore } from '$lib/stores/exchange.store'; | ||
import { get } from 'svelte/store'; | ||
import { expect } from 'vitest'; | ||
|
||
describe('exchange.derived', () => { | ||
describe('exchangeInitialized', () => { | ||
beforeEach(() => { | ||
vi.spyOn(exchangeEnv, 'EXCHANGE_DISABLED', 'get').mockImplementation(() => false); | ||
}); | ||
|
||
it('should return false when exchange store is empty', () => { | ||
expect(get(exchangeInitialized)).toBe(false); | ||
}); | ||
|
||
it('should return true when exchange is disabled', () => { | ||
vi.spyOn(exchangeEnv, 'EXCHANGE_DISABLED', 'get').mockImplementationOnce(() => true); | ||
|
||
expect(get(exchangeInitialized)).toBe(true); | ||
}); | ||
|
||
it('should return true when exchange store is not empty', () => { | ||
exchangeStore.set([{ ethereum: { usd: 1 } }]); | ||
|
||
expect(get(exchangeInitialized)).toBe(true); | ||
}); | ||
|
||
it('should return false when exchange store is reset', () => { | ||
exchangeStore.set([{ ethereum: { usd: 1 } }]); | ||
exchangeStore.reset(); | ||
|
||
expect(get(exchangeInitialized)).toBe(false); | ||
}); | ||
}); | ||
}); |