Skip to content

Commit

Permalink
Fix amount string on order details
Browse files Browse the repository at this point in the history
  • Loading branch information
Reckless-Satoshi committed Jan 15, 2024
1 parent 5dcb6f0 commit 82f1e90
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
13 changes: 6 additions & 7 deletions frontend/src/components/OrderDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ const OrderDetails = ({
const { t } = useTranslation();
const theme = useTheme();
const { federation } = useContext<UseFederationStoreType>(FederationContext);
const { orderUpdatedAt } = useContext<UseGarageStoreType>(GarageContext);
const [coordinator, setCoordinator] = useState<Coordinator | null>(
federation.getCoordinator(shortAlias),
);
Expand All @@ -71,10 +70,10 @@ const OrderDetails = ({
useEffect(() => {
setCoordinator(federation.getCoordinator(shortAlias));
setCurrencyCode(currencies[(currentOrder?.currency ?? 1).toString()]);
}, [currentOrder, orderUpdatedAt]);
}, [currentOrder]);

const amountString = useMemo(() => {
if (currentOrder === null || currentOrder.amount === null) return;
if (currentOrder === null) return;

if (currentOrder.currency === 1000) {
return (
Expand All @@ -88,14 +87,14 @@ const OrderDetails = ({
} else {
return (
amountToString(
currentOrder.amount.toString(),
currentOrder.amount?.toString(),
currentOrder.amount > 0 ? false : currentOrder.has_range,
currentOrder.min_amount,
currentOrder.max_amount,
) + ` ${String(currencyCode)}`
);
}
}, [orderUpdatedAt, currencyCode]);
}, [currentOrder, currencyCode]);

// Countdown Renderer callback with condition
const countdownRenderer = function ({
Expand Down Expand Up @@ -208,7 +207,6 @@ const OrderDetails = ({
send = t('You send via {{method}} {{amount}}', {
amount: amountString,
method: order.payment_method,
currencyCode,
});
receive = t('You receive via Lightning {{amount}} Sats (Approx)', {
amount: sats,
Expand Down Expand Up @@ -239,8 +237,9 @@ const OrderDetails = ({
method: order.payment_method,
});
}

return { send, receive };
}, [orderUpdatedAt]);
}, [currentOrder, amountString]);

return (
<Grid container spacing={0}>
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/components/TradeBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,6 @@ const TradeBox = ({ baseUrl, onStartAgain }: TradeBoxProps): JSX.Element => {
baseContract.prompt = function () {
return (
<SuccessfulPrompt
baseUrl={baseUrl}
order={order}
ratePlatform={ratePlatform}
onClickStartAgain={onStartAgain}
Expand Down Expand Up @@ -688,7 +687,6 @@ const TradeBox = ({ baseUrl, onStartAgain }: TradeBoxProps): JSX.Element => {
baseContract.prompt = function () {
return (
<SuccessfulPrompt
baseUrl={baseUrl}
order={order}
ratePlatform={ratePlatform}
onClickStartAgain={onStartAgain}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/contexts/FederationContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export const FederationContextProvider = ({
useEffect(() => {
if (currentOrderId.id && currentOrderId.shortAlias) {
setCurrentOrder(null);
setBadOrder(undefined);
clearInterval(timer);
fetchCurrentOrder();
}
Expand Down

0 comments on commit 82f1e90

Please sign in to comment.