Skip to content

Commit 91ddb21

Browse files
committed
frontend: only update addbuyreceiveonemptybalance state if mounted
Used mounted hook to only update AddBuyReceiveOnEmptyBalances state if the component is actually mounted. This was an approach to fix unknown account code error that appears doing the following: 1) unlock device 2) navigate to account 3) back to account summary 4) unplug the devie Removing the device sometimes errors in AddBuyReceiveOnEmptyBalances component. When logging deciveIDs, keystores and accounts (in sidebar.tsx), it seems after unplugging the device the keystore is already empty but the frontend still has accounts for a short time.
1 parent fdc1c22 commit 91ddb21

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)