From e25239d81fdb8278cc051e9d55a1717d00f43ef5 Mon Sep 17 00:00:00 2001 From: Tim Olson <> Date: Mon, 27 Nov 2023 18:35:40 -0400 Subject: [PATCH] order amount bugfix --- src/components/LadderOrder.vue | 20 +++++++++++--------- src/components/Order.vue | 7 ++----- src/orderbuild.js | 2 +- src/store/store.js | 4 +++- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/components/LadderOrder.vue b/src/components/LadderOrder.vue index ddb8a74..6af30c7 100644 --- a/src/components/LadderOrder.vue +++ b/src/components/LadderOrder.vue @@ -2,8 +2,10 @@ - + + + @@ -27,16 +29,16 @@ import {useOrderStore} from "@/store/store"; import LimitPrice from "@/components/LimitPrice.vue"; import Order from "@/components/Order.vue"; import {computed, ref} from "vue"; -import {newTimeConstraint, TimeMode} from "@/blockchain/orderlib.js"; import {limitConstraint, maxFraction} from "@/orderbuild.js"; -import {validateMax} from "@/validate.js"; +import {validateRequired, validateTranches} from "@/validate.js"; const os = useOrderStore() -const num = ref(3) const skew = ref(0) const rungs = computed(()=>{ - const n = num.value; + if( !os.limitPrice || !os.limitPrice2 ) + return [] + const n = os.tranches; const a = parseFloat(os.limitPrice); const b = parseFloat(os.limitPrice2); if( n < 1 || !a || !b ) return [] @@ -52,7 +54,7 @@ const rungsFmt = computed(()=>{ return rungs.value.map((r)=>r.toPrecision(5)) // todo precisions }) const fractions = computed(()=>{ - const n = num.value + const n = os.tranches const s = skew.value / 100 const result = [] if( s === 1 ) { @@ -72,11 +74,11 @@ const fractions = computed(()=>{ } return result }) -const amounts = computed( ()=>fractions.value.map((f)=>f*os.amount) ) +const amounts = computed( ()=>fractions.value.map((f)=>f*os.totalAmount) ) function buildTranches() { const ts = [] - const n = num.value + const n = os.tranches const mf = Number(maxFraction) for( let i=0; i import {useOrderStore, useStore} from "@/store/store"; -import {computed, ref} from "vue"; import PhoneCard from "@/components/PhoneCard.vue"; import Amount from "@/components/Amount.vue" // noinspection ES6UnusedImports import {routeInverted, SingletonCoroutine, vAutoSelect} from "@/misc.js"; -import {newLimitConstraint, newOrder, newTimeConstraint, TimeMode} from "@/blockchain/orderlib.js"; +import {newOrder} from "@/blockchain/orderlib.js"; import {FixedNumber} from "ethers"; import {pendOrder} from "@/blockchain/wallet.js"; import NeedsProvider from "@/components/NeedsProvider.vue"; -import RoutePrice from "@/components/RoutePrice.vue"; import router from "@/router/index.js"; import PairChoice from "@/components/PairChoice.vue"; -import {isEmpty, validateAmount, validateRequired} from "@/validate.js"; const s = useStore() const os = useOrderStore() @@ -44,7 +41,7 @@ function placeOrder() { const tokenIn = os.buy ? tb.address : ta.address const tokenOut = os.buy ? ta.address : tb.address const route = os.route - const amt = FixedNumber.fromString(os.amount.toString(), {decimals: os.amountToken.decimals}).value + const amt = FixedNumber.fromString(os.totalAmount.toString(), {decimals: os.amountToken.decimals}).value const ts = props.tranches() const order = newOrder(tokenIn, tokenOut, route.exchange, route.fee, amt, os.amountIsInput, ts) pendOrder(order) diff --git a/src/orderbuild.js b/src/orderbuild.js index 8fbe28f..2030e40 100644 --- a/src/orderbuild.js +++ b/src/orderbuild.js @@ -1,6 +1,6 @@ import {routeInverted} from "@/misc.js"; import {newLimitConstraint, newTimeConstraint, TimeMode} from "@/blockchain/orderlib.js"; -import {useOrderStore, useStore} from "@/store/store.js"; +import {useOrderStore} from "@/store/store.js"; export const maxFraction = 65535n // by contract definition of uint16 fraction diff --git a/src/store/store.js b/src/store/store.js index 0a673ec..a6b8a5e 100644 --- a/src/store/store.js +++ b/src/store/store.js @@ -150,6 +150,8 @@ export const useOrderStore = defineStore('order', ()=> { const limitIsMinimum = computed(() => !(buy.value ^ inverted.value)) const amountToken = computed(() => amountIsTokenA.value ? tokenA.value : tokenB.value) const amountIsInput = computed(() => amountIsTokenA.value !== buy.value) + const totalAmount = computed(()=> amountIsTotal.value ? amount.value : amount.value * tranches.value ) + const trancheAmount = computed(()=> amountIsTotal.value ? amount.value / tranches.value : amount.value ) function setDefaultTokens(tokens) { if( tokens.length > 0 ) @@ -161,6 +163,6 @@ export const useOrderStore = defineStore('order', ()=> { return { tokenA, tokenB, buy, inverted, amount, amountIsTokenA, amountIsTotal, limitPrice, limitPrice2, tranches, interval, intervalIsTotal, timeUnitIndex, routes, routesPending, validOrder, route, base, quote, pairSymbol, - limitIsMinimum, amountToken, amountIsInput, setDefaultTokens, + limitIsMinimum, amountToken, amountIsInput, setDefaultTokens, totalAmount, trancheAmount, } }) \ No newline at end of file