Skip to content

Commit

Permalink
Change locale and localeMessages as single action
Browse files Browse the repository at this point in the history
Updating the current locale and the locale messages resulted in two
renders, and during the first the state was inconsistent (it would say
the locale had changed to the new one, but still be using the old set
of locale messages). Instead the locale is now updated with one atomic
action.

This was required after adding the locale to the missing locale message
warning, as otherwise it would say the message was missing from the
wrong locale.
  • Loading branch information
Gudahtt committed Sep 4, 2019
1 parent ec53db9 commit 51874e7
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 19 deletions.
3 changes: 1 addition & 2 deletions test/unit/ui/app/actions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1155,9 +1155,8 @@ describe('Actions', () => {

const expectedActions = [
{ type: 'SHOW_LOADING_INDICATION', value: undefined },
{ type: 'SET_CURRENT_LOCALE', value: { locale: 'en', messages: enLocale }},
{ type: 'HIDE_LOADING_INDICATION' },
{ type: 'SET_CURRENT_LOCALE', value: 'en' },
{ type: 'SET_LOCALE_MESSAGES', value: enLocale },
]

return store.dispatch(actions.updateCurrentLocale('en'))
Expand Down
2 changes: 1 addition & 1 deletion test/unit/ui/app/reducers/metamask.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ describe('MetaMask Reducers', () => {
it('sets current locale', () => {
const state = reduceMetamask({}, {
type: actions.SET_CURRENT_LOCALE,
value: 'ge',
value: { locale: 'ge' },
})

assert.equal(state.currentLocale, 'ge')
Expand Down
4 changes: 2 additions & 2 deletions ui/app/ducks/locale/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ function reduceMetamask (state, action) {
const localeMessagesState = extend({}, state.localeMessages)

switch (action.type) {
case actions.SET_LOCALE_MESSAGES:
case actions.SET_CURRENT_LOCALE:
return extend(localeMessagesState, {
current: action.value,
current: action.value.messages,
})
default:
return localeMessagesState
Expand Down
2 changes: 1 addition & 1 deletion ui/app/ducks/metamask/metamask.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ function reduceMetamask (state, action) {

case actions.SET_CURRENT_LOCALE:
return extend(metamaskState, {
currentLocale: action.value,
currentLocale: action.value.locale,
})

case actions.SET_PENDING_TOKENS:
Expand Down
19 changes: 6 additions & 13 deletions ui/app/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,8 @@ var actions = {

// locale
SET_CURRENT_LOCALE: 'SET_CURRENT_LOCALE',
SET_LOCALE_MESSAGES: 'SET_LOCALE_MESSAGES',
setCurrentLocale,
updateCurrentLocale,
setLocaleMessages,
//
// Feature Flags
setFeatureFlag,
Expand Down Expand Up @@ -2604,25 +2602,20 @@ function updateCurrentLocale (key) {
return dispatch(actions.displayWarning(err.message))
}
switchDirection(textDirection)
dispatch(actions.setCurrentLocale(key, localeMessages))
dispatch(actions.hideLoadingIndication())
dispatch(actions.setCurrentLocale(key))
dispatch(actions.setLocaleMessages(localeMessages))
})
})
}
}

function setCurrentLocale (key) {
function setCurrentLocale (locale, messages) {
return {
type: actions.SET_CURRENT_LOCALE,
value: key,
}
}

function setLocaleMessages (localeMessages) {
return {
type: actions.SET_LOCALE_MESSAGES,
value: localeMessages,
value: {
locale,
messages,
},
}
}

Expand Down

0 comments on commit 51874e7

Please sign in to comment.