From 0b9285bc0a0437002178ac0f6175011b58d36003 Mon Sep 17 00:00:00 2001 From: Daniel Espendiller Date: Tue, 13 Aug 2024 18:28:10 +0200 Subject: [PATCH] update to vue.js 3 --- templates/trades.html.twig | 10 ++-- web/static/js/trades.js | 49 ++++++++-------- web/static/js/trades.vue | 116 ++++++++++++++++++++++++++++--------- 3 files changed, 119 insertions(+), 56 deletions(-) diff --git a/templates/trades.html.twig b/templates/trades.html.twig index 798549c75..2a717aeaf 100644 --- a/templates/trades.html.twig +++ b/templates/trades.html.twig @@ -3,9 +3,9 @@ {% block title %}Trades | Crypto Bot{% endblock %} {% block javascript %} - - - + + + {% endblock %} {% block content %} @@ -30,11 +30,11 @@ -
+
- +
diff --git a/web/static/js/trades.js b/web/static/js/trades.js index 023ee7960..5cd092d3a 100644 --- a/web/static/js/trades.js +++ b/web/static/js/trades.js @@ -1,30 +1,31 @@ -Vue.filter('filter_price', function(value) { - if (parseFloat(value) < 1) { - return Intl.NumberFormat('en-US', { - useGrouping: false, - minimumFractionDigits: 2, - maximumFractionDigits: 6 - }).format(value); - } +const options = { + moduleCache: { + vue: Vue + }, - return Intl.NumberFormat('en-US', { - useGrouping: false, - minimumFractionDigits: 2, - maximumFractionDigits: 2 - }).format(value); -}); + getFile(url) { + return fetch(url).then(response => (response.ok ? response.text() : Promise.reject(response))); + }, -Vue.filter('round', function(value, decimalPlaces = 0) { - return value.toFixed(decimalPlaces); -}); + addStyle(styleStr) { + const style = document.createElement('style'); + style.textContent = styleStr; + const ref = document.head.getElementsByTagName('style')[0] || null; + document.head.insertBefore(style, ref); + }, -Vue.filter('date', function(value) { - return new Date(value).toLocaleString(); -}); + log(type, ...args) { + console.log(type, ...args); + } +}; + +const { loadModule, version } = window['vue3-sfc-loader']; -new Vue({ - el: '#vue-trades', +const app = Vue.createApp({ components: { - 'trades': httpVueLoader('js/trades.vue') - } + 'my-component': Vue.defineAsyncComponent(() => loadModule('./js/trades.vue', options)) + }, + template: `` }); + +app.mount('#vue-trades'); diff --git a/web/static/js/trades.vue b/web/static/js/trades.vue index 3ebf5c0d7..e6331f8d1 100644 --- a/web/static/js/trades.vue +++ b/web/static/js/trades.vue @@ -4,7 +4,7 @@

Positions

{{ positionsUpdatedAt }}
- +
@@ -31,30 +31,30 @@ - + - - + +
- {{ position.position.profit|round(2) }} % + {{ round(position.position.profit, 2) }} % @@ -77,7 +77,7 @@
-

Orders

{{ ordersUpdatedAt }}
+

Orders

{{ ordersUpdatedAt }}
@@ -106,12 +106,12 @@
{{ order.order.symbol }} {{ order.order.type }} {{ order.order.id }}{{ order.order.price }} {{ order.percent_to_price|round(1) }} %{{ order.order.price }} {{ round(order.percent_to_price, 1) }} % {{ order.order.amount }} {{ order.order.retry }} {{ order.order.ourId }}{{ order.order.createdAt|date('d.m.y H:i') }}{{ order.order.updatedAt|date('d.m.y H:i') }}{{ date(order.order.createdAt, 'd.m.y H:i') }}{{ date(order.order.updatedAt, 'd.m.y H:i') }} {{ order.order.status }} @@ -130,19 +130,22 @@ - +