Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] app init fixes #121

Merged
merged 2 commits into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/navigation/tabs/home/HomeRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,13 @@ const HomeRoot = () => {
}, [brazeQuickLinks]);

const showPortfolioValue = useAppSelector(({APP}) => APP.showPortfolioValue);
const appIsLoading = useAppSelector(({APP}) => APP.appIsLoading);

useEffect(() => {
return navigation.addListener('focus', () => {
dispatch(updatePortfolioBalance());
if (!appIsLoading) {
dispatch(updatePortfolioBalance());
} // portfolio balance is updated in app init
});
}, [dispatch, navigation]);

Expand Down
8 changes: 3 additions & 5 deletions src/store/wallet/effects/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,22 @@ import {WalletActions} from '../../index';
import {getPriceHistory, startGetRates} from '../rates/rates';
import {startGetTokenOptions} from '../currencies/currencies';
import {startUpdateAllKeyAndWalletStatus} from '../status/status';
import {updatePortfolioBalance} from '../../wallet.actions';

export const startWalletStoreInit =
(): Effect<Promise<void>> => async (dispatch, getState: () => RootState) => {
try {
const {WALLET, APP} = getState();
const defaultAltCurrencyIsoCode = APP.defaultAltCurrency.isoCode;

await dispatch(startGetTokenOptions());
// both needed for startUpdateAllKeyAndWalletStatus
await dispatch(startGetTokenOptions()); // needed for getRates. Get more recent 1inch tokens list
await dispatch(startGetRates({init: true})); // populate rates and alternative currency list

if (Object.keys(WALLET.keys).length) {
dispatch(startUpdateAllKeyAndWalletStatus({}));
}

await dispatch(startGetRates({init: true})); // populate rates and alternative currency list

dispatch(getPriceHistory(defaultAltCurrencyIsoCode));
dispatch(updatePortfolioBalance());
dispatch(WalletActions.successWalletStoreInit());
} catch (e) {
console.error(e);
Expand Down
1 change: 1 addition & 0 deletions src/store/wallet/effects/status/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ export const startUpdateAllKeyAndWalletStatus =
dispatch(startUpdateAllWalletStatusForKey({key, force}));
}),
);
dispatch(updatePortfolioBalance()); // update portfolio balance after updating all keys balances
dispatch(successUpdateAllKeysAndStatus());
resolve();
} catch (err) {
Expand Down