mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
46d72d17a9
Changes to the background state were being detected in the `update` event handler in `ui/index.js` that receives state updates from the background. However this doesn't catch every update; some state changes are received by the UI in-between these `update` events. The background `getState` function is callable directly from the UI, and many action creators call it via `forceUpdateMetamaskState` to update the `metamask` state immediately without waiting for the next `update` event. These state updates skip this change detection in `ui/index.js`. For example, if a 3Box state restoration resulted in a `currentLocale` change, and then a `forceUpdateMetamaskState` call completed before the next `update `event was received, then `updateCurrentLocale` wouldn't be called, and the `locale` store would not be updated correctly with the localized messages for the new locale. We now check for background state changes in the `updateMetamaskState` action creator. All `metamask` state updates go through this function, so we aren't missing any changes anymore.
50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
import assert from 'assert'
|
|
import configureMockStore from 'redux-mock-store'
|
|
import thunk from 'redux-thunk'
|
|
import * as actions from '../../../ui/app/store/actions'
|
|
import actionConstants from '../../../ui/app/store/actionConstants'
|
|
|
|
const middlewares = [thunk]
|
|
const mockStore = configureMockStore(middlewares)
|
|
|
|
describe('tx confirmation screen', function () {
|
|
const txId = 1457634084250832
|
|
const initialState = {
|
|
appState: {
|
|
},
|
|
metamask: {
|
|
unapprovedTxs: {
|
|
[txId]: {
|
|
id: txId,
|
|
status: 'unconfirmed',
|
|
time: 1457634084250,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
const store = mockStore(initialState)
|
|
|
|
describe('cancelTx', function () {
|
|
it('creates COMPLETED_TX with the cancelled transaction ID', async function () {
|
|
actions._setBackgroundConnection({
|
|
approveTransaction (_, cb) {
|
|
cb('An error!')
|
|
},
|
|
cancelTransaction (_, cb) {
|
|
cb()
|
|
},
|
|
getState (cb) {
|
|
cb(null, {})
|
|
},
|
|
})
|
|
|
|
await store.dispatch(actions.cancelTx({ id: txId }))
|
|
const storeActions = store.getActions()
|
|
const completedTxAction = storeActions.find(({ type }) => type === actionConstants.COMPLETED_TX)
|
|
const { id } = completedTxAction.value
|
|
assert.equal(id, txId)
|
|
})
|
|
})
|
|
})
|