fix: live trade redirects only updating URL bar
This commit is contained in:
parent
0e68eb8c42
commit
4e58d20e84
3 changed files with 40 additions and 13 deletions
|
|
@ -89,8 +89,10 @@
|
||||||
setOpenMobile(false);
|
setOpenMobile(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleTradeClick(coinSymbol: string) {
|
async function handleTradeClick(coinSymbol: string) {
|
||||||
goto(`/coin/${coinSymbol.toLowerCase()}`);
|
const targetPath = `/coin/${coinSymbol.toLowerCase()}`;
|
||||||
|
|
||||||
|
await goto(targetPath, { invalidateAll: true });
|
||||||
setOpenMobile(false);
|
setOpenMobile(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -443,11 +445,7 @@
|
||||||
<Sidebar.MenuItem>
|
<Sidebar.MenuItem>
|
||||||
<Sidebar.MenuButton>
|
<Sidebar.MenuButton>
|
||||||
{#snippet child({ props }: { props: MenuButtonProps })}
|
{#snippet child({ props }: { props: MenuButtonProps })}
|
||||||
<a
|
<a href="/legal/terms" onclick={handleTermsClick} class={`${props.class}`}>
|
||||||
href="/legal/terms"
|
|
||||||
onclick={handleTermsClick}
|
|
||||||
class={`${props.class}`}
|
|
||||||
>
|
|
||||||
<Scale />
|
<Scale />
|
||||||
<span>Terms of Service</span>
|
<span>Terms of Service</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
@ -457,11 +455,7 @@
|
||||||
<Sidebar.MenuItem>
|
<Sidebar.MenuItem>
|
||||||
<Sidebar.MenuButton>
|
<Sidebar.MenuButton>
|
||||||
{#snippet child({ props }: { props: MenuButtonProps })}
|
{#snippet child({ props }: { props: MenuButtonProps })}
|
||||||
<a
|
<a href="/legal/privacy" onclick={handlePrivacyClick} class={`${props.class}`}>
|
||||||
href="/legal/privacy"
|
|
||||||
onclick={handlePrivacyClick}
|
|
||||||
class={`${props.class}`}
|
|
||||||
>
|
|
||||||
<ShieldCheck />
|
<ShieldCheck />
|
||||||
<span>Privacy Policy</span>
|
<span>Privacy Policy</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
|
||||||
|
|
@ -226,6 +226,10 @@ function connect(): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
function setCoin(coinSymbol: string): void {
|
function setCoin(coinSymbol: string): void {
|
||||||
|
if (activeCoin !== coinSymbol && activeCoin !== '@global') {
|
||||||
|
unsubscribeFromPriceUpdates(activeCoin);
|
||||||
|
}
|
||||||
|
|
||||||
activeCoin = coinSymbol;
|
activeCoin = coinSymbol;
|
||||||
sendMessage({ type: 'set_coin', coinSymbol });
|
sendMessage({ type: 'set_coin', coinSymbol });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,9 +26,10 @@
|
||||||
import { getPublicUrl, getTimeframeInSeconds } from '$lib/utils.js';
|
import { getPublicUrl, getTimeframeInSeconds } from '$lib/utils.js';
|
||||||
import { websocketController, type PriceUpdate, isConnectedStore } from '$lib/stores/websocket';
|
import { websocketController, type PriceUpdate, isConnectedStore } from '$lib/stores/websocket';
|
||||||
import SEO from '$lib/components/self/SEO.svelte';
|
import SEO from '$lib/components/self/SEO.svelte';
|
||||||
|
import { page } from '$app/state';
|
||||||
|
|
||||||
const { data } = $props();
|
const { data } = $props();
|
||||||
const coinSymbol = data.coinSymbol;
|
let coinSymbol = $derived(data.coinSymbol);
|
||||||
let coin = $state<any>(null);
|
let coin = $state<any>(null);
|
||||||
let loading = $state(true);
|
let loading = $state(true);
|
||||||
let chartData = $state<any[]>([]);
|
let chartData = $state<any[]>([]);
|
||||||
|
|
@ -63,6 +64,34 @@
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Handle route changes to update coin data
|
||||||
|
$effect(() => {
|
||||||
|
const currentCoinSymbol = page.params.coinSymbol;
|
||||||
|
if (currentCoinSymbol && currentCoinSymbol !== coinSymbol) {
|
||||||
|
loading = true;
|
||||||
|
coin = null;
|
||||||
|
chartData = [];
|
||||||
|
volumeData = [];
|
||||||
|
userHolding = 0;
|
||||||
|
|
||||||
|
// Unsubscribe from the old coin's updates
|
||||||
|
websocketController.unsubscribeFromPriceUpdates(coinSymbol.toUpperCase());
|
||||||
|
|
||||||
|
// Update the data prop which will trigger coinSymbol to update via $derived
|
||||||
|
data.coinSymbol = currentCoinSymbol;
|
||||||
|
|
||||||
|
// Load new coin data and set up new subscriptions
|
||||||
|
loadCoinData().then(() => {
|
||||||
|
loadUserHolding();
|
||||||
|
websocketController.setCoin(currentCoinSymbol.toUpperCase());
|
||||||
|
websocketController.subscribeToPriceUpdates(
|
||||||
|
currentCoinSymbol.toUpperCase(),
|
||||||
|
handlePriceUpdate
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
async function loadCoinData() {
|
async function loadCoinData() {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/api/coin/${coinSymbol}?timeframe=${selectedTimeframe}`);
|
const response = await fetch(`/api/coin/${coinSymbol}?timeframe=${selectedTimeframe}`);
|
||||||
|
|
|
||||||
Reference in a new issue