From bb10145f5633f7b543fe9656ac7b0321e7b7c5c3 Mon Sep 17 00:00:00 2001 From: wireless_purple Date: Tue, 6 Aug 2024 00:15:47 +0000 Subject: [PATCH] optimizations --- bun.lockb | Bin 48922 -> 50698 bytes package.json | 2 +- src/lib/server/context.js | 42 +++- src/routes/+layout.svelte | 294 ++++++++++++------------ src/routes/+page.server.js | 4 +- src/routes/+page.svelte | 127 +++++----- src/routes/market/[market]/+page.svelte | 108 +++++---- svelte.config.js | 4 +- 8 files changed, 304 insertions(+), 277 deletions(-) diff --git a/bun.lockb b/bun.lockb index d83674ac973d999628e717eecdfeed35a252ac92..53fc12bb9c9f39cf2ba4b7ff5ab9cf061fe2a3d8 100755 GIT binary patch delta 6851 zcmeHMdt6jUmcF-XurJaAqCnF;1q2@;&>$#Clf*=!1#DjpA~FaKqCB(_e4*W_C?KeK ze1Sp5P2yuRM#Ur=b)#d9U}BV+b#~1p8Z$b|WaDUDGn$EHzPjC)&g7Tu?qB=Y-XGun z&N+3eZr!T7r>YNaeX_O#QD0sMo zRo?(+dL8U;;H6;JUZHVuRemYQEr70so@--0*d+vpmze-g1UrMHZCp@U8L`Aaqw+5rMb%51-DW&oOW=FwVr#!#BqNI@HjFt1MN=gg4H3O}kDg}F@)+`&R*m$Ik zhk{wBdGHYM*XRJ_8#caZ<6|~%w{e4&&6X;gVIJ566*Fy|WaAMw_5!o+JKFd$I?nXl zHoj_OQ$=ZM)gq4bK`;DJ-iJngnID+xU0^l~hr#}sJj;3rY!r*Yf#Atv0cQyX2SaxN z4+G!9(*nR3ZF~Ui553-|mx9@Y^k6pKMHp{)@C@6ykAe|>v=oZYX+ z{UDAT4zj*QuXfxn9^bsf`}C&eH@8e|)PVaJ)Q$TD5}dXCtCWiSm(<{_6-LTAZX!A$ zrxxdUzMO=CT46tIFT&yt48`OZi4|U_7PQoCq@cICbOF>N;>0RQ5yU?asd!UFHk`x>l zCAR90{_G&ZRm*=uskpmR1Mb<>jr%SV+_a9ZnD-1)x+OZ^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Ggk(xe1JWRVDvtws?`mxMxE<7CLpY*nT;ne5BqZFw{rRh_J>GcPF zdi?8zYyNC_GEg3#YO?LvDii2niNqQ_?B z*0xNe_u2zG%-q4EJI`GEIP;r{ibRXtdC}ez)E*=qtF8KG(e=Q>j^tlFG;yRXg9XdZ zzlq{^Wjf4sLu1?YdoMqov{~zQ8uxk%t=eVJzNqT+aQ*t5N1xAlW1>Z-rDmk3W(#5d z&#yT@`Bc`Rx-SBr&*+U^c88f4xb%6~sS%^5{YSuWrLT9{WfX<(wmZzM!c)&~S#jGs z`n^C@9=Uhhv&}4oby)7$b8`PX0l%52xIB2~!JmFv_g28OkvdSbnb>$s+@6+vOUVoP zpQ1~zY9cNr=cD8Y%`5=`8$8?=961en>EFMd4Q`t47q{wm<{(p_}G%+~DN>Rhm; z`P-C${|Ke;vCH%1*<*K@$)4zq#q#sb*ZhH~uc&2@J=;tUwKg2N|F^CAwt&9~TMD0c zFMl8N(O&_CZ zf8|Sy6q)FxLG+;0%`@ zJEbH4qy=bum6?j#JgDr*L%W}@hsW5((D<4C%bYE7`pG`^{eL|4*_)BP&1I!#a^0Cen_B%an16bo*e2)?A_DPNdb{8B&`ey3jq2Yx}qExRGWi zYjfA7g@Z4~9aW@1kzx+ban4KDGfba#%0Kj* zg9l=BuRa+FFtb(e@y}XUd=&Flz;ia4J~7DRIAmC;)g&&SgGV@_` z_vCFmQ*bje5O85XdVuS~ewuMOFXT%@-S$g5aCmu7*pZhUJ;CQnReJ2zoSyPa&sqKp D?Hc+h diff --git a/package.json b/package.json index 30be46e..273bf68 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "@sveltejs/kit": "^2.5.20", "@sveltejs/vite-plugin-svelte": "^3.1.1", "sass": "^1.77.8", - "svelte": "^4.2.18", + "svelte": "^5.0.0-next.210", "svelte-adapter-bun": "^0.5.2", "svelte-preprocess": "^6.0.2", "vite": "^5.3.5" diff --git a/src/lib/server/context.js b/src/lib/server/context.js index 947d18e..f2b690c 100644 --- a/src/lib/server/context.js +++ b/src/lib/server/context.js @@ -1,10 +1,15 @@ import { watch } from "fs"; -import { writable } from "svelte/store"; +import { derived, writable } from "svelte/store"; const offers = writable([]); const trades = writable([]); const crypto = writable([]); const fiat = writable([]); +const liquidity = derived(offers, ($offers) => + Object.values($offers) + .flat() + .reduce((a, b) => a + Number.parseInt(b.amount), 0), +); const formatTrades = (e) => { return e.map((e) => { @@ -20,11 +25,26 @@ const formatTrades = (e) => { }); }; const formatOffers = (e) => { - return Object.groupBy(e, ({ currencyCode }) => currencyCode); + return Object.groupBy( + e.map((e) => { + return { + direction: e.direction, + currencyCode: e.currencyCode, + amount: e.amount, + price: e.price, + paymentMethod: e.paymentMethod, + primaryMarketAmount: e.primaryMarketAmount, + }; + }), + ({ currencyCode }) => currencyCode, + ); }; const formatCrypto = (e) => { - e[e.findIndex((e) => e.code === "XMR")].precision = 12; - e[e.findIndex((e) => e.code === "XMR")].sign = "ɱ"; + e.push({ + precision: 12, + code: "XMR", + sign: "ɱ", + }); return e; }; const formatFiat = (e) => { @@ -47,16 +67,16 @@ Bun.file(`${import.meta.env.VITE_DB_PATH}trade_statistics.json`) .then((j) => { trades.set(formatTrades(j)); }); -Bun.file(`${import.meta.env.VITE_DB_PATH}crypto_currency_list.json`) - .json() - .then((j) => { - crypto.set(formatCrypto(j)); - }); -Bun.file(`${import.meta.env.VITE_DB_PATH}/traditional_currency_list.json`) +Bun.file(`${import.meta.env.VITE_DB_PATH}active_traditional_currency_list.json`) .json() .then((j) => { fiat.set(formatFiat(j)); }); +Bun.file(`${import.meta.env.VITE_DB_PATH}active_crypto_currency_list.json`) + .json() + .then((j) => { + crypto.set(formatCrypto(j)); + }); const watcher = watch(import.meta.env.VITE_DB_PATH, async (_, filename) => { const file = Bun.file(import.meta.env.VITE_DB_PATH + filename); @@ -84,4 +104,4 @@ process.on("SIGINT", () => { process.exit(0); }); -export { offers, trades, crypto, fiat }; +export { offers, trades, crypto, fiat, liquidity }; diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index abe104d..9a6d9ae 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -15,153 +15,153 @@ Object.groupBy ||= (values, keyFinder) => { \ No newline at end of file diff --git a/src/routes/+page.server.js b/src/routes/+page.server.js index 84f7fa0..6512e33 100644 --- a/src/routes/+page.server.js +++ b/src/routes/+page.server.js @@ -1,6 +1,6 @@ -import { offers, trades } from "$lib/server/context"; +import { liquidity, trades } from "$lib/server/context"; import { get } from "svelte/store"; export function load() { - return { trades: get(trades), offers: get(offers) }; + return { trades: get(trades), liquidity: get(liquidity) }; } diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 0be8b67..e6a4da3 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -111,9 +111,6 @@ const gridLayout = { }, }; let w; -const liquidity = Object.values(data.offers) - .flat() - .reduce((a, b) => a + Number.parseInt(b.amount), 0); @@ -125,77 +122,81 @@ const liquidity = Object.values(data.offers)

