Fix book table in the v0.6.0 version (#1083)

* Get favorites from context

* Rerender objects on favorite mode change

* Format sats amount in millionths
This commit is contained in:
aftermath 2024-01-22 09:27:02 +00:00 committed by GitHub
parent 876846aa3a
commit 5cdaf93908
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 18 deletions

View File

@ -1,4 +1,4 @@
import React, { useMemo } from 'react'; import React, { useContext, useMemo } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { import {
Typography, Typography,
@ -16,26 +16,24 @@ import { useTheme } from '@mui/system';
import { AutocompletePayments } from '../MakerForm'; import { AutocompletePayments } from '../MakerForm';
import { fiatMethods, swapMethods, PaymentIcon } from '../PaymentMethods'; import { fiatMethods, swapMethods, PaymentIcon } from '../PaymentMethods';
import { FlagWithProps } from '../Icons'; import { FlagWithProps } from '../Icons';
import { AppContext, type UseAppStoreType } from '../../contexts/AppContext';
import CheckBoxOutlineBlankIcon from '@mui/icons-material/CheckBoxOutlineBlank'; import CheckBoxOutlineBlankIcon from '@mui/icons-material/CheckBoxOutlineBlank';
import { type Favorites } from '../../models';
import SwapCalls from '@mui/icons-material/SwapCalls'; import SwapCalls from '@mui/icons-material/SwapCalls';
interface BookControlProps { interface BookControlProps {
width: number; width: number;
fav: Favorites;
setFav: (state: Favorites) => void;
paymentMethod: string[]; paymentMethod: string[];
setPaymentMethods: (state: string[]) => void; setPaymentMethods: (state: string[]) => void;
} }
const BookControl = ({ const BookControl = ({
width, width,
fav,
setFav,
paymentMethod, paymentMethod,
setPaymentMethods, setPaymentMethods,
}: BookControlProps): JSX.Element => { }: BookControlProps): JSX.Element => {
const { fav, setFav } = useContext<UseAppStoreType>(AppContext);
const { t, i18n } = useTranslation(); const { t, i18n } = useTranslation();
const theme = useTheme(); const theme = useTheme();

View File

@ -106,7 +106,7 @@ const BookTable = ({
showNoResults = true, showNoResults = true,
onOrderClicked = () => null, onOrderClicked = () => null,
}: BookTableProps): JSX.Element => { }: BookTableProps): JSX.Element => {
const { fav, setFav, setOpen } = useContext<UseAppStoreType>(AppContext); const { fav, setOpen } = useContext<UseAppStoreType>(AppContext);
const { federation, coordinatorUpdatedAt } = const { federation, coordinatorUpdatedAt } =
useContext<UseFederationStoreType>(FederationContext); useContext<UseFederationStoreType>(FederationContext);
@ -312,7 +312,7 @@ const BookTable = ({
); );
}, },
}; };
}, []); }, [fav.mode]);
const amountObj = useCallback((width: number) => { const amountObj = useCallback((width: number) => {
return { return {
@ -321,11 +321,11 @@ const BookTable = ({
type: 'number', type: 'number',
width: width * fontSize, width: width * fontSize,
renderCell: (params: any) => { renderCell: (params: any) => {
const amount = fav.mode === 'swap' ? params.row.amount * 100000 : params.row.amount; const amount = fav.mode === 'swap' ? params.row.amount * 100 : params.row.amount;
const minAmount = const minAmount =
fav.mode === 'swap' ? params.row.min_amount * 100000 : params.row.min_amount; fav.mode === 'swap' ? params.row.min_amount * 100 : params.row.min_amount;
const maxAmount = const maxAmount =
fav.mode === 'swap' ? params.row.max_amount * 100000 : params.row.max_amount; fav.mode === 'swap' ? params.row.max_amount * 100 : params.row.max_amount;
return ( return (
<div <div
style={{ cursor: 'pointer' }} style={{ cursor: 'pointer' }}
@ -334,12 +334,12 @@ const BookTable = ({
}} }}
> >
{amountToString(amount, params.row.has_range, minAmount, maxAmount) + {amountToString(amount, params.row.has_range, minAmount, maxAmount) +
(fav.mode === 'swap' ? 'K Sats' : '')} (fav.mode === 'swap' ? 'M Sats' : '')}
</div> </div>
); );
}, },
}; };
}, []); }, [fav.mode]);
const currencyObj = useCallback((width: number) => { const currencyObj = useCallback((width: number) => {
return { return {
@ -392,7 +392,7 @@ const BookTable = ({
); );
}, },
}; };
}, []); }, [fav.mode]);
const paymentSmallObj = useCallback((width: number) => { const paymentSmallObj = useCallback((width: number) => {
return { return {
@ -928,8 +928,6 @@ const BookTable = ({
componentsProps={{ componentsProps={{
toolbar: { toolbar: {
width, width,
fav,
setFav,
paymentMethod: paymentMethods, paymentMethod: paymentMethods,
setPaymentMethods, setPaymentMethods,
}, },
@ -966,8 +964,6 @@ const BookTable = ({
componentsProps={{ componentsProps={{
toolbar: { toolbar: {
width, width,
fav,
setFav,
paymentMethod: paymentMethods, paymentMethod: paymentMethods,
setPaymentMethods, setPaymentMethods,
}, },