{
const [openAddToWatchlist, setOpenAddToWatchlist] = useState(false);
const handleCloseAddTrade = () => { setOpenAddTrade(false); };
- const handleAddToWatchlist = (item: SearchTickerItem) => { addToWatchlist(item); setOpenAddToWatchlist(false); }
+ const handleAddToWatchlist = (item: SearchTickerItem) => {
+ addToWatchlist(item); setOpenAddToWatchlist(false);
+ addToMyList(item);
+ }
return
{/* Watchlist */}
- {
- const [showCloseTrades, setShowCloseTrades] = useState((typeof window !== "undefined" ? window?.localStorage?.getItem("showCloseTrades") == 'true': false) || false);
+ const [showCloseTrades, setShowCloseTrades] = useState((typeof window !== "undefined" ? window?.localStorage?.getItem("showCloseTrades") == 'true' : false) || false);
const toggleShowCloseTrades = useCallback((newstate: boolean) => {
setShowCloseTrades(newstate);
window?.localStorage?.setItem("showCloseTrades", `${newstate}`);
}, []);
- return {showCloseTrades, toggleShowCloseTrades }
+ return { showCloseTrades, toggleShowCloseTrades }
}
+export const useMyLocalWatchList = (initialState: SearchTickerItem[]) => {
+ const [wl, setWl] = useLocalStorage("localwatchlist", initialState);
+
+ const removeFromMyList = (item: SearchTickerItem) => {
+ setWl(v => v.filter((ticker) => ticker.symbol != item.symbol));
+ }
+
+ const addToMyList = (item: SearchTickerItem) => {
+ setWl(v => {
+ v.push(item)
+ return v;
+ });
+ }
+
+ return { wl, removeFromMyList, addToMyList }
+}
+
+