diff --git a/src/routes/options-calculator/+page.svelte b/src/routes/options-calculator/+page.svelte index ff1f9a40..1a40a14b 100644 --- a/src/routes/options-calculator/+page.svelte +++ b/src/routes/options-calculator/+page.svelte @@ -1184,6 +1184,14 @@ } async function handleAddOptionLeg() { + if (userStrategy?.length >= 5) { + toast.error("You've reached the maximum number of option legs.", { + style: `border-radius: 5px; background: #fff; color: #000; border: 1px solid ${$mode === "light" ? "#F3F4F6" : "#4B5563"}; font-size: 15px; padding: 10px;`, + }); + + return; + } + if (userStrategy.length === 0) { userStrategy = [ { @@ -1346,9 +1354,45 @@ shouldUpdate = true; } - // LIFECYCLE FUNCTIONS + async function handleSaveStrategy() { + try { + // Create filtered strategies without strikeList and dateList + const strategiesToSave = userStrategy.map( + ({ strikeList, dateList, ...rest }) => rest, + ); + + // Save the filtered version + localStorage?.setItem( + "options-calculator-strategy", + JSON?.stringify({ + userStrategy: strategiesToSave, + ticker: selectedTicker, + }), + ); + + toast.success("Options Strategy saved!", { + style: `border-radius: 5px; background: #fff; color: #000; border: 1px solid ${$mode === "light" ? "#F3F4F6" : "#4B5563"}; font-size: 15px; padding: 10px;`, + }); + } catch (e) { + console.log("Failed saving indicator rules: ", e); + } + } onMount(async () => { + try { + const savedStrategy = localStorage?.getItem( + "options-calculator-strategy", + ); + + if (savedStrategy) { + const parsedData = JSON.parse(savedStrategy); + userStrategy = parsedData?.userStrategy; + selectedTicker = parsedData?.ticker; + } + } catch (e) { + console.log(e); + } + await getStockData(); await loadData(); @@ -1424,8 +1468,8 @@
changeStrategy(strategy)} class="{selectedStrategy === strategy?.name - ? 'bg-blue-100 dark:bg-primary text-muted' - : ''} text-sm elect-none flex items-center space-x-2 border border-gray-300 dark:border-gray-600 rounded-full px-3 py-1 text-blue-700 dark:text-white dark:sm:hover:text-white sm:hover:text-muted cursor-pointer" + ? 'bg-blue-100 dark:bg-white text-muted ' + : 'text-blue-700 dark:text-white dark:sm:hover:text-white sm:hover:text-muted'} text-sm select-none flex items-center space-x-2 border border-gray-300 dark:border-gray-600 rounded-full px-3 py-1 cursor-pointer" > {strategy.name} {#if strategy?.sentiment} @@ -1453,57 +1497,122 @@
{#if isLoaded && config} - -
- -
- {#if inputValue?.length !== 0 && inputValue !== selectedTicker} - - {#each searchBarData as searchItem} - changeTicker(searchItem)} + +
+
+
- {searchItem?.symbol} - {searchItem?.name} -
- - {:else} - - No results found - - {/each} - - {/if} - + + +
+ +
+ {#if inputValue?.length !== 0 && inputValue !== selectedTicker} + + {#each searchBarData as searchItem} + changeTicker(searchItem)} + > +
+ {searchItem?.symbol} + {searchItem?.name} +
+
+ {:else} + + No results found + + {/each} +
+ {/if} +
+ + + +
@@ -1719,26 +1828,6 @@ {/each} - -
@@ -1748,7 +1837,7 @@ use:highcharts={config} >
-
+