From 5d3d1d6f5a059ed7ee63d6aeef2c7ed6dfdbb10d Mon Sep 17 00:00:00 2001 From: tim Date: Tue, 29 Oct 2024 16:30:05 -0400 Subject: [PATCH] fill notifications and chart autoupdate --- src/blockchain/uniswap.js | 2 +- src/charts/ordershapes.js | 2 -- src/components/Status.vue | 4 +++ src/notify.js | 51 +++++++++++++++++++++++++++++++++++++++ src/socket.js | 14 ++++++++--- 5 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 src/notify.js diff --git a/src/blockchain/uniswap.js b/src/blockchain/uniswap.js index ea4969c..46f189d 100644 --- a/src/blockchain/uniswap.js +++ b/src/blockchain/uniswap.js @@ -31,7 +31,7 @@ export function uniswapV3PoolAddress(chainId, tokenAddrA, tokenAddrB, fee) { export function uniswapV3AveragePrice(amountIn, amountOut, fee) { if (amountIn === 0n || amountOut === 0n) return null - const fmtX18 = {decimals: 18, width: 256, signed: false}; + const fmtX18 = {decimals: 18, width: 512, signed: false}; let result = FixedNumber.fromValue(amountOut, 0, fmtX18) .div(FixedNumber.fromValue(amountIn, 0, fmtX18)).toUnsafeFloat() result /= (1 - fee / 1_000_000) // adjust for pool fee diff --git a/src/charts/ordershapes.js b/src/charts/ordershapes.js index fdebd54..355153f 100644 --- a/src/charts/ordershapes.js +++ b/src/charts/ordershapes.js @@ -13,14 +13,12 @@ export class OrderShapes { } update(orderStatus) { - // todo delete old shapes for (const old of this.trancheShapes) old.delete() this.status = orderStatus this.trancheShapes = []; for (let i = 0; i < orderStatus.trancheStatus.length; i++) this.trancheShapes.push(new TrancheShapes(this.symbol, this.status, i)); - // todo TV shape group } show() {for (const t of this.trancheShapes) t.show();} diff --git a/src/components/Status.vue b/src/components/Status.vue index bbdb8be..ee810f4 100644 --- a/src/components/Status.vue +++ b/src/components/Status.vue @@ -373,6 +373,10 @@ const orders = computed(()=>{ } result.sort((a,b)=>b.startTime-a.startTime) // console.log('orders', result) + for( const st of result ) { + if( st.id in orderShapes ) + orderShapes[st.id].update(st) + } return result }) diff --git a/src/notify.js b/src/notify.js new file mode 100644 index 0000000..7206361 --- /dev/null +++ b/src/notify.js @@ -0,0 +1,51 @@ +/* + * Copyright ©2024 Dexorder LLC. All Rights Reserved. + */ + +import {getToken} from "@/blockchain/token.js"; + +let native = false // whether native browser notifications are allowed + +Notification.requestPermission() + .then(permission => { + console.log(`notification permission: ${permission}`); + native = permission === 'granted' + }) + .catch(error => { + console.error(`notification permission error: ${error}`); + native = false; + }); + + +export function notify(title, message=null) { + if (native) { + const options = { + renotify: true, + tag: title, + } + if (message!==null) + options.body = message + new Notification(title, options) + } + console.log('notify:', title, message) +} + + +export async function notifyFillEvent(chainId, status, trancheIndex, fill) { + let low = status.order.tokenIn + let high = status.order.tokenOut + if (high{ let filledIn = 0n let filledOut = 0n const [activationTime, fills] = filled[i]; - ts.fills = [] - for (const fill of fills) { + const numOld = ts.fills.length; + for (let i=0; iconsole.log('fill notification error', e)) + ts.fills.push(f) + } } ts.filledIn = filledIn ts.filledOut = filledOut