Skip to content

Commit

Permalink
fix(coinmarket): reflect account updates in coinmarket
Browse files Browse the repository at this point in the history
(cherry picked from commit 9894500)
  • Loading branch information
FreeWall authored and MiroslavProchazka committed Jan 21, 2025
1 parent 2eaf105 commit ee5fa76
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,12 @@ export const useCoinmarketExchangeForm = ({
}
}, [defaultValues, values, removeDraft]);

useEffect(() => {
if (account.key === coinmarketAccount?.key) {
setAccount(coinmarketAccount);
}
}, [account, setAccount, coinmarketAccount]);

// react-hook-form auto register custom form fields (without HTMLElement)
useEffect(() => {
register('options');
Expand Down
13 changes: 13 additions & 0 deletions packages/suite/src/middlewares/wallet/coinmarketMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { MiddlewareAPI } from 'redux';

import { UI } from '@trezor/connect';
import { Route } from '@suite-common/suite-types';
import { accountsActions } from '@suite-common/wallet-core';

import { AppState, Action, Dispatch } from 'src/types/suite';
import {
Expand Down Expand Up @@ -214,5 +215,17 @@ export const coinmarketMiddleware =
}
}

if (isCoinmarketRoute && action.type === accountsActions.updateAccount.type) {
const account = action.payload;

if (state.wallet.coinmarket.sell.coinmarketAccount?.key === account.key) {
api.dispatch(coinmarketSellActions.setCoinmarketSellAccount(account));
}

if (state.wallet.coinmarket.exchange.coinmarketAccount?.key === account.key) {
api.dispatch(coinmarketExchangeActions.setCoinmarketExchangeAccount(account));
}
}

return action;
};

0 comments on commit ee5fa76

Please sign in to comment.