From 085aad8ffd5d3c4aa8166996b419402b1205b7ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Sim=C3=A3o?= Date: Wed, 9 Feb 2022 19:15:26 +0100 Subject: [PATCH] Created CryptoInput component --- src/components/CryptoInput/index.tsx | 104 +++++++++++++++++++++++++++ src/components/CryptoInput/types.ts | 11 +++ src/components/CryptoInput/utils.ts | 5 ++ 3 files changed, 120 insertions(+) create mode 100644 src/components/CryptoInput/index.tsx create mode 100644 src/components/CryptoInput/types.ts create mode 100644 src/components/CryptoInput/utils.ts diff --git a/src/components/CryptoInput/index.tsx b/src/components/CryptoInput/index.tsx new file mode 100644 index 0000000..cc63581 --- /dev/null +++ b/src/components/CryptoInput/index.tsx @@ -0,0 +1,104 @@ +import * as React from 'react' +import { Box, Text, TextInput, Button } from 'grommet' + +import { fetchFiatValue } from 'src/components/CryptoInput/utils' +import * as t from './types' + +export const CryptoInput: React.FC = ({ + value, + maxValue, + onChange, + onChangeCurrency, +}) => { + const [currency, setCurrency] = React.useState( + t.CurrencyTypeEnum.NEAR + ) + const [fiatValue, setFiatValue] = React.useState(0) + + const updateFiatValues = async () => { + const newFiatValue = await fetchFiatValue() + const newTotalFiatValue = newFiatValue * Number(value) + setFiatValue(newTotalFiatValue) + } + + // Todo: make a redux value for it, updated every X minutes + React.useEffect(() => { + updateFiatValues() + }, [value]) + return ( + + + { + onChange(e?.target?.value) + }} + /> + {maxValue ? ( +