Skip to content

Commit

Permalink
Small refactor of code that was looping
Browse files Browse the repository at this point in the history
Closes #266
  • Loading branch information
tombeckenham committed Dec 9, 2024
1 parent f922461 commit 5b3ac07
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 39 deletions.
84 changes: 46 additions & 38 deletions src/ui/views/Dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,45 +49,53 @@ const Dashboard = ({ value, setValue }) => {
setValue(index);
};

const fetchAll = useCallback(async () => {
setLoading(true);
//todo fix cadence loading
await wallet.getCadenceScripts();
const [network, userDomain] = await Promise.all([
wallet.getNetwork(),
wallet.fetchUserDomain(),
]);
const isChild = await wallet.getActiveWallet();

if (isChild === 'evm') {
setIsEvm(true);
}
const env: string = process.env.NODE_ENV!;
const firebaseConfig = getFirbaseConfig();
console.log(process.env.NODE_ENV);
// const firebaseProductionConfig = prodConig;

const app = initializeApp(firebaseConfig, env);
const remoteConfig = getRemoteConfig(app);
console.log('remoteConfig ', app);
fetchAndActivate(remoteConfig)
.then((res) => {
console.log('res ', remoteConfig);

console.log('Remote Config values fetched and activated');
})
.catch((error) => {
console.error('Error fetching remote config:', error);
});

setNetwork(network);
setDomain(userDomain);
setLoading(false);
}, [wallet]);

useEffect(() => {
fetchAll();
}, [fetchAll, wallet]);
console.log('useEffect - fetchAll');
let isMounted = true;

const fetchAll = async () => {
//todo fix cadence loading
await wallet.getCadenceScripts();
const [network, userDomain] = await Promise.all([
wallet.getNetwork(),
wallet.fetchUserDomain(),
]);
const isChild = await wallet.getActiveWallet();

if (isChild === 'evm') {
setIsEvm(true);
}
const env: string = process.env.NODE_ENV!;
const firebaseConfig = getFirbaseConfig();

const app = initializeApp(firebaseConfig, env);
const remoteConfig = getRemoteConfig(app);
console.log('remoteConfig ', app);
fetchAndActivate(remoteConfig)
.then((res) => {
console.log('res ', remoteConfig);

console.log('Remote Config values fetched and activated');
})
.catch((error) => {
console.error('Error fetching remote config:', error);
});

return { network, userDomain };
};

fetchAll().then(({ network, userDomain }) => {
if (isMounted) {
setNetwork(network);
setDomain(userDomain);
setLoading(false);
}
});

return () => {
isMounted = false;
};
}, [wallet]);

return (
<div className="page">
Expand Down
2 changes: 1 addition & 1 deletion src/ui/views/Wallet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const WalletTab = ({ network }) => {
const pollTimer = setInterval(async () => {
const nowTime = new Date().getTime();
const data = await func();
if (data.length > 2 || nowTime - startTime >= endTime) {
if ((data && data.length > 2) || nowTime - startTime >= endTime) {
if (pollTimer) {
clearInterval(pollTimer);
}
Expand Down

0 comments on commit 5b3ac07

Please sign in to comment.