Skip to content

Commit b77aa79

Browse files
committed
refill modal fix
1 parent 6b0ca84 commit b77aa79

File tree

2 files changed

+34
-107
lines changed

2 files changed

+34
-107
lines changed

src/entities/balance/ui/RefillModalContent.tsx

Lines changed: 34 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@ import { FC, useMemo, useState, useId, useEffect } from 'react';
22
import {
33
Box,
44
Button,
5-
Divider,
65
ModalBody,
76
ModalCloseButton,
87
ModalContent,
98
ModalFooter,
109
ModalHeader,
1110
Stack,
12-
VStack,
1311
useRadio,
1412
useRadioGroup,
15-
useClipboard
13+
useClipboard,
14+
useToast
1615
} from '@chakra-ui/react';
1716
import { createTransferLink, fromDecimals, H4 } from 'src/shared';
1817
import { observer } from 'mobx-react-lite';
@@ -21,7 +20,6 @@ import { useBillingHistoryQuery } from 'src/shared/hooks';
2120
import { UsdtRefillTab } from './UsdtRefillTab';
2221
import { TonDeprecatedTab } from './TonDeprecatedTab';
2322
import { PromoCodeTab } from './PromoCodeTab';
24-
import { SuccessRefillMessage } from './SuccessRefillMessage';
2523
import { useDepositAddressQuery, useApplyPromoCodeMutation } from '../queries';
2624

2725
type Currency = 'USDT' | 'TON';
@@ -35,12 +33,6 @@ const CURRENCY_DECIMALS: Record<Currency, number> = {
3533
TON: TON_DECIMALS
3634
} as const;
3735

38-
interface DetectedRefill {
39-
id: string;
40-
amount: string;
41-
date: Date;
42-
}
43-
4436
const RadioCard: FC<{
4537
children: React.ReactNode;
4638
value: string;
@@ -97,8 +89,9 @@ const RefillModalContent: FC<{
9789

9890
const [mode, setMode] = useState<RefillMode>('USDT');
9991
const [amount, setAmount] = useState<string>('');
100-
const [detectedRefills, setDetectedRefills] = useState<DetectedRefill[]>([]);
92+
const [shownRefillIds, setShownRefillIds] = useState<Set<string>>(new Set());
10193
const [baselineTransactionId, setBaselineTransactionId] = useState<string | null>(null);
94+
const toast = useToast();
10295

10396
const {
10497
handleSubmit,
@@ -186,27 +179,33 @@ const RefillModalContent: FC<{
186179
const baselineIndex = billingHistory.findIndex(item => item.id === baselineTransactionId);
187180
if (baselineIndex === -1) return;
188181

189-
const existsRefills = detectedRefills.map(item => item.id);
190-
191-
const newRefills: DetectedRefill[] = billingHistory
182+
// Найти новые пополнения которые еще не были показаны в toast
183+
billingHistory
192184
.slice(0, baselineIndex)
193-
.filter(item => item.type === 'deposit')
194-
.map(item => ({
195-
id: item.id,
196-
amount: item.amount.stringCurrencyAmount,
197-
currency: item.amount.currency,
198-
date: item.date
199-
}))
200-
.filter(item => !existsRefills.includes(item.id));
201-
202-
const refills = [...detectedRefills, ...newRefills].sort((a, b) => b.date.getTime() - a.date.getTime()).slice(0, 2);
203-
204-
setDetectedRefills(refills);
205-
}, [billingHistory, baselineTransactionId]);
206-
207-
const handleRemoveRefill = (id: string) => {
208-
setDetectedRefills(prev => prev.filter(refill => refill.id !== id));
209-
};
185+
.filter(item => item.type === 'deposit' && !shownRefillIds.has(item.id))
186+
.forEach(item => {
187+
// Показать toast уведомление
188+
toast({
189+
title: 'Refill detected',
190+
description: `${item.amount.stringCurrencyAmount} received at ${item.date.toLocaleTimeString(
191+
'en-US',
192+
{
193+
hour: '2-digit',
194+
minute: '2-digit',
195+
second: '2-digit',
196+
hour12: false
197+
}
198+
)}`,
199+
status: 'success',
200+
position: 'bottom-left',
201+
isClosable: true,
202+
duration: 5000
203+
});
204+
205+
// Отметить как показанное
206+
setShownRefillIds(prev => new Set([...prev, item.id]));
207+
});
208+
}, [billingHistory, baselineTransactionId, shownRefillIds, toast]);
210209

211210
return (
212211
<ModalContent maxW="400px">
@@ -292,8 +291,8 @@ const RefillModalContent: FC<{
292291
{mode === 'USDT' && (
293292
<>
294293
<Button
295-
mt="2"
296294
w="full"
295+
mt="2"
297296
isDisabled={!paymentLink || isDepositAddressLoading}
298297
onClick={handlePayByLink}
299298
>
@@ -324,24 +323,9 @@ const RefillModalContent: FC<{
324323
</Button>
325324
)}
326325

327-
{detectedRefills.length > 0 && (
328-
<>
329-
<Divider />
330-
<VStack align="stretch" w="full" spacing="1">
331-
{detectedRefills.map(refill => (
332-
<SuccessRefillMessage
333-
key={refill.id}
334-
amount={refill.amount}
335-
date={refill.date}
336-
onClose={() => handleRemoveRefill(refill.id)}
337-
/>
338-
))}
339-
</VStack>
340-
<Button w="full" onClick={onClose} variant="primary">
341-
Done
342-
</Button>
343-
</>
344-
)}
326+
<Button w="full" onClick={onClose} variant="primary" mt={mode === 'TON' ? 3 : 0}>
327+
Done
328+
</Button>
345329
</ModalFooter>
346330
</ModalContent>
347331
);

src/entities/balance/ui/SuccessRefillMessage.tsx

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)