UI fixes including loop suppression when model doesnt change
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<component :is="component" :order="order" :builder="builder"/>
|
||||
<component :is="component" v-bind="props"/>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
@@ -8,7 +8,7 @@ import DCABuilder from "@/components/chart/DCABuilder.vue";
|
||||
import LimitBuilder from "@/components/chart/LimitBuilder.vue";
|
||||
import MarketBuilder from "@/components/chart/MarketBuilder.vue";
|
||||
|
||||
const props = defineProps(['order','builder'])
|
||||
const props = defineProps(['order', 'builder'])
|
||||
|
||||
const component = computed(()=>{
|
||||
switch (props.builder.component) {
|
||||
|
||||
@@ -2,21 +2,22 @@
|
||||
<row-bar :color="color">
|
||||
<color-band :color="color"/>
|
||||
<div :style="faintColorStyle" style="width: 100%" class="justify-start align-content-start">
|
||||
<v-text-field type="number" inputmode="numeric" pattern="[0-9]*\.?[0-9]*" v-model="os.amount" variant="outlined" density="compact" hide-details
|
||||
min="0" :step="os.amount?Math.floor(os.amount/1000):1"
|
||||
<v-text-field type="number" inputmode="numeric" pattern="[0-9]*\.?[0-9]*" v-model="order.amount" variant="outlined" density="compact" hide-details
|
||||
min="0" :step="order.amount?Math.floor(order.amount/1000):1"
|
||||
style="max-width:24em; display: inline-grid"
|
||||
class="py-2" :color="color"
|
||||
:label="os.amountIsTokenA ? 'Amount':('Value in '+os.quote.s)"
|
||||
:label="order.amountIsTokenA ? 'Amount':('Value in '+co.selectedSymbol.quote.s)"
|
||||
>
|
||||
<template v-slot:prepend>
|
||||
<v-btn :text="(os.buy ? 'Buy ' : 'Sell ') + os.base.s" variant="tonal" :color="color" @click="os.buy=!os.buy"/>
|
||||
<v-btn :text="(order.buy ? 'Buy ' : 'Sell ') + co.selectedSymbol.base.s" variant="tonal" :color="color" @click="order.buy=!order.buy"/>
|
||||
</template>
|
||||
<template v-slot:append-inner>
|
||||
<v-btn :text="os.amountToken.s+(os.amountIsTokenA?'':' worth')" :color="color" variant="text" @click="os.amountIsTokenA=!os.amountIsTokenA"/>
|
||||
<v-btn :text="order.amountIsTokenA?co.selectedSymbol.base.s:co.selectedSymbol.quote.s+' worth'"
|
||||
:color="color" variant="text" @click="order.amountIsTokenA=!order.amountIsTokenA"/>
|
||||
</template>
|
||||
</v-text-field>
|
||||
<template v-for="b in builders(order)">
|
||||
<builder-factory :order="order" :builder="b" :color="color"/>
|
||||
<builder-factory :order="order" :builder="b"/>
|
||||
</template>
|
||||
<div class="my-3">
|
||||
<span :style="colorStyle" class="ma-3">Add condition:</span>
|
||||
@@ -51,6 +52,7 @@ const props = defineProps(['order'])
|
||||
const co = useChartOrderStore()
|
||||
const os = useOrderStore()
|
||||
|
||||
console.log('order', props.order)
|
||||
function build(order, component, options={}) {
|
||||
order.builders.push(newBuilder(component, options))
|
||||
}
|
||||
@@ -61,7 +63,7 @@ function builders(order) {
|
||||
}
|
||||
|
||||
const theme = useTheme().current
|
||||
const color = computed(()=>os.buy?theme.value.colors.success:theme.value.colors.error)
|
||||
const color = computed(()=>props.order.buy?theme.value.colors.success:theme.value.colors.error)
|
||||
const lightColor = computed(() => lightenColor(color.value))
|
||||
const faintColor = computed(() => lightenColor2(color.value))
|
||||
const colorStyle = computed(() => { return {'color': color.value} })
|
||||
@@ -69,9 +71,9 @@ const bgColorStyle = computed(() => { return {'background-color': color.value} }
|
||||
const lightColorStyle = computed(() => { return {'background-color': lightColor.value} })
|
||||
const faintColorStyle = computed(() => { return {'background-color': faintColor.value} })
|
||||
|
||||
const inToken = computed( ()=>os.buy ? os.tokenB : os.tokenA )
|
||||
const inToken = computed( ()=>props.order.buy ? co.selectedSymbol.quote : co.selectedSymbol.base )
|
||||
const maxAmount = computed(()=>{
|
||||
const balance = s.balances[inToken]
|
||||
const balance = s.balances[inToken.value]
|
||||
if( !balance )
|
||||
return 0
|
||||
const divisor = os.amountIsTotal ? 1 : os.tranches
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
<script setup>
|
||||
import {useChartOrderStore} from "@/orderbuild.js";
|
||||
import Toolbar from "@/components/chart/Toolbar.vue";
|
||||
import BuilderFactory from "@/components/chart/BuilderFactory.vue";
|
||||
import {addSymbolChangedCallback, removeSymbolChangedCallback} from "@/charts/chart.js";
|
||||
import {onBeforeUnmount} from "vue";
|
||||
import {useOrderStore} from "@/store/store.js";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<!-- todo extract builder-panel --> <!-- :builder="builder" color-tag="limit" -->
|
||||
<row-bar :color="builder.color">
|
||||
<row-bar :color="builder.color" :data-ignore="autoAdjust">
|
||||
<color-band :color="builder.color"/>
|
||||
<div style="min-width: 3em; font-size: larger" :style="colorStyle"
|
||||
class="align-self-start ml-2 pt-3">{{ rungs === 1 ? 'Limit' : 'Ladder' }}</div>
|
||||
@@ -60,7 +60,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import {computed} from "vue";
|
||||
import {computed, onBeforeUnmount, onMounted} from "vue";
|
||||
import {chart} from "@/charts/chart.js";
|
||||
import {useChartOrderStore} from "@/orderbuild.js";
|
||||
import Color from "color";
|
||||
@@ -94,7 +94,6 @@ const skew100 = computed( {
|
||||
set(v) {props.builder.skew = v/100; adjustShapes()}
|
||||
} )
|
||||
|
||||
|
||||
// we keep two special control lines as the edge of the ranges and then deletable lines in-between
|
||||
|
||||
const lineAPrice = computed({
|
||||
@@ -126,15 +125,14 @@ const lineB = new HLine(
|
||||
)
|
||||
|
||||
const adjustInteriorLine = (line) => {
|
||||
console.log('interior line onModel')
|
||||
props.builder.color = line.color
|
||||
adjustShapes()
|
||||
}
|
||||
|
||||
let interiorLines = []
|
||||
|
||||
function createInteriorLine(price) {
|
||||
const line = new HLine({price: price, color: props.builder.color}, adjustInteriorLine, deleteBuilder)
|
||||
function createInteriorLine(price, lineProps) {
|
||||
const line = new HLine({price: price, color: props.builder.color}, adjustInteriorLine, deleteBuilder, lineProps)
|
||||
line.onPoints = function (points) {
|
||||
const delta = points[0].price - this.model.price
|
||||
if (delta !== 0) {
|
||||
@@ -225,6 +223,8 @@ const rungs = computed({
|
||||
const prices = computed(()=>{
|
||||
let a = props.builder.priceA
|
||||
let b = props.builder.priceB
|
||||
|
||||
|
||||
const r = props.builder.rungs
|
||||
// console.log('prices for', a, b, r)
|
||||
if ( a===null || !r ) return [] // no data
|
||||
@@ -264,7 +264,7 @@ const weights = computed(() => {
|
||||
|
||||
const colors = computed( ()=> {
|
||||
const color = props.builder.color !== null ? props.builder.color
|
||||
: os.buy ? theme.value.colors.success : theme.value.colors.error
|
||||
: props.buy ? theme.value.colors.success : theme.value.colors.error
|
||||
const c = new Color(color).rgb()
|
||||
const ws = weights.value;
|
||||
const max = Math.max(...ws)
|
||||
@@ -274,24 +274,27 @@ const colors = computed( ()=> {
|
||||
})
|
||||
|
||||
|
||||
const amountSymbol = computed(()=>props.order.amountIsTokenA ? co.selectedSymbol.base.s : co.selectedSymbol.quote.s )
|
||||
|
||||
|
||||
function allocationText(weight) {
|
||||
const alloc = props.builder.allocation
|
||||
if (alloc===null) return ''
|
||||
const w = weight * alloc
|
||||
// console.log('weight', weight, alloc, props.amount)
|
||||
const a = props.order.amount * w
|
||||
const t = os.amountToken
|
||||
return `${(w*100).toFixed(1)}% ${a.toLocaleString('fullwide')} ${t.s}`
|
||||
return `${(w*100).toFixed(1)}% = ${a.toLocaleString('fullwide')} ${amountSymbol.value}`
|
||||
}
|
||||
|
||||
|
||||
function adjustShapes() {
|
||||
// this is where all the lines are created or adjusted
|
||||
console.log('adjustShapes()')
|
||||
// console.log('adjustShapes()')
|
||||
|
||||
const limits = prices.value
|
||||
const colorStrings = colors.value
|
||||
// line properties
|
||||
const lps = weights.value.map((w)=>{return {text:allocationText(w), textcolor:color.value}})
|
||||
console.log('things', colorStrings, lps)
|
||||
if( limits.length === 0 ) {
|
||||
lineA.delete()
|
||||
lineB.delete()
|
||||
@@ -332,15 +335,18 @@ function adjustShapes() {
|
||||
for( let i=0; i<limits.length-2; i++ ) {
|
||||
const limit = limits[1+i]
|
||||
if (i === interiorLines.length)
|
||||
createInteriorLine(limit)
|
||||
createInteriorLine(limit, lps[1+i])
|
||||
else if (!interiorLines[i].beingDragged())
|
||||
interiorLines[i].setModel({price:limit, color: colorStrings[1+i]}, lps[1+i])
|
||||
}
|
||||
}
|
||||
|
||||
return ''
|
||||
}
|
||||
|
||||
|
||||
const autoAdjust = computed(adjustShapes)
|
||||
|
||||
|
||||
function deleteShapes() {
|
||||
lineA.delete()
|
||||
lineB.delete()
|
||||
@@ -359,6 +365,8 @@ function deleteBuilder() {
|
||||
if (!props.builder.priceA)
|
||||
lineA.createOrDraw(); // initiate drawing mode
|
||||
|
||||
onMounted(adjustShapes)
|
||||
onBeforeUnmount(deleteShapes)
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<div class="bg-grey-lighten-1" style="width:1em"> </div>
|
||||
<div style="min-width: 3em; font-size: larger" class="align-self-start ma-3">Market Order</div>
|
||||
<div>
|
||||
<v-text-field type="number" v-model="os.slippage"
|
||||
<v-text-field type="number" v-model="props.builder.slippage"
|
||||
density="compact" hide-details class="mx-1 my-2" variant="outlined"
|
||||
label="Max Slippage" min="0" max="100" step="0.01"
|
||||
style="width: 9em;"
|
||||
@@ -20,7 +20,6 @@ import {useChartOrderStore} from "@/orderbuild.js";
|
||||
import {builderDefaults} from "@/misc.js";
|
||||
import {useOrderStore} from "@/store/store.js";
|
||||
|
||||
const os = useOrderStore()
|
||||
const co = useChartOrderStore()
|
||||
const props = defineProps(['order', 'builder'])
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ const co = useChartOrderStore()
|
||||
let shape = null
|
||||
|
||||
function newOrder() {
|
||||
console.log('new order 1')
|
||||
co.newOrder()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user