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] wallet status update #1555

Merged
merged 4 commits into from
Feb 10, 2025
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
11 changes: 1 addition & 10 deletions src/navigation/tabs/home/HomeRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,7 @@ const HomeRoot = () => {
const brazeQuickLinks = useAppSelector(selectBrazeQuickLinks);
const keys = useAppSelector(({WALLET}) => WALLET.keys);
const wallets = Object.values(keys).flatMap(k => k.wallets);
let pendingTxps: any = [];
each(wallets, x => {
// Filter out txps used for pay fees in other wallets
x.pendingTxps = filter(x.pendingTxps, txp => {
return txp.coin === x.currencyAbbreviation;
});
if (x.pendingTxps) {
pendingTxps = pendingTxps.concat(x.pendingTxps);
}
});
const pendingTxps = wallets.flatMap(w => w.pendingTxps);
const appIsLoading = useAppSelector(({APP}) => APP.appIsLoading);
const defaultAltCurrency = useAppSelector(({APP}) => APP.defaultAltCurrency);
const keyMigrationFailure = useAppSelector(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,7 @@ const TransactionProposalNotifications = () => {
);
const [selectAll, setSelectAll] = useState(false);

let pendingTxps: TransactionProposal[] = [];
_.each(wallets, x => {
// Filter out txps used for pay fees in other wallets
x.pendingTxps = _.filter(x.pendingTxps, txp => {
return txp.coin === x.currencyAbbreviation;
});
if (x.pendingTxps.length > 0) {
pendingTxps = pendingTxps.concat(x.pendingTxps);
}
});
let pendingTxps: TransactionProposal[] = wallets.flatMap(w => w.pendingTxps);

if (walletId) {
pendingTxps = _.filter(pendingTxps, txp => {
Expand Down
2 changes: 1 addition & 1 deletion src/store/wallet/effects/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const startWalletStoreInit =
await dispatch(
getAndDispatchUpdatedWalletBalances({
context: 'init',
skipRateUpdate: false,
skipRateUpdate: false, // Skip rate update on initial load to improve performance
}),
);
}
Expand Down
5 changes: 3 additions & 2 deletions src/store/wallet/effects/rates/rates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ import {
} from '@moralisweb3/common-evm-utils';
import {calculateUsdToAltFiat} from '../../../../store/buy-crypto/buy-crypto.effects';
import {IsERCToken} from '../../utils/currency';
import { UpdateAllKeyAndWalletStatusContext } from '../status/status';

export const startGetRates =
({init, force}: {init?: boolean; force?: boolean}): Effect<Promise<Rates>> =>
({context, force}: {context?: UpdateAllKeyAndWalletStatusContext; force?: boolean}): Effect<Promise<Rates>> =>
async (dispatch, getState) => {
return new Promise(async resolve => {
dispatch(LogActions.info('startGetRates: starting...'));
Expand Down Expand Up @@ -82,7 +83,7 @@ export const startGetRates =
LogActions.info('startGetRates: success get request (yesterday)'),
);

if (init) {
if (context === 'init') {
dispatch(
LogActions.info('startGetRates: setting alternative currency list'),
);
Expand Down
2 changes: 1 addition & 1 deletion src/store/wallet/effects/status/statusv2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export const getAndDispatchUpdatedWalletBalances = ({
try {
// Update rates if needed
if (!skipRateUpdate) {
await dispatch(startGetRates({}));
await dispatch(startGetRates({context}));
}

// Get updated balances
Expand Down
19 changes: 11 additions & 8 deletions src/store/wallet/wallet.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -632,14 +632,17 @@ export const walletReducer = (
});

// Update wallet statuses
walletBalances.forEach(({keyId, walletId, status}) => {
if (updatedKeys[keyId]?.wallets?.[walletId]) {
updatedKeys[keyId].wallets[walletId] = {
...updatedKeys[keyId].wallets[walletId],
balance: status.balance,
pendingTxps: status.pendingTxps,
singleAddress: status.singleAddress,
};
walletBalances.forEach(({ keyId, walletId, status }) => {
if (updatedKeys[keyId]?.wallets?.length > 0) {
updatedKeys[keyId].wallets = updatedKeys[keyId].wallets.map((wallet) => {
if (wallet.id === walletId) {
wallet.balance = status.balance;
wallet.pendingTxps = status.pendingTxps;
wallet.isRefreshing = false;
wallet.singleAddress = status.singleAddress;
}
return wallet;
});
}
});

Expand Down