-
Notifications
You must be signed in to change notification settings - Fork 46
fix(frontend): load the OISY Trade balances during initialization #13998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
401c82d
fix(frontend): load OISY Trade balances at initialization
sbpublic 27781bd
Merge branch 'main' into impr/frontend/load-oisy-trade-at-init
sbpublic 0bf5506
fix(frontend): drop an OISY Trade load whose identity is no longer cu…
sbpublic f3bb3ca
Merge branch 'impr/frontend/load-oisy-trade-at-init' of https://githu…
sbpublic 5c2c887
fix(frontend): gate the OISY Trade loader on the provider flag
sbpublic 2b29fc2
fix(frontend): let only the newest OISY Trade load commit
sbpublic c0a9943
Merge branch 'main' into impr/frontend/load-oisy-trade-at-init
sbpublic 1d309a8
Merge branch 'main' into impr/frontend/load-oisy-trade-at-init
sbpublic 580f2ba
Merge branch 'main' into impr/frontend/load-oisy-trade-at-init
sbpublic dfcc94e
Merge branch 'main' into impr/frontend/load-oisy-trade-at-init
sbpublic c945c76
fix(frontend): load only the balances app-wide for the hero total
sbpublic 3484a12
Merge branch 'main' into impr/frontend/load-oisy-trade-at-init
sbpublic 88e0c41
Merge branch 'main' into impr/frontend/load-oisy-trade-at-init
sbpublic 47fe7bd
Merge branch 'main' into impr/frontend/load-oisy-trade-at-init
sbpublic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
src/frontend/src/lib/components/loaders/LoaderOisyTrade.svelte
This file contains hidden or 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,21 @@ | ||
| <script lang="ts"> | ||
| import { OISY_TRADE_ENABLED } from '$env/oisy-trade'; | ||
| import { authIdentity } from '$lib/derived/auth.derived'; | ||
| import { loadOisyTrade } from '$lib/services/oisy-trade.services'; | ||
|
|
||
| // Loads the DEX pairs, supported tokens, balances and orders app-wide (e.g. the | ||
| // hero net worth, which counts deposited balances) without visiting the Trading | ||
| // tab or the OISY Trade page first. Reactive on the identity. | ||
| // | ||
| // Gated on the provider flag rather than the `anyTradingProviderEnabled` | ||
| // aggregate: this only ever talks to the OISY Trade canister, so it must stay | ||
| // off when that provider is, even with the Trading surface kept reachable by | ||
| // another one — the same split `TradingList` and `OisyTradeProvider` make. | ||
| $effect(() => { | ||
| if (!OISY_TRADE_ENABLED) { | ||
| return; | ||
| } | ||
|
|
||
| loadOisyTrade({ identity: $authIdentity }); | ||
|
sbpublic marked this conversation as resolved.
Outdated
|
||
| }); | ||
| </script> | ||
This file contains hidden or 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 hidden or 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
79 changes: 79 additions & 0 deletions
79
src/frontend/src/tests/lib/components/loaders/LoaderOisyTrade.spec.ts
This file contains hidden or 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,79 @@ | ||
| import LoaderOisyTrade from '$lib/components/loaders/LoaderOisyTrade.svelte'; | ||
| import { mockAuthStore } from '$tests/mocks/auth.mock'; | ||
| import { mockIdentity } from '$tests/mocks/identity.mock'; | ||
| import { render, waitFor } from '@testing-library/svelte'; | ||
|
|
||
| const { mockTradingEnabled, mockProviderEnabled, mockLoadOisyTrade } = vi.hoisted(() => ({ | ||
| mockTradingEnabled: { value: true }, | ||
| mockProviderEnabled: { value: true }, | ||
| mockLoadOisyTrade: vi.fn(() => Promise.resolve(undefined)) | ||
| })); | ||
|
|
||
| // The two flags are mocked independently, as `OisyTradeProvider.svelte.spec.ts` | ||
| // does: the codebase models the Trading surface staying reachable through | ||
| // another provider while OISY TRADE itself is off, and this loader must follow | ||
| // the provider flag, not the aggregate. | ||
| vi.mock('$env/trading', () => ({ | ||
| get anyTradingProviderEnabled() { | ||
| return mockTradingEnabled.value; | ||
| } | ||
| })); | ||
|
|
||
| vi.mock('$env/oisy-trade', () => ({ | ||
| get OISY_TRADE_ENABLED() { | ||
| return mockProviderEnabled.value; | ||
| } | ||
| })); | ||
|
|
||
| vi.mock('$lib/services/oisy-trade.services', () => ({ | ||
| loadOisyTrade: mockLoadOisyTrade | ||
| })); | ||
|
|
||
| describe('LoaderOisyTrade', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
|
|
||
| mockTradingEnabled.value = true; | ||
| mockProviderEnabled.value = true; | ||
| }); | ||
|
|
||
| it('should load the OISY Trade data when an identity is available', async () => { | ||
| mockAuthStore(); | ||
|
|
||
| render(LoaderOisyTrade); | ||
|
|
||
| await waitFor(() => { | ||
| expect(mockLoadOisyTrade).toHaveBeenCalledExactlyOnceWith({ identity: mockIdentity }); | ||
| }); | ||
| }); | ||
|
|
||
| // Signed out, `loadOisyTrade` resets the store, so the loader must still call it. | ||
| it('should call the loader with a nullish identity when signed out', async () => { | ||
| mockAuthStore(null); | ||
|
|
||
| render(LoaderOisyTrade); | ||
|
|
||
| await waitFor(() => { | ||
| expect(mockLoadOisyTrade).toHaveBeenCalledExactlyOnceWith({ identity: null }); | ||
| }); | ||
| }); | ||
|
|
||
| it('should not load anything when the OISY Trade provider is disabled', () => { | ||
| mockProviderEnabled.value = false; | ||
| mockAuthStore(); | ||
|
|
||
| render(LoaderOisyTrade); | ||
|
|
||
| expect(mockLoadOisyTrade).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should not load anything when OISY Trade is off but another provider keeps the surface on', () => { | ||
| mockTradingEnabled.value = true; | ||
| mockProviderEnabled.value = false; | ||
| mockAuthStore(); | ||
|
|
||
| render(LoaderOisyTrade); | ||
|
|
||
| expect(mockLoadOisyTrade).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.