save selected symbol & timeframe
This commit is contained in:
@@ -2,7 +2,7 @@ import {useChartOrderStore} from "@/orderbuild.js";
|
||||
import {invokeCallbacks, prototype} from "@/common.js";
|
||||
import {DataFeed, feelessTickerKey, getAllSymbols, lookupSymbol} from "@/charts/datafeed.js";
|
||||
import {intervalToSeconds, SingletonCoroutine} from "@/misc.js";
|
||||
import {useStore} from "@/store/store.js";
|
||||
import {usePrefStore, useStore} from "@/store/store.js";
|
||||
import {tvCustomThemes} from "../../theme.js";
|
||||
import {copyPoints} from "@/charts/chart-misc.js";
|
||||
|
||||
@@ -14,6 +14,7 @@ let symbolChangedCbs = [] // callbacks for TV's chart.onSymbolChanged()
|
||||
|
||||
const s = useStore()
|
||||
const co = useChartOrderStore()
|
||||
const prefs = usePrefStore()
|
||||
|
||||
export function addSymbolChangedCallback(cb) {
|
||||
symbolChangedCbs.push(cb)
|
||||
@@ -26,6 +27,7 @@ export function removeSymbolChangedCallback(cb) {
|
||||
function symbolChanged(symbol) {
|
||||
const info = symbol===null ? null : lookupSymbol(symbol.ticker)
|
||||
co.selectedSymbol = info
|
||||
prefs.selectedTicker = info?.ticker
|
||||
symbolChangedCbs.forEach((cb) => cb(info))
|
||||
updateFeeDropdown()
|
||||
console.log('symbol changed', info)
|
||||
@@ -54,8 +56,9 @@ export async function setSymbolTicker(ticker) {
|
||||
}
|
||||
|
||||
|
||||
function changeInterval(interval, _timeframe) {
|
||||
function changeInterval(interval) {
|
||||
co.intervalSecs = intervalToSeconds(interval)
|
||||
prefs.selectedTimeframe = interval
|
||||
DataFeed.intervalChanged(co.intervalSecs)
|
||||
}
|
||||
|
||||
@@ -128,6 +131,8 @@ function selectPool(fee) {
|
||||
}
|
||||
|
||||
export function initWidget(el) {
|
||||
const symbol = prefs.selectedTicker === null ? 'default' : prefs.selectedTicker
|
||||
const interval = prefs.selectedTimeframe === null ? '15' : prefs.selectedTimeframe
|
||||
widget = window.tvWidget = new TradingView.widget({
|
||||
|
||||
// Widget Options
|
||||
@@ -135,8 +140,8 @@ export function initWidget(el) {
|
||||
library_path: "/charting_library/",
|
||||
// debug: true,
|
||||
autosize: true,
|
||||
symbol: 'default',
|
||||
interval: '15',
|
||||
symbol,
|
||||
interval,
|
||||
container: el,
|
||||
datafeed: DataFeed, // use this for ohlc
|
||||
locale: "en",
|
||||
|
||||
@@ -207,7 +207,9 @@ export const usePrefStore = defineStore({
|
||||
// user preferences
|
||||
const inverted = ref({})
|
||||
const acceptedTos = ref('NO TOS ACCEPTED')
|
||||
return {inverted, acceptedTos,}
|
||||
const selectedTicker = ref(null)
|
||||
const selectedTimeframe = ref(null)
|
||||
return {inverted, acceptedTos, selectedTicker, selectedTimeframe}
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user