Skip to content

Commit

Permalink
move swap form context
Browse files Browse the repository at this point in the history
  • Loading branch information
SorinC6 committed Apr 16, 2024
1 parent 09f5d6c commit 0664746
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Expand Up @@ -15,6 +15,7 @@ import TopBarLayout from '../../components/layout/TopBarLayout';
import SidebarContainer from '../SidebarContainer';
import NavBarTitle from '../../components/topbar/NavBarTitle';
import NavBarContainerRevamp from '../NavBarContainerRevamp';
import { SwapFormProvider } from './context/swap-form';

type Props = {|
...StoresAndActionsProps,
Expand Down Expand Up @@ -75,7 +76,9 @@ class SwapPageContainer extends Component<AllProps> {
showAsCard
withPadding={false}
>
{children}
<SwapFormProvider swapStore={this.props.stores.substores.ada.swapStore}>
{children}
</SwapFormProvider>
</TopBarLayout>
);
}
Expand Down
Expand Up @@ -6,7 +6,6 @@ import { CreateSwapOrder } from './CreateSwapOrder';
import ConfirmSwapTransaction from './ConfirmSwapTransaction';
import TxSubmittedStep from './TxSubmittedStep';
import LimitOrderWarningDialog from '../../../components/swap/LimitOrderWarningDialog';
import { SwapFormProvider } from '../context/swap-form';
import type { StoresAndActionsProps } from '../../../types/injectedProps.types';
import { useSwap } from '@yoroi/swap';
import { runInAction } from 'mobx';
Expand All @@ -23,6 +22,7 @@ import { HaskellShelleyTxSignRequest } from '../../../api/ada/transactions/shell
import LoadingOverlay from '../../../components/swap/LoadingOverlay';
import { IncorrectWalletPasswordError } from '../../../api/common/errors';
import { observer } from 'mobx-react';
import useSwapForm from '../context/swap-form/useSwapForm';

export const PRICE_IMPACT_MODERATE_RISK = 1;
export const PRICE_IMPACT_HIGH_RISK = 10;
Expand All @@ -45,7 +45,9 @@ function SwapPage(props: StoresAndActionsProps): Node {
limitPrice: orderLimitPrice,
},
frontendFeeTiersChanged,
orderData,
} = useSwap();
const { sellTokenInfo, buyTokenInfo } = useSwapForm();

const isMarketOrder = orderType === 'market';
const impact = isMarketOrder ? Number(selectedPoolCalculation?.prices.priceImpact ?? 0) : 0;
Expand All @@ -58,9 +60,13 @@ function SwapPage(props: StoresAndActionsProps): Node {
const [signRequest, setSignRequest] = useState<?HaskellShelleyTxSignRequest>(null);
const userPasswordState = StateWrap(useState<string>(''));
const txSubmitErrorState = StateWrap(useState<?Error>(null));
const isValidTickers = sellTokenInfo?.ticker && buyTokenInfo?.ticker;

const swapFormCanContinue =
selectedPoolCalculation != null && sell.quantity !== '0' && buy.quantity !== '0';
selectedPoolCalculation != null &&
sell.quantity !== '0' &&
buy.quantity !== '0' &&
isValidTickers;

const confirmationCanContinue = userPasswordState.value !== '' && signRequest != null;

Expand Down Expand Up @@ -277,7 +283,7 @@ function SwapPage(props: StoresAndActionsProps): Node {
};

return (
<SwapFormProvider swapStore={props.stores.substores.ada.swapStore}>
<>
<Box display="flex" flexDirection="column" height="100%">
<Box
sx={{ flexGrow: '1', overflowY: 'auto', p: '24px' }}
Expand Down Expand Up @@ -378,7 +384,7 @@ function SwapPage(props: StoresAndActionsProps): Node {
}}
/>
)}
</SwapFormProvider>
</>
);
}

Expand Down

0 comments on commit 0664746

Please sign in to comment.