denormalized PairEntry, cleaned up console logs
This commit is contained in:
@@ -5,7 +5,18 @@
|
||||
<v-card-subtitle>Split order across time</v-card-subtitle>
|
||||
<v-card-text>
|
||||
|
||||
<pair-entry v-model="pair"/>
|
||||
<token-choice v-model="tokenA" class="token-choice mb-1">
|
||||
<template v-slot:prepend>
|
||||
<v-btn :text="buy ? 'Buy' : 'Sell'" :color="buy ? 'green' : 'red'"
|
||||
variant="outlined" @click="buy=!buy" class="bs-button"/>
|
||||
</template>
|
||||
</token-choice>
|
||||
<token-choice v-model="tokenB" class="token-choice">
|
||||
<template v-slot:prepend>
|
||||
<v-btn :text="!buy ? 'Buy' : 'Sell'" :color="!buy ? 'green' : 'red'"
|
||||
variant="outlined" @click="buy=!buy" class="bs-button"/>
|
||||
</template>
|
||||
</token-choice>
|
||||
|
||||
<v-chip v-for="r in routes" variant="text">
|
||||
{{ s.chain.name }}
|
||||
@@ -18,28 +29,28 @@
|
||||
<v-progress-circular indeterminate/> Searching for {{pairSymbol}} pools...
|
||||
</div>
|
||||
|
||||
<v-alert v-if="routes.length===0 && !routeFinder.pending()" text="No pool found!" type=""/>
|
||||
<v-alert v-if="routes.length===0 && !routeFinder.pending()" text="No pool found!"/>
|
||||
|
||||
<div v-if="routes.length">
|
||||
<v-text-field label='Amount' type="number" step="1" variant="outlined" aria-valuemin="0" min="0"
|
||||
:model-value="amount" :rules="[validateRequired,validateAmount]">
|
||||
v-model="amount" :rules="[validateRequired,validateAmount]" v-auto-select>
|
||||
<template v-slot:append-inner>
|
||||
<v-btn @click="amountIsBase=!amountIsBase" variant="outlined" class="mr-2">
|
||||
{{ amountIsBase ? pair.tokenA.symbol : pair.tokenB.symbol }}
|
||||
{{ amountIsBase ? tokenA.symbol : tokenB.symbol }}
|
||||
</v-btn>
|
||||
<v-btn :text="amountIsTotal ? 'total' : 'per tranche'" variant="outlined"
|
||||
@click="amountIsTotal=!amountIsTotal" class="total"/>
|
||||
</template>
|
||||
</v-text-field>
|
||||
<v-text-field label="Tranches" type="number" variant="outlined" aria-valuemin="1" min="1" max="255"
|
||||
:model-value="tranches" :rules="[validateRequired,validateTranches]">
|
||||
:model-value="tranches" :rules="[validateRequired,validateTranches]" v-auto-select>
|
||||
<!-- <template v-slot:prepend-inner>-->
|
||||
<!-- <div>{{ amountIsTotal ? 'Split into' : 'Times' }}</div>-->
|
||||
<!-- </template>-->
|
||||
<template v-slot:append-inner>tranches</template>
|
||||
</v-text-field>
|
||||
<v-text-field type="number" variant="outlined" :min="1" v-model="interval" class="interval"
|
||||
:label="intervalIsTotal ? 'Completion time' : 'Time between tranches'">
|
||||
:label="intervalIsTotal ? 'Completion time' : 'Time between tranches'" v-auto-select>
|
||||
<!-- <template v-slot:append>APART</template>-->
|
||||
<template v-slot:prepend-inner>
|
||||
<v-btn variant="outlined" :text="intervalIsTotal ? 'Within' : 'Spaced apart'" class="within mr-2"
|
||||
@@ -51,40 +62,20 @@
|
||||
</v-text-field>
|
||||
<v-text-field v-model="limitPrice" :label="(limitIsMinimum?'Minimum':'Maximum')+' Price'" type="number"
|
||||
variant="outlined" aria-valuemin="0" min="0"
|
||||
clearable :rules="[validateAmount, validateMin]">
|
||||
clearable :rules="[validateAmount, validateMin]" v-auto-select>
|
||||
<template v-slot:append-inner>
|
||||
<v-btn variant="outlined" @click="inverted=!inverted">
|
||||
{{
|
||||
inverted ? pair.tokenB.symbol + '/' + pair.tokenA.symbol : pair.tokenA.symbol + '/' + pair.tokenB.symbol
|
||||
}}
|
||||
{{pairSymbol}}
|
||||
</v-btn>
|
||||
</template>
|
||||
</v-text-field>
|
||||
<!--
|
||||
<v-text-field v-model="minPrice" label="Minimum Price" type="number" variant="outlined" aria-valuemin="0" min="0"
|
||||
clearable :rules="[validateAmount, validateMin]">
|
||||
<template v-slot:append-inner>
|
||||
<v-btn variant="outlined" @click="inverted=!inverted">
|
||||
{{ inverted ? pair.tokenB.symbol + '/' + pair.tokenA.symbol : pair.tokenA.symbol + '/' + pair.tokenB.symbol }}
|
||||
</v-btn>
|
||||
</template>
|
||||
</v-text-field>
|
||||
<v-text-field v-model="maxPrice" label="Maximum Price" type="number" variant="outlined" aria-valuemin="0" min="0"
|
||||
clearable :rules="[validateAmount, validateMax]">
|
||||
<template v-slot:append-inner>
|
||||
<v-btn variant="outlined" @click="inverted=!inverted">
|
||||
{{ inverted ? pair.tokenB.symbol + '/' + pair.tokenA.symbol : pair.tokenA.symbol + '/' + pair.tokenB.symbol }}
|
||||
</v-btn>
|
||||
</template>
|
||||
</v-text-field>
|
||||
-->
|
||||
</div>
|
||||
|
||||
</v-card-text>
|
||||
|
||||
<v-card-actions class="d-flex justify-space-evenly mb-4">
|
||||
<v-btn variant="outlined" color="red">Cancel</v-btn>
|
||||
<v-btn variant="flat" color="green" :disabled="!routes.length">Place Order</v-btn>
|
||||
<v-btn variant="flat" color="green" :disabled="!validOrder">Place Order</v-btn>
|
||||
</v-card-actions>
|
||||
</PhoneCard>
|
||||
</NeedsQueryHelper>
|
||||
@@ -93,33 +84,52 @@
|
||||
<script setup>
|
||||
import {useStore} from "@/store/store";
|
||||
import {computed, ref} from "vue";
|
||||
import PairEntry from "@/components/PairEntry.vue";
|
||||
import TokenChoice from "@/components/TokenChoice.vue"
|
||||
import PhoneCard from "@/components/PhoneCard.vue";
|
||||
import {queryHelperContract} from "@/blockchain/contract.js";
|
||||
import {SingletonCoroutine} from "@/misc.js";
|
||||
import NeedsQueryHelper from "@/components/NeedsQueryHelper.vue";
|
||||
// noinspection ES6UnusedImports
|
||||
import {vAutoSelect} from "@/misc.js";
|
||||
|
||||
const s = useStore()
|
||||
// pair is computed to allow for dynamic computation of a default value based on current chainId
|
||||
const _pair = ref({buy:true})
|
||||
const pair = computed({
|
||||
const buy = ref(false)
|
||||
let _tokenA = ref(s.tokens && s.tokens.length >= 1 ? s.tokens[0] : null)
|
||||
let _tokenB = ref(s.tokens && s.tokens.length >= 2 ? s.tokens[1] : null)
|
||||
const tokenA = computed({
|
||||
get() {
|
||||
console.log('te getpair',_pair.value)
|
||||
return _pair.value
|
||||
return _tokenA.value
|
||||
},
|
||||
set(value) {
|
||||
console.log('set pair',value)
|
||||
_pair.value = value
|
||||
routes.value = []
|
||||
routeFinder.invoke()
|
||||
if( !_tokenA.value || _tokenA.value.address !== value.address ) {
|
||||
_tokenA.value = value
|
||||
routeFinder.invoke()
|
||||
}
|
||||
}
|
||||
})
|
||||
const pairSelected = computed(()=>_pair.value.tokenA && _pair.value.tokenB && routes.value)
|
||||
const base = computed(()=>!pairSelected?{}:_pair.value.tokenA)
|
||||
const quote = computed(()=>!pairSelected?{}:_pair.value.tokenB)
|
||||
const tokenB = computed({
|
||||
get() {
|
||||
return _tokenB.value
|
||||
},
|
||||
set(value) {
|
||||
if( !_tokenB.value || _tokenB.value.address !== value.address ) {
|
||||
_tokenB.value = value
|
||||
routeFinder.invoke()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const pairSymbol = computed(()=>base.value?.symbol+'/'+quote.value?.symbol)
|
||||
const base = computed(()=>{
|
||||
const token = inverted.value ? _tokenB.value : _tokenA.value
|
||||
return !token?{}:token
|
||||
})
|
||||
const quote = computed(()=>{
|
||||
const token = inverted.value ? _tokenA.value : _tokenB.value
|
||||
return !token?{}:token
|
||||
})
|
||||
const routes = ref([])
|
||||
const amount = ref(1)
|
||||
const amount = ref(0)
|
||||
const amountIsBase = ref(false)
|
||||
const amountIsTotal = ref(true)
|
||||
const tranches = ref(3)
|
||||
@@ -131,21 +141,22 @@ const interval = ref(10)
|
||||
const intervalIsTotal = ref(true)
|
||||
const timeUnits = ['minutes', 'hours', 'days']
|
||||
const timeUnitIndex = ref(1)
|
||||
|
||||
const limitIsMinimum = computed(() => !(pair.value.buy ^ inverted.value))
|
||||
const limitIsMinimum = computed(() => !(buy.value ^ inverted.value))
|
||||
const validOrder = computed(()=>amount.value > 0 && routes.value.length > 0 )
|
||||
|
||||
async function findRoute() {
|
||||
if( !pair.value || !pair.value.tokenA || !pair.value.tokenB )
|
||||
return null
|
||||
if( !_tokenA.value || !_tokenB.value ) {
|
||||
routes.value = []
|
||||
return
|
||||
}
|
||||
const helper = await queryHelperContract()
|
||||
console.log('helper',helper)
|
||||
let rawRoutes
|
||||
try {
|
||||
rawRoutes = await helper.getRoutes(pair.value.tokenA.address, pair.value.tokenB.address)
|
||||
rawRoutes = await helper.getRoutes(tokenA.value.address, tokenB.value.address)
|
||||
}
|
||||
catch (e) {
|
||||
routes.value = []
|
||||
console.log('routes exception', e)
|
||||
// console.log('routes exception', e)
|
||||
return
|
||||
}
|
||||
// todo expose all available pools
|
||||
@@ -166,8 +177,8 @@ async function findRoute() {
|
||||
routes.value = [result]
|
||||
}
|
||||
|
||||
const routeFinder = new SingletonCoroutine(findRoute,50)
|
||||
|
||||
const routeFinder = new SingletonCoroutine(findRoute,10)
|
||||
routeFinder.invoke()
|
||||
|
||||
function toggleTimeUnits() {
|
||||
timeUnitIndex.value++
|
||||
@@ -229,6 +240,12 @@ function validateMin(v) {
|
||||
<style scoped lang="scss">
|
||||
@use "@/styles/vars" as *;
|
||||
|
||||
.token-choice {
|
||||
width: 16em;
|
||||
}
|
||||
.bs-button {
|
||||
width: 6em;
|
||||
}
|
||||
.amount {
|
||||
width: 23em;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user