From 491ce02e13a1038968af793682108bb81306d1b0 Mon Sep 17 00:00:00 2001 From: vantuz-subhuman Date: Tue, 21 Nov 2023 12:52:46 +0300 Subject: [PATCH] flow fixes --- .../app/components/swap/PriceInput.js | 9 +++------ .../app/components/swap/SwapInput.js | 7 +------ .../app/components/swap/types.js | 7 +++++++ .../containers/swap/asset-swap/SwapForm.js | 19 ++++++++++++------- 4 files changed, 23 insertions(+), 19 deletions(-) create mode 100644 packages/yoroi-extension/app/components/swap/types.js diff --git a/packages/yoroi-extension/app/components/swap/PriceInput.js b/packages/yoroi-extension/app/components/swap/PriceInput.js index 04c91031c6..1ff346c554 100644 --- a/packages/yoroi-extension/app/components/swap/PriceInput.js +++ b/packages/yoroi-extension/app/components/swap/PriceInput.js @@ -1,11 +1,8 @@ // @flow import type { Node } from 'react'; import { Box, Typography } from '@mui/material'; - -type AssetAmount = {| - ticker: string, - amount: number, -|}; +import type { AssetAmount } from './types' +import { BigNumber } from 'bignumber.js'; type Props = {| label: string, @@ -64,7 +61,7 @@ export default function PriceInput({ placeholder="0" bgcolor={readonly ? 'grayscale.50' : 'common.white'} readOnly={readonly} - value={baseCurrency.amount / quoteCurrency.amount || 0} + value={(new BigNumber(baseCurrency.amount)).div(quoteCurrency.amount).toString()} /> diff --git a/packages/yoroi-extension/app/components/swap/SwapInput.js b/packages/yoroi-extension/app/components/swap/SwapInput.js index dda9d56dd9..f97f144a84 100644 --- a/packages/yoroi-extension/app/components/swap/SwapInput.js +++ b/packages/yoroi-extension/app/components/swap/SwapInput.js @@ -4,12 +4,7 @@ import { useState } from 'react'; import { Box, Typography } from '@mui/material'; import { ReactComponent as ChevronDownIcon } from '../../assets/images/revamp/icons/chevron-down.inline.svg'; import { ReactComponent as DefaultTokenImage } from '../../assets/images/revamp/token-default.inline.svg'; - -type AssetAmount = {| - ticker: string, - amount: number, - walletAmount: number, -|}; +import type { AssetAmount } from './types'; type Props = {| label: string, diff --git a/packages/yoroi-extension/app/components/swap/types.js b/packages/yoroi-extension/app/components/swap/types.js new file mode 100644 index 0000000000..f59a54c91d --- /dev/null +++ b/packages/yoroi-extension/app/components/swap/types.js @@ -0,0 +1,7 @@ +//@flow + +export type AssetAmount = {| + ticker: string, + amount: string, + walletAmount: number, +|}; \ No newline at end of file diff --git a/packages/yoroi-extension/app/containers/swap/asset-swap/SwapForm.js b/packages/yoroi-extension/app/containers/swap/asset-swap/SwapForm.js index 97f93bd42b..f6d067382c 100644 --- a/packages/yoroi-extension/app/containers/swap/asset-swap/SwapForm.js +++ b/packages/yoroi-extension/app/containers/swap/asset-swap/SwapForm.js @@ -1,4 +1,5 @@ // @flow +import type { Node } from 'react'; import { useState } from 'react'; import { Box, Button, Typography } from '@mui/material'; import { ReactComponent as SwitchIcon } from '../../../assets/images/revamp/icons/switch.inline.svg'; @@ -8,18 +9,22 @@ import { ReactComponent as UsdaTokenImage } from './usda.inline.svg'; import SwapInput from '../../../components/swap/SwapInput'; import PriceInput from '../../../components/swap/PriceInput'; -const defaultFromAsset = { amount: '', walletAmount: 212, ticker: 'TADA' }; -const defaultToAsset = { amount: '', walletAmount: 0, ticker: '' }; +const defaultFromAsset = { + amount: '', + ticker: 'TADA', + walletAmount: 212, +}; +const defaultToAsset = { + amount: '', + ticker: '', + walletAmount: 0, +}; -export default function SwapForm() { +export default function SwapForm(): Node { const [isMarketOrder, setIsMarketOrder] = useState(true); const [fromAsset, setFromAsset] = useState(defaultFromAsset); const [toAsset, setToAsset] = useState(defaultToAsset); - // - // eslint-disable-next-line no-unused-vars - const handleOpenedDialog = type => setOpenedDialog(type); - const handleSwitchSelectedAssets = () => { setFromAsset(toAsset); setToAsset(fromAsset);