Skip to content

Commit cf93f46

Browse files
committed
frontend: only update addbuyreceiveonemptybalance state if mounted
Used mounted hook to only update AddBuyReceiveOnEmptyBalances state if the component is actually mounted.
1 parent fdc1c22 commit cf93f46

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

frontends/web/src/routes/account/info/buyReceiveCTA.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { Balances } from '../summary/accountssummary';
2222
import { isBitcoinCoin } from '../utils';
2323
import { getExchangeSupportedAccounts } from '../../buy/utils';
2424
import styles from './buyReceiveCTA.module.css';
25+
import { useMountedRef } from '../../../hooks/mount';
2526

2627
type TBuyReceiveCTAProps = {
2728
balanceList?: [string, IBalance][];
@@ -62,12 +63,20 @@ export const BuyReceiveCTA = ({ code, unit, balanceList, exchangeBuySupported =
6263

6364

6465
export const AddBuyReceiveOnEmptyBalances = ({ balances, accounts }: TAddBuyReceiveOnEmpyBalancesProps) => {
65-
66+
const mounted = useMountedRef();
6667
const [supportedAccounts, setSupportedAccounts] = useState<IAccount[]>();
6768

6869
useEffect(() => {
69-
getExchangeSupportedAccounts(accounts).then(setSupportedAccounts);
70-
}, [accounts]);
70+
if (mounted.current) {
71+
getExchangeSupportedAccounts(accounts)
72+
.then(supportedAccounts => {
73+
if (mounted.current) {
74+
setSupportedAccounts(supportedAccounts);
75+
}
76+
})
77+
.catch(console.error);
78+
}
79+
}, [accounts, mounted]);
7180

7281
if (balances === undefined || supportedAccounts === undefined) {
7382
return null;

0 commit comments

Comments
 (0)