fix: abort and unsub if we unmount inside the loop, and check after the loop as well
This commit is contained in:
parent
e574100bb5
commit
03434b4329
|
@ -58,12 +58,21 @@ const LumeProvider = ({ children }) => {
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const fetchAndUpdateNetworks = async () => {
|
const fetchAndUpdateNetworks = async () => {
|
||||||
|
const unsub = () => {
|
||||||
|
statusUnsubs.current.forEach((unsub) => unsub());
|
||||||
|
statusUnsubs.current = new Map<any, any>();
|
||||||
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const types = await networkRegistry.getTypes();
|
const types = await networkRegistry.getTypes();
|
||||||
const newNetworksMap = new Map();
|
const newNetworksMap = new Map();
|
||||||
const newStatusUnsubs = new Map();
|
const newStatusUnsubs = new Map();
|
||||||
|
|
||||||
for (const type of types) {
|
for (const type of types) {
|
||||||
|
if (!isMounted.current) {
|
||||||
|
unsub();
|
||||||
|
return;
|
||||||
|
}
|
||||||
const list = await networkRegistry.getNetworksByType(type);
|
const list = await networkRegistry.getNetworksByType(type);
|
||||||
for (const module of list) {
|
for (const module of list) {
|
||||||
const client = createNetworkClient(module);
|
const client = createNetworkClient(module);
|
||||||
|
@ -101,6 +110,8 @@ const LumeProvider = ({ children }) => {
|
||||||
...prevLume,
|
...prevLume,
|
||||||
networks: Array.from(newNetworksMap.values()),
|
networks: Array.from(newNetworksMap.values()),
|
||||||
}));
|
}));
|
||||||
|
} else {
|
||||||
|
unsub();
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (isMounted.current) {
|
if (isMounted.current) {
|
||||||
|
|
Loading…
Reference in New Issue