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