diff --git a/src/components/coin-analytics.tsx b/src/components/coin-analytics.tsx index f1e68ee..9680f3b 100644 --- a/src/components/coin-analytics.tsx +++ b/src/components/coin-analytics.tsx @@ -1,5 +1,6 @@ import { loadAllAssetActionsBySymbol, + queryAssetMaxAmountBySymbol, queryLastAssetsBySymbol, updateAssetPrice, } from "@/middlelayers/charts"; @@ -80,6 +81,8 @@ const App = ({ const [updatePriceValue, setUpdatePriceValue] = useState(-1); const [updatePriceDialogOpen, setUpdatePriceDialogOpen] = useState(false); + const [maxPosition, setMaxPosition] = useState(0); + const [walletAliasMap, setWalletAliasMap] = useState<{ [k: string]: string | undefined; }>({}); @@ -153,18 +156,14 @@ const App = ({ [currency, latestPrice] ); - const currentValue = useMemo(() => latestAsset?.value || 0, [latestAsset]); - const currentValueStr = useMemo( - () => - currency.symbol + - prettyNumberToLocaleString(currencyWrapper(currency)(currentValue)), - [currency, currentValue] - ); + const rank = useMemo(() => { + const rankNum = _(allowSymbols).indexOf(symbol) + 1; + if (rankNum === 0) { + return "-"; + } - const rank = useMemo( - () => latestAsset?.amount.toFixed(10).replace(/0+$/, "") || 0, - [latestAsset] - ); + return "#" + rankNum; + }, [symbol, allowSymbols]); const profitStr = useMemo( () => @@ -190,6 +189,10 @@ const App = ({ setLatestAsset(res); }); + queryAssetMaxAmountBySymbol(s).then((res) => { + setMaxPosition(res); + }); + getLogoPath(s).then((res) => { setLogo(res); }); @@ -344,7 +347,7 @@ const App = ({

- amount: {rank} + rank: {rank}

@@ -373,7 +376,7 @@ const App = ({ {breakEvenPriceStr}

- profit rate: {profitRate}% + latest price: {latestPriceStr}

@@ -401,7 +404,7 @@ const App = ({ {profitStr}

- current value: {currentValueStr} + profit rate: {profitRate}%

@@ -428,7 +431,7 @@ const App = ({ {costPriceStr}

- latest price: {latestPriceStr} + max pos: {maxPosition.toFixed(8).replace(/0+$/, "")}

diff --git a/src/middlelayers/charts.ts b/src/middlelayers/charts.ts index 1f7937b..df4b7fd 100644 --- a/src/middlelayers/charts.ts +++ b/src/middlelayers/charts.ts @@ -164,6 +164,11 @@ async function queryAssets(size = 1, symbol?: string): Promise { return _(assets).groupBy("createdAt").values().value() } +export async function queryAssetMaxAmountBySymbol(symbol: string): Promise { + const res = await queryMaxAmountBySymbol(symbol) || 0 + return res +} + // return all asset prices for all symbols export function queryAllAssetPrices(): Promise { return queryAssetPrices() @@ -225,6 +230,14 @@ export async function queryLastAssetsBySymbol(symbol: string): Promise { + const db = await getDatabase() + const sql = `SELECT sum(amount) as amount FROM ${ASSETS_TABLE_NAME} WHERE symbol = ? GROUP BY uuid ORDER BY amount DESC LIMIT 1` + const models = await db.select<{ amount: number }[]>(sql, [symbol]) + + return models[0]?.amount +} + export async function queryAssetsAfterCreatedAt(createdAt?: number): Promise { const db = await getDatabase() const ts = createdAt ? new Date(createdAt).toISOString() : new Date(0).toISOString()