-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ca2a9be
commit 9ba72f4
Showing
3 changed files
with
97 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters