From 9ba72f491d697339f9872ec05fd0f0a8aa9cd1df Mon Sep 17 00:00:00 2001 From: WhidRubeld Date: Thu, 9 Sep 2021 16:28:53 +0300 Subject: [PATCH] force trends integration --- src/hooks/index.ts | 1 + src/hooks/useForceTrends.ts | 41 +++++++++++++++++ src/screens/Stats/extra/InfoTable.tsx | 65 ++++++++++++++++++++++----- 3 files changed, 97 insertions(+), 10 deletions(-) create mode 100644 src/hooks/useForceTrends.ts diff --git a/src/hooks/index.ts b/src/hooks/index.ts index 51e5d3b..dd7c5c9 100644 --- a/src/hooks/index.ts +++ b/src/hooks/index.ts @@ -18,5 +18,6 @@ export { default as useAppState } from './useAppState' export { default as useTickSocket } from './useTickSocket' export { default as useIntervalTicks } from './useIntervalTicks' export { default as useTractionForce } from './useTractionForce' +export { default as useForceTrends } from './useForceTrends' export const useDispatch = () => useDefaultDispatch() diff --git a/src/hooks/useForceTrends.ts b/src/hooks/useForceTrends.ts new file mode 100644 index 0000000..b86048c --- /dev/null +++ b/src/hooks/useForceTrends.ts @@ -0,0 +1,41 @@ +import { IPair } from '@interfaces' +import { useMemo } from 'react' + +const TRENDS = ['USDT', 'BTC'] + +export default function useForceTrends( + data: { + pair: IPair + force: number | null + }[] +) { + const results = useMemo(() => { + return TRENDS.map((v) => { + const forces = data + .filter((k) => { + const { pair, force } = k + const { symbol } = pair + const mainCurrency = symbol.substr( + symbol.length - v.length, + symbol.length - 1 + ) + + return mainCurrency === v && !!force + }) + .map((v) => v.force as number) + + const force = forces.length + ? forces.reduce((prev, curr) => { + return prev + curr + }, 0) / forces.length + : null + + return { + currency: v, + force, + } + }) + }, [data]) + + return results +} diff --git a/src/screens/Stats/extra/InfoTable.tsx b/src/screens/Stats/extra/InfoTable.tsx index 01637bd..4f1c3a4 100644 --- a/src/screens/Stats/extra/InfoTable.tsx +++ b/src/screens/Stats/extra/InfoTable.tsx @@ -1,6 +1,11 @@ -import { ActivityIndicator, Card, DataTable, Text } from '@components' +import { ActivityIndicator, Card, DataTable, Text, Title } from '@components' import { unix2time } from '@helpers' -import { useTheme, useTickSocket, useTractionForce } from '@hooks' +import { + useForceTrends, + useTheme, + useTickSocket, + useTractionForce, +} from '@hooks' import React from 'react' import { View, StyleSheet } from 'react-native' @@ -15,31 +20,66 @@ export default function InfoTable() { return Math.abs(a.force || 0) - Math.abs(b.force || 0) }) + const trends = useForceTrends(res) + + const forceColor = (force: number | null) => { + if (force === null) return colors.text + if (force > 0) return 'green' + if (force < 0) return 'red' + return 'orange' + } + if (!res.length) return null return ( <> + + Тренд MA (4 ч.) + + + + + Валюта + Сила тяги + + + {trends.map((v) => { + return ( + + {v.currency} + + + {v.force !== null ? `${v.force.toFixed(3)}` : '-'} + + + + ) + })} + + + + Тренды по парам (4 ч.) + Валютная пара - Сила тяги (4h) + Сила тяги {res.map((v) => { - const color = () => { - if (v.force === null) return colors.text - if (v.force > 0) return 'green' - if (v.force < 0) return 'red' - return 'orange' - } return ( {v.pair.symbol} @@ -83,6 +123,11 @@ export default function InfoTable() { } const styles = StyleSheet.create({ + title: { + fontWeight: '200', + marginTop: 10, + marginBottom: 5, + }, table: { position: 'relative', marginBottom: 5,