Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/frontend/src/lib/components/loaders/LoaderOisyTrade.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script lang="ts">
import { anyTradingProviderEnabled } from '$env/trading';
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.
$effect(() => {
if (!anyTradingProviderEnabled) {
Comment thread
sbpublic marked this conversation as resolved.
Outdated
return;
}

loadOisyTrade({ identity: $authIdentity });
Comment thread
sbpublic marked this conversation as resolved.
Outdated
Comment thread
sbpublic marked this conversation as resolved.
Outdated
});
</script>
3 changes: 3 additions & 0 deletions src/frontend/src/lib/components/loaders/Loaders.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import LoaderHarvest from '$lib/components/loaders/LoaderHarvest.svelte';
import LoaderLiquidium from '$lib/components/loaders/LoaderLiquidium.svelte';
import LoaderMetamask from '$lib/components/loaders/LoaderMetamask.svelte';
import LoaderOisyTrade from '$lib/components/loaders/LoaderOisyTrade.svelte';
import LoaderSwapTokens from '$lib/components/loaders/LoaderSwapTokens.svelte';
import LoaderTokens from '$lib/components/loaders/LoaderTokens.svelte';
import LoaderUserProfile from '$lib/components/loaders/LoaderUserProfile.svelte';
Expand Down Expand Up @@ -62,6 +63,8 @@

<LoaderLiquidium />

<LoaderOisyTrade />

<LoaderSwapTokens />

{@render children()}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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, mockLoadOisyTrade } = vi.hoisted(() => ({
mockTradingEnabled: { value: true },
mockLoadOisyTrade: vi.fn(() => Promise.resolve(undefined))
}));

vi.mock('$env/trading', () => ({
get anyTradingProviderEnabled() {
return mockTradingEnabled.value;
}
}));

vi.mock('$lib/services/oisy-trade.services', () => ({
loadOisyTrade: mockLoadOisyTrade
}));

describe('LoaderOisyTrade', () => {
beforeEach(() => {
vi.clearAllMocks();

mockTradingEnabled.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 no trading provider is enabled', () => {
mockTradingEnabled.value = false;
mockAuthStore();

render(LoaderOisyTrade);

expect(mockLoadOisyTrade).not.toHaveBeenCalled();
});
});
Loading