Skip to content

Commit 5cc027c

Browse files
committed
feat: integrate fetchDepositAddress into BalanceStore and enhance RefillModal for better error handling and loading states
1 parent 3696463 commit 5cc027c

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

src/entities/balance/model/balance.store.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export class BalanceStore {
4949
makeAutoObservable(this);
5050
this.projectsStore = projectsStore;
5151
this.fetchTonRate();
52+
this.fetchDepositAddress();
5253

5354
createImmediateReaction(
5455
() => this.projectsStore.selectedProject,

src/entities/balance/ui/RefillModal.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@ const RefillModal: FC<{
88
isOpen: boolean;
99
onClose: () => void;
1010
}> = props => {
11-
useEffect(() => {
12-
if (props.isOpen) {
13-
balanceStore.fetchDepositAddress();
14-
}
15-
}, [props.isOpen]);
16-
1711
return (
1812
<Modal scrollBehavior="inside" size="md" {...props}>
1913
<ModalOverlay />

src/entities/balance/ui/RefillModalContent.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FC, useEffect, useMemo, useRef, useState } from 'react';
1+
import { FC, useMemo, useRef, useState } from 'react';
22
import {
33
Box,
44
Button,
@@ -138,11 +138,7 @@ const RefillModalContent: FC<{
138138
</ModalHeader>
139139
<ModalCloseButton />
140140
<ModalBody pt="0" pb="4">
141-
{balanceStore.depositAddress$.isLoading ? (
142-
<Center h="80px">
143-
<Spinner />
144-
</Center>
145-
) : balanceStore.depositAddress$.error ? (
141+
{balanceStore.depositAddress$.error ? (
146142
<Box color="accent.orange">
147143
<Box>Balance refill is not available right now.</Box>
148144
<Box>Please try again later.</Box>
@@ -207,8 +203,14 @@ const RefillModalContent: FC<{
207203
justifyContent="center"
208204
flexDirection="column"
209205
>
210-
{paymentLink ? (
206+
{paymentLink && balanceStore.depositAddress$.isResolved ? (
211207
<QRCodeSVG bgColor="transparent" size={200} value={paymentLink} />
208+
) : !balanceStore.depositAddress$.isResolved && !balanceStore.depositAddress$.isLoading ? (
209+
<Center h="200px">
210+
<Text textStyle="body2" color="text.secondary">
211+
Error fetching deposit address
212+
</Text>
213+
</Center>
212214
) : (
213215
<svg
214216
width="200"

src/pages/balance/BalanceBlock.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { FC } from 'react';
22
import { H2, Overlay, Span, toDecimals, InfoTooltip } from 'src/shared';
3-
import { Box, Button, Flex, Skeleton, useDisclosure, Link, Text } from '@chakra-ui/react';
3+
import { Box, Button, Flex, Skeleton, useDisclosure, Text } from '@chakra-ui/react';
44
import { PromoCodeModal, RefillModal } from 'src/entities';
55
import { observer } from 'mobx-react-lite';
66
import { balanceStore } from 'src/shared/stores';

src/pages/balance/BillingBlock.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ const BillingBlock: FC<BillingBlockProps> = ({ billingStore }) => {
1414
const hasBillingHistory = billingStore.billingHistory.length > 0;
1515
const isLoading = billingStore.billingHistoryLoading;
1616

17+
// Reset state when store instance changes
18+
useEffect(() => {
19+
setHasEverLoaded(false);
20+
setPreviousRowCount(0);
21+
}, [billingStore]);
22+
1723
// Track whether data has ever been loaded and remember the row count
1824
useEffect(() => {
1925
if (!isLoading && hasBillingHistory) {

0 commit comments

Comments
 (0)