XMR/USD

{formatPrice(grouped["USD"][0].price, "USD", true)} -
-

Liquidity

- {formatPrice(liquidity, "XMR", true, false)} -
+
+

Liquidity

+ {formatPrice(data.liquidity, "XMR", true, false)} +
-
-

Price XMR/

+
+

Price XMR/

- - - - -
-
-

- Volume

- - - - - - - + + - -
+ +
+
+

+ Volume

+ + + + + + + + + +
-

Markets

- - - - - - - {#each Object.values(Object.groupBy(data.trades, ({currency}) => currency)).toSorted((a,b) => b.length - a.length || (b[0].currency < a[0].currency ? 1 : -1)).slice(0, 16) as market} - - - - - - {/each} -
CurrencyPriceTrades
{getAsset(market[0].currency).name} ({market[0].currency}){formatPrice(market[0].price, market[0].currency, true, false)}{market.length}
-

View more »

+

Markets

+ + + + + + + + {#each Object.values(Object.groupBy(data.trades, ({currency}) => currency)).toSorted((a,b) => b.length - a.length || (b[0].currency < a[0].currency ? 1 : -1)).slice(0, 16) as market} + + + + + + {/each} + +
CurrencyPriceTrades
{getAsset(market[0].currency).name} ({market[0].currency}){formatPrice(market[0].price, market[0].currency, true, false)}{market.length}
+

View more »

-

Trades

+

Trades

- - - - - - {#each data.trades.slice(0, 16) as trade} - - - - - - {/each} + + + + + + + {#each data.trades.slice(0, 16) as trade} + + + + + + {/each} +
DateAmount (XMR)Amount
{new Date(trade.date).toISOString().replace("T", " ").replace(/\.\d*Z/, "")}{formatPrice(trade.xmrAmount, "XMR", false, false)}{formatPrice(trade.amount, trade.currency, false, false)} {trade.currency}
DateAmount (XMR)Amount
{new Date(trade.date).toISOString().replace("T", " ").replace(/\.\d*Z/, "")}{formatPrice(trade.xmrAmount, "XMR", false, false)}{formatPrice(trade.amount, trade.currency, false, false)} {trade.currency}

View more »

diff --git a/src/routes/market/[market]/+page.svelte b/src/routes/market/[market]/+page.svelte index 92b4e77..7e486fc 100644 --- a/src/routes/market/[market]/+page.svelte +++ b/src/routes/market/[market]/+page.svelte @@ -71,69 +71,75 @@ const BUY_SELL = isMoneroQuote(market) ? ["SELL", "BUY"] : ["BUY", "SELL"]; {marketPair} - Haveno Markets
-
-

{marketPair}

- {formatPrice(data.trades?.[0]?.price, market, true, false)} - - - - -
+
+

{marketPair}

+ {formatPrice(data.trades?.[0]?.price, market, true, false)} + + + + +

Buy Offers

- - - - - - {#each data.offers[BUY_SELL[0]]?.toSorted((a,b) => a.price < b.price ? 1 : -1)||[] as offer} - - - - - - {/each} + + + + + + + {#each data.offers[BUY_SELL[0]]?.toSorted((a,b) => a.price < b.price ? 1 : -1)||[] as offer} + + + + + + {/each} +
PriceAmount (XMR)Amount ({market})
{formatPrice(offer.price, market, false, false)}{formatPrice(offer.amount, "XMR", false, false)}{formatPrice(offer.primaryMarketAmount, market, false, false)}
PriceAmount (XMR)Amount ({market})
{formatPrice(offer.price, market, false, false)}{formatPrice(offer.amount, "XMR", false, false)}{formatPrice(offer.primaryMarketAmount, market, false, false)}

Sell Offers

- - - - - - {#each data.offers[BUY_SELL[1]]?.toSorted((a,b) => a.price > b.price ? 1 : -1)||[] as offer} - - - - - - {/each} + + + + + + + {#each data.offers[BUY_SELL[1]]?.toSorted((a,b) => a.price > b.price ? 1 : -1)||[] as offer} + + + + + + {/each} +
PriceAmount (XMR)Amount ({market})
{formatPrice(offer.price, market, false, false)}{formatPrice(offer.amount, "XMR", false, false)}{formatPrice(offer.primaryMarketAmount, market, false, false)}
PriceAmount (XMR)Amount ({market})
{formatPrice(offer.price, market, false, false)}{formatPrice(offer.amount, "XMR", false, false)}{formatPrice(offer.primaryMarketAmount, market, false, false)}
-
-

Last Trades

- - - - - - - - {#each data.trades as trade} - - - - - - - {/each} -
DatePriceAmount (XMR)Amount ({market})
{new Date(trade.date).toISOString().replace("T", " ").replace(/\.\d*Z/, "")}{formatPrice(trade.price, trade.currency, false, false)}{formatPrice(trade.xmrAmount, "XMR", false, false)}{formatPrice(trade.amount, trade.currency, false, false)}
-
+
+

Last Trades

+ + + + + + + + + {#each data.trades as trade} + + + + + + + {/each} + +
DatePriceAmount (XMR)Amount ({market})
{new Date(trade.date).toISOString().replace("T", " ").replace(/\.\d*Z/, "")}{formatPrice(trade.price, trade.currency, false, false)}{formatPrice(trade.xmrAmount, "XMR", false, false)}{formatPrice(trade.amount, trade.currency, false, false)}
+
\ No newline at end of file diff --git a/svelte.config.js b/svelte.config.js index f6c3133..7e91979 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -1,12 +1,12 @@ import adapter from "svelte-adapter-bun"; -import preprocess from "svelte-preprocess"; +import { sveltePreprocess } from "svelte-preprocess"; /** @type {import('@sveltejs/kit').Config} */ const config = { kit: { adapter: adapter(), }, - preprocess: [preprocess()], + preprocess: sveltePreprocess(), }; export default config;