symbol rework; fee % switching; symbol search improvements
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import {useChartOrderStore} from "@/orderbuild.js";
|
||||
import {invokeCallbacks, prototype} from "@/common.js";
|
||||
import {DataFeed, initFeeDropdown, lookupSymbol} from "@/charts/datafeed.js";
|
||||
import {DataFeed, feelessTickerKey, getAllSymbols, lookupSymbol} from "@/charts/datafeed.js";
|
||||
import {intervalToSeconds, SingletonCoroutine} from "@/misc.js";
|
||||
import {useStore} from "@/store/store.js";
|
||||
import {tvCustomThemes} from "../../theme.js";
|
||||
@@ -22,11 +22,11 @@ export function removeSymbolChangedCallback(cb) {
|
||||
symbolChangedCbs = symbolChangedCbs.filter((i)=>i!==cb)
|
||||
}
|
||||
|
||||
function changeSymbol(symbol) {
|
||||
console.error('change symbol', symbol)
|
||||
function symbolChanged(symbol) {
|
||||
if (symbol===null)
|
||||
co.selectedSymbol = null
|
||||
else {
|
||||
updateFeeDropdown()
|
||||
const info = lookupSymbol(symbol.ticker)
|
||||
symbolChangedCbs.forEach((cb) => cb(info))
|
||||
co.selectedSymbol = info
|
||||
@@ -44,6 +44,16 @@ export async function setSymbol(symbol) {
|
||||
}
|
||||
|
||||
|
||||
export async function setSymbolTicker(ticker) {
|
||||
const found = getAllSymbols()[ticker]
|
||||
if (!found) {
|
||||
console.error('No symbol for ticker', ticker)
|
||||
return
|
||||
}
|
||||
await setSymbol(found)
|
||||
}
|
||||
|
||||
|
||||
function changeInterval(interval, _timeframe) {
|
||||
co.intervalSecs = intervalToSeconds(interval)
|
||||
DataFeed.intervalChanged(co.intervalSecs)
|
||||
@@ -70,6 +80,50 @@ const subscribeEvents = [
|
||||
*/
|
||||
|
||||
|
||||
let feeDropdown = null
|
||||
|
||||
export function initFeeDropdown(w) {
|
||||
widget = w
|
||||
widget.createDropdown(
|
||||
{
|
||||
title: 'Fees',
|
||||
tooltip: 'Choose Fee Tier',
|
||||
items: [/*{title: 'Automatic Fee Selection', onSelect: () => {log('autofees')}}*/],
|
||||
icon: `<svg xmlns="http://www.w3.org/2000/svg" width="28" height="28"><g fill="none" stroke="currentColor"><circle cx="10" cy="10" r="2.5"/><circle cx="18" cy="18" r="2.5"/><path stroke-linecap="square" d="M17.5 7.5l-7 13"/></g></svg>`,
|
||||
}
|
||||
).then(dropdown => {
|
||||
feeDropdown = dropdown;
|
||||
updateFeeDropdown()
|
||||
})
|
||||
}
|
||||
|
||||
export function updateFeeDropdown() {
|
||||
if (feeDropdown === null) return
|
||||
const symbolItem = useChartOrderStore().selectedSymbol
|
||||
let items
|
||||
if (symbolItem === null)
|
||||
items = [{title: '0.00%'}]
|
||||
else {
|
||||
const feeGroup = symbolItem.feeGroup
|
||||
items = feeGroup.map((p) => {
|
||||
const [_addr, fee] = p
|
||||
return {
|
||||
title: (fee / 10000).toFixed(2) + '%',
|
||||
onSelect: fee === symbolItem.fee ? ()=>{} : () => selectPool(fee),
|
||||
}
|
||||
})
|
||||
}
|
||||
feeDropdown.applyOptions({items})
|
||||
}
|
||||
|
||||
function selectPool(fee) {
|
||||
const co = useChartOrderStore();
|
||||
const s = co.selectedSymbol;
|
||||
const ticker = feelessTickerKey(s.ticker) + '|' + fee
|
||||
if (ticker !== s.ticker)
|
||||
setSymbolTicker(ticker).catch((e)=>console.error('Could not change TV symbol to', ticker))
|
||||
}
|
||||
|
||||
export function initWidget(el) {
|
||||
widget = window.tvWidget = new TradingView.widget({
|
||||
library_path: "/charting_library/",
|
||||
@@ -107,7 +161,7 @@ function initChart() {
|
||||
const themeName = useStore().theme;
|
||||
widget.changeTheme(themeName).catch((e)=>console.warn(`Could not change theme to ${themeName}`, e))
|
||||
chart.crossHairMoved().subscribe(null, (point)=>setTimeout(()=>handleCrosshairMovement(point),0) )
|
||||
chart.onSymbolChanged().subscribe(null, changeSymbol)
|
||||
chart.onSymbolChanged().subscribe(null, symbolChanged)
|
||||
chart.onIntervalChanged().subscribe(null, changeInterval)
|
||||
chart.onDataLoaded().subscribe(null, dataLoaded)
|
||||
const tzapi = chart.getTimezoneApi();
|
||||
@@ -118,10 +172,10 @@ function initChart() {
|
||||
const symbolExt = chart.symbolExt();
|
||||
// console.log('symbolExt', symbolExt);
|
||||
if(symbolExt) {
|
||||
changeSymbol(symbolExt)
|
||||
symbolChanged(symbolExt)
|
||||
}
|
||||
else {
|
||||
changeSymbol(null)
|
||||
symbolChanged(null)
|
||||
}
|
||||
changeInterval(widget.symbolInterval().interval)
|
||||
co.chartReady = true
|
||||
|
||||
Reference in New Issue
Block a user