1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-22 17:33:23 +01:00

Remove SET_CURRENT_FIAT action (#11003)

The `SET_CURRENT_FIAT` action has been removed. It has been replaced
by a call to `forceUpdateMetamaskState`. The only purpose of this
action was to eagerly update the current fiat currency settings before
the next state update. Forcing a state update instead is simpler and
safer.

The `setCurrentCurrency` function in the background has been updated to
no longer return the state, now that it's no longer needed.
This commit is contained in:
Mark Stacey 2021-05-07 11:32:22 -02:30 committed by GitHub
parent 580baff97e
commit 14dc6b58cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 6 additions and 53 deletions

View File

@ -2517,7 +2517,7 @@ export default class MetamaskController extends EventEmitter {
};
this.currencyRateController.update(currencyState);
this.currencyRateController.configure(currencyState);
cb(null, this.currencyRateController.state);
cb(null);
return;
} catch (err) {
cb(err);

View File

@ -93,13 +93,6 @@ export default function reduceMetamask(state = {}, action) {
return Object.assign(metamaskState, { identities });
}
case actionConstants.SET_CURRENT_FIAT:
return Object.assign(metamaskState, {
currentCurrency: action.value.currentCurrency,
conversionRate: action.value.conversionRate,
conversionDate: action.value.conversionDate,
});
case actionConstants.UPDATE_TOKENS:
return {
...metamaskState,

View File

@ -74,26 +74,6 @@ describe('MetaMask Reducers', () => {
});
});
it('sets current fiat', () => {
const value = {
currentCurrency: 'yen',
conversionRate: 3.14,
conversionDate: new Date(2018, 9),
};
const state = reduceMetamask(
{},
{
type: actionConstants.SET_CURRENT_FIAT,
value,
},
);
expect(state.currentCurrency).toStrictEqual(value.currentCurrency);
expect(state.conversionRate).toStrictEqual(value.conversionRate);
expect(state.conversionDate).toStrictEqual(value.conversionDate);
});
it('updates tokens', () => {
const newTokens = {
address: '0x617b3f8050a0bd94b6b1da02b4384ee5b4df13f4',

View File

@ -29,7 +29,6 @@ export const HIDE_WARNING = 'HIDE_WARNING';
export const SHOW_ACCOUNT_DETAIL = 'SHOW_ACCOUNT_DETAIL';
export const SHOW_ACCOUNTS_PAGE = 'SHOW_ACCOUNTS_PAGE';
export const SHOW_CONF_TX_PAGE = 'SHOW_CONF_TX_PAGE';
export const SET_CURRENT_FIAT = 'SET_CURRENT_FIAT';
// account detail screen
export const SHOW_SEND_TOKEN_PAGE = 'SHOW_SEND_TOKEN_PAGE';
export const SHOW_PRIVATE_KEY = 'SHOW_PRIVATE_KEY';

View File

@ -470,25 +470,16 @@ export function setCurrentCurrency(currencyCode) {
return async (dispatch) => {
dispatch(showLoadingIndication());
log.debug(`background.setCurrentCurrency`);
let data;
try {
data = await promisifiedBackground.setCurrentCurrency(currencyCode);
await promisifiedBackground.setCurrentCurrency(currencyCode);
await forceUpdateMetamaskState(dispatch);
} catch (error) {
log.error(error.stack);
log.error(error);
dispatch(displayWarning(error.message));
return;
} finally {
dispatch(hideLoadingIndication());
}
dispatch({
type: actionConstants.SET_CURRENT_FIAT,
value: {
currentCurrency: data.currentCurrency,
conversionRate: data.conversionRate,
conversionDate: data.conversionDate,
},
});
};
}

View File

@ -618,28 +618,18 @@ describe('Actions', () => {
it('calls setCurrentCurrency', async () => {
const store = mockStore();
const setCurrentCurrency = background.setCurrentCurrency.callsFake(
(_, cb) =>
cb(null, {
currentCurrency: 'currency',
conversionRate: 100,
conversionDate: 1611839083653,
}),
);
background.setCurrentCurrency.callsFake((_, cb) => cb());
actions._setBackgroundConnection(background);
await store.dispatch(actions.setCurrentCurrency('jpy'));
expect(setCurrentCurrency.callCount).toStrictEqual(1);
expect(background.setCurrentCurrency.callCount).toStrictEqual(1);
});
it('throws if setCurrentCurrency throws', async () => {
const store = mockStore();
background.setCurrentCurrency.callsFake((_, cb) =>
cb(new Error('error')),
);
actions._setBackgroundConnection(background);
const expectedActions = [