Add migration on 3box imports and remove feature flag (#7209)

* Delete unused code

* Run threebox imports through migrations

* Remove 3box feature flag

* Remove unnecessary use of 'type' in threebox._updatePlugin

* Fix threebox controller getLastUpdated

* Turn off threebox by default

* Rename restoredFromThreeBox to showRestorePrompt

* Remove accientally added method from threebox controller

* Restore from threebox on import from unlock screen

* Throw on non 404 errors from Box.getconfig in new3Box
feature/default_network_editable
Dan J Miller 5 years ago committed by GitHub
parent e1efb4d7ac
commit 970e90ea70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      app/scripts/controllers/preferences.js
  2. 94
      app/scripts/controllers/threebox.js
  3. 20
      app/scripts/metamask-controller.js
  4. 7
      development/mock-3box.js
  5. 31
      test/e2e/threebox.spec.js
  6. 9
      test/unit/app/controllers/metamask-controller-test.js
  7. 18
      ui/app/pages/home/home.component.js
  8. 12
      ui/app/pages/home/home.container.js
  9. 5
      ui/app/pages/keychains/restore-vault.js
  10. 5
      ui/app/pages/settings/advanced-tab/advanced-tab.component.js
  11. 11
      ui/app/pages/settings/advanced-tab/advanced-tab.container.js
  12. 15
      ui/app/pages/settings/advanced-tab/tests/advanced-tab-component.test.js
  13. 2
      ui/app/pages/settings/advanced-tab/tests/advanced-tab-container.test.js
  14. 153
      ui/app/store/actions.js

@ -42,7 +42,6 @@ class PreferencesController {
// perform sensitive operations. // perform sensitive operations.
featureFlags: { featureFlags: {
showIncomingTransactions: true, showIncomingTransactions: true,
threeBox: false,
}, },
knownMethodData: {}, knownMethodData: {},
participateInMetaMetrics: null, participateInMetaMetrics: null,

@ -2,9 +2,9 @@ const ObservableStore = require('obs-store')
const Box = process.env.IN_TEST const Box = process.env.IN_TEST
? require('../../../development/mock-3box') ? require('../../../development/mock-3box')
: require('3box') : require('3box')
// const Box = require(process.env.IN_TEST ? '../lib/mock-3box' : '3box/dist/3box.min')
const log = require('loglevel') const log = require('loglevel')
const migrations = require('../migrations/')
const Migrator = require('../lib/migrator')
const JsonRpcEngine = require('json-rpc-engine') const JsonRpcEngine = require('json-rpc-engine')
const providerFromEngine = require('eth-json-rpc-middleware/providerFromEngine') const providerFromEngine = require('eth-json-rpc-middleware/providerFromEngine')
const createMetamaskMiddleware = require('./network/createMetamaskMiddleware') const createMetamaskMiddleware = require('./network/createMetamaskMiddleware')
@ -48,8 +48,9 @@ class ThreeBoxController {
}) })
const initState = { const initState = {
threeBoxSyncingAllowed: true, threeBoxSyncingAllowed: false,
restoredFromThreeBox: null, showRestorePrompt: true,
threeBoxLastUpdated: 0,
...opts.initState, ...opts.initState,
threeBoxAddress: null, threeBoxAddress: null,
threeBoxSynced: false, threeBoxSynced: false,
@ -57,10 +58,9 @@ class ThreeBoxController {
} }
this.store = new ObservableStore(initState) this.store = new ObservableStore(initState)
this.registeringUpdates = false this.registeringUpdates = false
this.lastMigration = migrations.sort((a, b) => a.version - b.version).slice(-1)[0]
const threeBoxFeatureFlagTurnedOn = this.preferencesController.getFeatureFlags().threeBox if (initState.threeBoxSyncingAllowed) {
if (threeBoxFeatureFlagTurnedOn) {
this.init() this.init()
} }
} }
@ -73,12 +73,19 @@ class ThreeBoxController {
} }
} }
async _update3Box ({ type }, newState) { async _update3Box () {
try { try {
const { threeBoxSyncingAllowed, threeBoxSynced } = this.store.getState() const { threeBoxSyncingAllowed, threeBoxSynced } = this.store.getState()
if (threeBoxSyncingAllowed && threeBoxSynced) { if (threeBoxSyncingAllowed && threeBoxSynced) {
await this.space.private.set('lastUpdated', Date.now()) const newState = {
await this.space.private.set(type, JSON.stringify(newState)) preferences: this.preferencesController.store.getState(),
addressBook: this.addressBookController.state,
lastUpdated: Date.now(),
lastMigration: this.lastMigration,
}
await this.space.private.set('metamaskBackup', JSON.stringify(newState))
await this.setShowRestorePromptToFalse()
} }
} catch (error) { } catch (error) {
console.error(error) console.error(error)
@ -105,11 +112,20 @@ class ThreeBoxController {
async new3Box () { async new3Box () {
const accounts = await this.keyringController.getAccounts() const accounts = await this.keyringController.getAccounts()
const address = accounts[0] this.address = await this.keyringController.getAppKeyAddress(accounts[0], 'wallet://3box.metamask.io')
let backupExists
if (this.getThreeBoxSyncingState()) { try {
const threeBoxConfig = await Box.getConfig(this.address)
backupExists = threeBoxConfig.spaces && threeBoxConfig.spaces.metamask
} catch (e) {
if (e.message.match(/^Error: Invalid response (404)/)) {
backupExists = false
} else {
throw e
}
}
if (this.getThreeBoxSyncingState() || backupExists) {
this.store.updateState({ threeBoxSynced: false }) this.store.updateState({ threeBoxSynced: false })
this.address = await this.keyringController.getAppKeyAddress(address, 'wallet://3box.metamask.io')
let timedOut = false let timedOut = false
const syncTimeout = setTimeout(() => { const syncTimeout = setTimeout(() => {
@ -121,13 +137,13 @@ class ThreeBoxController {
}) })
}, SYNC_TIMEOUT) }, SYNC_TIMEOUT)
try { try {
this.box = await Box.openBox(address, this.provider) this.box = await Box.openBox(this.address, this.provider)
await this._waitForOnSyncDone() await this._waitForOnSyncDone()
this.space = await this.box.openSpace('metamask', { this.space = await this.box.openSpace('metamask', {
onSyncDone: async () => { onSyncDone: async () => {
const stateUpdate = { const stateUpdate = {
threeBoxSynced: true, threeBoxSynced: true,
threeBoxAddress: address, threeBoxAddress: this.address,
} }
if (timedOut) { if (timedOut) {
log.info(`3Box sync completed after timeout; no longer disabled`) log.info(`3Box sync completed after timeout; no longer disabled`)
@ -136,6 +152,7 @@ class ThreeBoxController {
clearTimeout(syncTimeout) clearTimeout(syncTimeout)
this.store.updateState(stateUpdate) this.store.updateState(stateUpdate)
log.debug('3Box space sync done') log.debug('3Box space sync done')
}, },
}) })
@ -147,15 +164,36 @@ class ThreeBoxController {
} }
async getLastUpdated () { async getLastUpdated () {
return await this.space.private.get('lastUpdated') const res = await this.space.private.get('metamaskBackup')
const parsedRes = JSON.parse(res || '{}')
return parsedRes.lastUpdated
}
async migrateBackedUpState (backedUpState) {
const migrator = new Migrator({ migrations })
const formattedStateBackup = {
PreferencesController: backedUpState.preferences,
AddressBookController: backedUpState.addressBook,
}
const initialMigrationState = migrator.generateInitialState(formattedStateBackup)
const migratedState = await migrator.migrateData(initialMigrationState)
return {
preferences: migratedState.PreferencesController,
addressBook: migratedState.AddressBookController,
}
} }
async restoreFromThreeBox () { async restoreFromThreeBox () {
this.setRestoredFromThreeBoxToTrue() const backedUpState = await this.space.private.get('metamaskBackup')
const backedUpPreferences = await this.space.private.get('preferences') const {
backedUpPreferences && this.preferencesController.store.updateState(JSON.parse(backedUpPreferences)) preferences,
const backedUpAddressBook = await this.space.private.get('addressBook') addressBook,
backedUpAddressBook && this.addressBookController.update(JSON.parse(backedUpAddressBook), true) } = await this.migrateBackedUpState(backedUpState)
this.store.updateState({ threeBoxLastUpdated: backedUpState.lastUpdated })
preferences && this.preferencesController.store.updateState(JSON.parse(preferences))
addressBook && this.addressBookController.update(JSON.parse(addressBook), true)
this.setShowRestorePromptToFalse()
} }
turnThreeBoxSyncingOn () { turnThreeBoxSyncingOn () {
@ -166,12 +204,8 @@ class ThreeBoxController {
this.box.logout() this.box.logout()
} }
setRestoredFromThreeBoxToTrue () { setShowRestorePromptToFalse () {
this.store.updateState({ restoredFromThreeBox: true }) this.store.updateState({ showRestorePrompt: false })
}
setRestoredFromThreeBoxToFalse () {
this.store.updateState({ restoredFromThreeBox: false })
} }
setThreeBoxSyncingPermission (newThreeboxSyncingState) { setThreeBoxSyncingPermission (newThreeboxSyncingState) {
@ -201,9 +235,9 @@ class ThreeBoxController {
_registerUpdates () { _registerUpdates () {
if (!this.registeringUpdates) { if (!this.registeringUpdates) {
const updatePreferences = this._update3Box.bind(this, { type: 'preferences' }) const updatePreferences = this._update3Box.bind(this)
this.preferencesController.store.subscribe(updatePreferences) this.preferencesController.store.subscribe(updatePreferences)
const updateAddressBook = this._update3Box.bind(this, { type: 'addressBook' }) const updateAddressBook = this._update3Box.bind(this)
this.addressBookController.subscribe(updateAddressBook) this.addressBookController.subscribe(updateAddressBook)
this.registeringUpdates = true this.registeringUpdates = true
} }

@ -543,7 +543,7 @@ module.exports = class MetamaskController extends EventEmitter {
// 3Box // 3Box
setThreeBoxSyncingPermission: nodeify(threeBoxController.setThreeBoxSyncingPermission, threeBoxController), setThreeBoxSyncingPermission: nodeify(threeBoxController.setThreeBoxSyncingPermission, threeBoxController),
restoreFromThreeBox: nodeify(threeBoxController.restoreFromThreeBox, threeBoxController), restoreFromThreeBox: nodeify(threeBoxController.restoreFromThreeBox, threeBoxController),
setRestoredFromThreeBoxToFalse: nodeify(threeBoxController.setRestoredFromThreeBoxToFalse, threeBoxController), setShowRestorePromptToFalse: nodeify(threeBoxController.setShowRestorePromptToFalse, threeBoxController),
getThreeBoxLastUpdated: nodeify(threeBoxController.getLastUpdated, threeBoxController), getThreeBoxLastUpdated: nodeify(threeBoxController.getLastUpdated, threeBoxController),
turnThreeBoxSyncingOn: nodeify(threeBoxController.turnThreeBoxSyncingOn, threeBoxController), turnThreeBoxSyncingOn: nodeify(threeBoxController.turnThreeBoxSyncingOn, threeBoxController),
initializeThreeBox: nodeify(this.initializeThreeBox, this), initializeThreeBox: nodeify(this.initializeThreeBox, this),
@ -752,16 +752,12 @@ module.exports = class MetamaskController extends EventEmitter {
await this.preferencesController.syncAddresses(accounts) await this.preferencesController.syncAddresses(accounts)
await this.txController.pendingTxTracker.updatePendingTxs() await this.txController.pendingTxTracker.updatePendingTxs()
const threeBoxFeatureFlagTurnedOn = this.preferencesController.getFeatureFlags().threeBox const threeBoxSyncingAllowed = this.threeBoxController.getThreeBoxSyncingState()
if (threeBoxSyncingAllowed && !this.threeBoxController.box) {
if (threeBoxFeatureFlagTurnedOn) { await this.threeBoxController.new3Box()
const threeBoxSyncingAllowed = this.threeBoxController.getThreeBoxSyncingState() this.threeBoxController.turnThreeBoxSyncingOn()
if (threeBoxSyncingAllowed && !this.threeBoxController.box) { } else if (threeBoxSyncingAllowed && this.threeBoxController.box) {
await this.threeBoxController.new3Box() this.threeBoxController.turnThreeBoxSyncingOn()
this.threeBoxController.turnThreeBoxSyncingOn()
} else if (threeBoxSyncingAllowed && this.threeBoxController.box) {
this.threeBoxController.turnThreeBoxSyncingOn()
}
} }
return this.keyringController.fullUpdate() return this.keyringController.fullUpdate()
@ -1714,7 +1710,7 @@ module.exports = class MetamaskController extends EventEmitter {
} }
async initializeThreeBox () { async initializeThreeBox () {
await this.threeBoxController.new3Box() await this.threeBoxController.init()
} }
/** /**

@ -55,6 +55,13 @@ class Mock3Box {
logout: () => {}, logout: () => {},
}) })
} }
static async getConfig (address) {
const backup = await loadFromMock3Box(`${address}-metamask-metamaskBackup`)
return backup
? { spaces: { metamask: {} } }
: {}
}
} }
module.exports = Mock3Box module.exports = Mock3Box

@ -51,12 +51,6 @@ describe('MetaMask', function () {
describe('set up data to be restored by 3box', () => { describe('set up data to be restored by 3box', () => {
describe('First time flow starting from an existing seed phrase', () => { describe('First time flow starting from an existing seed phrase', () => {
it('turns on the threebox feature flag', async () => {
await delay(largeDelayMs)
await driver.executeScript('window.metamask.setFeatureFlag("threeBox", true)')
await delay(largeDelayMs)
})
it('clicks the continue button on the welcome screen', async () => { it('clicks the continue button on the welcome screen', async () => {
await findElement(driver, By.css('.welcome-page__header')) await findElement(driver, By.css('.welcome-page__header'))
const welcomeScreenBtn = await findElement(driver, By.css('.first-time-flow__button')) const welcomeScreenBtn = await findElement(driver, By.css('.first-time-flow__button'))
@ -108,7 +102,7 @@ describe('MetaMask', function () {
}) })
}) })
describe('updates settings and address book', () => { describe('turns on threebox syncing', () => {
it('goes to the settings screen', async () => { it('goes to the settings screen', async () => {
await driver.findElement(By.css('.account-menu__icon')).click() await driver.findElement(By.css('.account-menu__icon')).click()
await delay(regularDelayMs) await delay(regularDelayMs)
@ -117,6 +111,23 @@ describe('MetaMask', function () {
settingsButton.click() settingsButton.click()
}) })
it('turns on threebox syncing', async () => {
const advancedButton = await findElement(driver, By.xpath(`//div[contains(text(), 'Advanced')]`))
await advancedButton.click()
const threeBoxToggle = await findElements(driver, By.css('.toggle-button'))
const threeBoxToggleButton = await threeBoxToggle[3].findElement(By.css('div'))
await threeBoxToggleButton.click()
})
})
describe('updates settings and address book', () => {
it('adds an address to the contact list', async () => {
const generalButton = await findElement(driver, By.xpath(`//div[contains(text(), 'General')]`))
await generalButton.click()
})
it('turns on use of blockies', async () => { it('turns on use of blockies', async () => {
const toggleButton = await findElement(driver, By.css('.toggle-button > div')) const toggleButton = await findElement(driver, By.css('.toggle-button > div'))
await toggleButton.click() await toggleButton.click()
@ -163,12 +174,6 @@ describe('MetaMask', function () {
}) })
describe('First time flow starting from an existing seed phrase', () => { describe('First time flow starting from an existing seed phrase', () => {
it('turns on the threebox feature flag', async () => {
await delay(largeDelayMs)
await driver2.executeScript('window.metamask.setFeatureFlag("threeBox", true)')
await delay(largeDelayMs)
})
it('clicks the continue button on the welcome screen', async () => { it('clicks the continue button on the welcome screen', async () => {
await findElement(driver2, By.css('.welcome-page__header')) await findElement(driver2, By.css('.welcome-page__header'))
const welcomeScreenBtn = await findElement(driver2, By.css('.first-time-flow__button')) const welcomeScreenBtn = await findElement(driver2, By.css('.first-time-flow__button'))

@ -129,14 +129,7 @@ describe('MetaMaskController', function () {
}) })
}) })
it('gets does not instantiate 3box if the feature flag is false', async () => { it('gets the address from threebox and creates a new 3box instance', async () => {
await metamaskController.submitPassword(password)
assert(threeBoxSpies.new3Box.notCalled)
assert(threeBoxSpies.turnThreeBoxSyncingOn.notCalled)
})
it('gets the address from threebox and creates a new 3box instance if the feature flag is true', async () => {
metamaskController.preferencesController.setFeatureFlag('threeBox', true)
await metamaskController.submitPassword(password) await metamaskController.submitPassword(password)
assert(threeBoxSpies.new3Box.calledOnce) assert(threeBoxSpies.new3Box.calledOnce)
assert(threeBoxSpies.turnThreeBoxSyncingOn.calledOnce) assert(threeBoxSpies.turnThreeBoxSyncingOn.calledOnce)

@ -38,12 +38,11 @@ export default class Home extends PureComponent {
threeBoxSynced: PropTypes.bool, threeBoxSynced: PropTypes.bool,
setupThreeBox: PropTypes.func, setupThreeBox: PropTypes.func,
turnThreeBoxSyncingOn: PropTypes.func, turnThreeBoxSyncingOn: PropTypes.func,
restoredFromThreeBox: PropTypes.bool, showRestorePrompt: PropTypes.bool,
selectedAddress: PropTypes.string, selectedAddress: PropTypes.string,
restoreFromThreeBox: PropTypes.func, restoreFromThreeBox: PropTypes.func,
setRestoredFromThreeBoxToFalse: PropTypes.func, setShowRestorePromptToFalse: PropTypes.func,
threeBoxLastUpdated: PropTypes.string, threeBoxLastUpdated: PropTypes.string,
threeBoxFeatureFlagIsTrue: PropTypes.bool,
} }
componentWillMount () { componentWillMount () {
@ -73,10 +72,10 @@ export default class Home extends PureComponent {
const { const {
threeBoxSynced, threeBoxSynced,
setupThreeBox, setupThreeBox,
restoredFromThreeBox, showRestorePrompt,
threeBoxLastUpdated, threeBoxLastUpdated,
} = this.props } = this.props
if (threeBoxSynced && restoredFromThreeBox === null && threeBoxLastUpdated === null) { if (threeBoxSynced && showRestorePrompt && threeBoxLastUpdated === null) {
setupThreeBox() setupThreeBox()
} }
} }
@ -94,10 +93,9 @@ export default class Home extends PureComponent {
selectedAddress, selectedAddress,
restoreFromThreeBox, restoreFromThreeBox,
turnThreeBoxSyncingOn, turnThreeBoxSyncingOn,
setRestoredFromThreeBoxToFalse, setShowRestorePromptToFalse,
restoredFromThreeBox, showRestorePrompt,
threeBoxLastUpdated, threeBoxLastUpdated,
threeBoxFeatureFlagIsTrue,
} = this.props } = this.props
if (forgottenPassword) { if (forgottenPassword) {
@ -155,7 +153,7 @@ export default class Home extends PureComponent {
/>, />,
}, },
{ {
shouldBeRendered: threeBoxFeatureFlagIsTrue && threeBoxLastUpdated && restoredFromThreeBox === null, shouldBeRendered: threeBoxLastUpdated && showRestorePrompt,
component: <HomeNotification component: <HomeNotification
descriptionText={t('restoreWalletPreferences', [ formatDate(parseInt(threeBoxLastUpdated), 'M/d/y') ])} descriptionText={t('restoreWalletPreferences', [ formatDate(parseInt(threeBoxLastUpdated), 'M/d/y') ])}
acceptText={t('restore')} acceptText={t('restore')}
@ -168,7 +166,7 @@ export default class Home extends PureComponent {
}) })
}} }}
onIgnore={() => { onIgnore={() => {
setRestoredFromThreeBoxToFalse() setShowRestorePromptToFalse()
}} }}
key="home-privacyModeDefault" key="home-privacyModeDefault"
/>, />,

@ -9,7 +9,7 @@ import {
restoreFromThreeBox, restoreFromThreeBox,
turnThreeBoxSyncingOn, turnThreeBoxSyncingOn,
getThreeBoxLastUpdated, getThreeBoxLastUpdated,
setRestoredFromThreeBoxToFalse, setShowRestorePromptToFalse,
} from '../../store/actions' } from '../../store/actions'
import { setThreeBoxLastUpdated } from '../../ducks/app/app' import { setThreeBoxLastUpdated } from '../../ducks/app/app'
import { getEnvironmentType } from '../../../../app/scripts/lib/util' import { getEnvironmentType } from '../../../../app/scripts/lib/util'
@ -24,9 +24,8 @@ const mapStateToProps = state => {
seedPhraseBackedUp, seedPhraseBackedUp,
tokens, tokens,
threeBoxSynced, threeBoxSynced,
restoredFromThreeBox, showRestorePrompt,
selectedAddress, selectedAddress,
featureFlags,
} = metamask } = metamask
const accountBalance = getCurrentEthBalance(state) const accountBalance = getCurrentEthBalance(state)
const { forgottenPassword, threeBoxLastUpdated } = appState const { forgottenPassword, threeBoxLastUpdated } = appState
@ -42,10 +41,9 @@ const mapStateToProps = state => {
shouldShowSeedPhraseReminder: !seedPhraseBackedUp && (parseInt(accountBalance, 16) > 0 || tokens.length > 0), shouldShowSeedPhraseReminder: !seedPhraseBackedUp && (parseInt(accountBalance, 16) > 0 || tokens.length > 0),
isPopup, isPopup,
threeBoxSynced, threeBoxSynced,
restoredFromThreeBox, showRestorePrompt,
selectedAddress, selectedAddress,
threeBoxLastUpdated, threeBoxLastUpdated,
threeBoxFeatureFlagIsTrue: featureFlags.threeBox,
} }
} }
@ -58,13 +56,13 @@ const mapDispatchToProps = (dispatch) => ({
if (lastUpdated) { if (lastUpdated) {
dispatch(setThreeBoxLastUpdated(lastUpdated)) dispatch(setThreeBoxLastUpdated(lastUpdated))
} else { } else {
dispatch(setRestoredFromThreeBoxToFalse()) dispatch(setShowRestorePromptToFalse())
dispatch(turnThreeBoxSyncingOn()) dispatch(turnThreeBoxSyncingOn())
} }
}) })
}, },
restoreFromThreeBox: (address) => dispatch(restoreFromThreeBox(address)), restoreFromThreeBox: (address) => dispatch(restoreFromThreeBox(address)),
setRestoredFromThreeBoxToFalse: () => dispatch(setRestoredFromThreeBoxToFalse()), setShowRestorePromptToFalse: () => dispatch(setShowRestorePromptToFalse()),
}) })
export default compose( export default compose(

@ -4,6 +4,7 @@ import {connect} from 'react-redux'
import { import {
createNewVaultAndRestore, createNewVaultAndRestore,
unMarkPasswordForgotten, unMarkPasswordForgotten,
initializeThreeBox,
} from '../../store/actions' } from '../../store/actions'
import { DEFAULT_ROUTE } from '../../helpers/constants/routes' import { DEFAULT_ROUTE } from '../../helpers/constants/routes'
import TextField from '../../components/ui/text-field' import TextField from '../../components/ui/text-field'
@ -21,6 +22,7 @@ class RestoreVaultPage extends Component {
leaveImportSeedScreenState: PropTypes.func, leaveImportSeedScreenState: PropTypes.func,
history: PropTypes.object, history: PropTypes.object,
isLoading: PropTypes.bool, isLoading: PropTypes.bool,
initializeThreeBox: PropTypes.func,
}; };
state = { state = {
@ -81,6 +83,7 @@ class RestoreVaultPage extends Component {
createNewVaultAndRestore, createNewVaultAndRestore,
leaveImportSeedScreenState, leaveImportSeedScreenState,
history, history,
initializeThreeBox,
} = this.props } = this.props
leaveImportSeedScreenState() leaveImportSeedScreenState()
@ -93,6 +96,7 @@ class RestoreVaultPage extends Component {
name: 'onboardingRestoredVault', name: 'onboardingRestoredVault',
}, },
}) })
initializeThreeBox()
history.push(DEFAULT_ROUTE) history.push(DEFAULT_ROUTE)
}) })
} }
@ -194,5 +198,6 @@ export default connect(
dispatch(unMarkPasswordForgotten()) dispatch(unMarkPasswordForgotten())
}, },
createNewVaultAndRestore: (pw, seed) => dispatch(createNewVaultAndRestore(pw, seed)), createNewVaultAndRestore: (pw, seed) => dispatch(createNewVaultAndRestore(pw, seed)),
initializeThreeBox: () => dispatch(initializeThreeBox()),
}) })
)(RestoreVaultPage) )(RestoreVaultPage)

@ -30,7 +30,6 @@ export default class AdvancedTab extends PureComponent {
threeBoxSyncingAllowed: PropTypes.bool.isRequired, threeBoxSyncingAllowed: PropTypes.bool.isRequired,
setThreeBoxSyncingPermission: PropTypes.func.isRequired, setThreeBoxSyncingPermission: PropTypes.func.isRequired,
threeBoxDisabled: PropTypes.bool.isRequired, threeBoxDisabled: PropTypes.bool.isRequired,
threeBoxFeatureFlag: PropTypes.bool.isRequired,
} }
state = { autoLogoutTimeLimit: this.props.autoLogoutTimeLimit } state = { autoLogoutTimeLimit: this.props.autoLogoutTimeLimit }
@ -301,7 +300,7 @@ export default class AdvancedTab extends PureComponent {
} }
renderContent () { renderContent () {
const { warning, threeBoxFeatureFlag } = this.props const { warning } = this.props
return ( return (
<div className="settings-page__body"> <div className="settings-page__body">
@ -313,7 +312,7 @@ export default class AdvancedTab extends PureComponent {
{ this.renderHexDataOptIn() } { this.renderHexDataOptIn() }
{ this.renderShowConversionInTestnets() } { this.renderShowConversionInTestnets() }
{ this.renderAutoLogoutTimeLimit() } { this.renderAutoLogoutTimeLimit() }
{ threeBoxFeatureFlag ? this.renderThreeBoxControl() : null } { this.renderThreeBoxControl() }
</div> </div>
) )
} }

@ -10,6 +10,7 @@ import {
setShowFiatConversionOnTestnetsPreference, setShowFiatConversionOnTestnetsPreference,
setAutoLogoutTimeLimit, setAutoLogoutTimeLimit,
setThreeBoxSyncingPermission, setThreeBoxSyncingPermission,
turnThreeBoxSyncingOnAndInitialize,
} from '../../../store/actions' } from '../../../store/actions'
import {preferencesSelector} from '../../../selectors/selectors' import {preferencesSelector} from '../../../selectors/selectors'
@ -19,7 +20,6 @@ export const mapStateToProps = state => {
featureFlags: { featureFlags: {
sendHexData, sendHexData,
advancedInlineGas, advancedInlineGas,
threeBox,
} = {}, } = {},
threeBoxSyncingAllowed, threeBoxSyncingAllowed,
threeBoxDisabled, threeBoxDisabled,
@ -34,7 +34,6 @@ export const mapStateToProps = state => {
autoLogoutTimeLimit, autoLogoutTimeLimit,
threeBoxSyncingAllowed, threeBoxSyncingAllowed,
threeBoxDisabled, threeBoxDisabled,
threeBoxFeatureFlag: threeBox,
} }
} }
@ -51,7 +50,13 @@ export const mapDispatchToProps = dispatch => {
setAutoLogoutTimeLimit: value => { setAutoLogoutTimeLimit: value => {
return dispatch(setAutoLogoutTimeLimit(value)) return dispatch(setAutoLogoutTimeLimit(value))
}, },
setThreeBoxSyncingPermission: newThreeBoxSyncingState => dispatch(setThreeBoxSyncingPermission(newThreeBoxSyncingState)), setThreeBoxSyncingPermission: newThreeBoxSyncingState => {
if (newThreeBoxSyncingState) {
dispatch(turnThreeBoxSyncingOnAndInitialize())
} else {
dispatch(setThreeBoxSyncingPermission(newThreeBoxSyncingState))
}
},
} }
} }

@ -6,7 +6,7 @@ import AdvancedTab from '../advanced-tab.component'
import TextField from '../../../../components/ui/text-field' import TextField from '../../../../components/ui/text-field'
describe('AdvancedTab Component', () => { describe('AdvancedTab Component', () => {
it('should render correctly when threeBoxFeatureFlag is false', () => { it('should render correctly when threeBoxFeatureFlag', () => {
const root = shallow( const root = shallow(
<AdvancedTab />, <AdvancedTab />,
{ {
@ -16,19 +16,6 @@ describe('AdvancedTab Component', () => {
} }
) )
assert.equal(root.find('.settings-page__content-row').length, 7)
})
it('should render correctly threeBoxFeatureFlag is true', () => {
const root = shallow(
<AdvancedTab threeBoxFeatureFlag={true} />,
{
context: {
t: s => `_${s}`,
},
}
)
assert.equal(root.find('.settings-page__content-row').length, 8) assert.equal(root.find('.settings-page__content-row').length, 8)
}) })

@ -9,7 +9,6 @@ const defaultState = {
featureFlags: { featureFlags: {
sendHexData: false, sendHexData: false,
advancedInlineGas: false, advancedInlineGas: false,
threeBox: false,
}, },
preferences: { preferences: {
autoLogoutTimeLimit: 0, autoLogoutTimeLimit: 0,
@ -32,7 +31,6 @@ describe('AdvancedTab Container', () => {
autoLogoutTimeLimit: 0, autoLogoutTimeLimit: 0,
threeBoxSyncingAllowed: false, threeBoxSyncingAllowed: false,
threeBoxDisabled: false, threeBoxDisabled: false,
threeBoxFeatureFlag: false,
} }
assert.deepEqual(props, expected) assert.deepEqual(props, expected)

@ -16,7 +16,6 @@ const { ENVIRONMENT_TYPE_NOTIFICATION } = require('../../../app/scripts/lib/enum
const { hasUnconfirmedTransactions } = require('../helpers/utils/confirm-tx.util') const { hasUnconfirmedTransactions } = require('../helpers/utils/confirm-tx.util')
const gasDuck = require('../ducks/gas/gas.duck') const gasDuck = require('../ducks/gas/gas.duck')
const WebcamUtils = require('../../lib/webcam-utils') const WebcamUtils = require('../../lib/webcam-utils')
const { getFeatureFlags } = require('../selectors/selectors')
var actions = { var actions = {
_setBackgroundConnection: _setBackgroundConnection, _setBackgroundConnection: _setBackgroundConnection,
@ -382,8 +381,9 @@ var actions = {
restoreFromThreeBox, restoreFromThreeBox,
getThreeBoxLastUpdated, getThreeBoxLastUpdated,
setThreeBoxSyncingPermission, setThreeBoxSyncingPermission,
setRestoredFromThreeBoxToFalse, setShowRestorePromptToFalse,
turnThreeBoxSyncingOn, turnThreeBoxSyncingOn,
turnThreeBoxSyncingOnAndInitialize,
} }
module.exports = actions module.exports = actions
@ -2798,116 +2798,93 @@ function hideSeedPhraseBackupAfterOnboarding () {
} }
function initializeThreeBox () { function initializeThreeBox () {
return (dispatch, getState) => { return (dispatch) => {
const state = getState() return new Promise((resolve, reject) => {
background.initializeThreeBox((err) => {
if (getFeatureFlags(state).threeBox) { if (err) {
return new Promise((resolve, reject) => { dispatch(actions.displayWarning(err.message))
background.initializeThreeBox((err) => { return reject(err)
if (err) { }
dispatch(actions.displayWarning(err.message)) resolve()
return reject(err)
}
resolve()
})
}) })
} else { })
return Promise.resolve()
}
} }
} }
function setRestoredFromThreeBoxToFalse () { function setShowRestorePromptToFalse () {
return (dispatch, getState) => { return (dispatch) => {
const state = getState() return new Promise((resolve, reject) => {
if (getFeatureFlags(state).threeBox) { background.setShowRestorePromptToFalse((err) => {
return new Promise((resolve, reject) => { if (err) {
background.setRestoredFromThreeBoxToFalse((err) => { dispatch(actions.displayWarning(err.message))
if (err) { return reject(err)
dispatch(actions.displayWarning(err.message)) }
return reject(err) resolve()
}
resolve()
})
}) })
} else { })
return Promise.resolve()
}
} }
} }
function turnThreeBoxSyncingOn () { function turnThreeBoxSyncingOn () {
return (dispatch, getState) => { return (dispatch) => {
const state = getState() return new Promise((resolve, reject) => {
if (getFeatureFlags(state).threeBox) { background.turnThreeBoxSyncingOn((err) => {
return new Promise((resolve, reject) => { if (err) {
background.turnThreeBoxSyncingOn((err) => { dispatch(actions.displayWarning(err.message))
if (err) { return reject(err)
dispatch(actions.displayWarning(err.message)) }
return reject(err) resolve()
}
resolve()
})
}) })
} else { })
return Promise.resolve()
}
} }
} }
function restoreFromThreeBox (accountAddress) { function restoreFromThreeBox (accountAddress) {
return (dispatch, getState) => { return (dispatch) => {
const state = getState() return new Promise((resolve, reject) => {
if (getFeatureFlags(state).threeBox) { background.restoreFromThreeBox(accountAddress, (err) => {
return new Promise((resolve, reject) => { if (err) {
background.restoreFromThreeBox(accountAddress, (err) => { dispatch(actions.displayWarning(err.message))
if (err) { return reject(err)
dispatch(actions.displayWarning(err.message)) }
return reject(err) resolve()
}
resolve()
})
}) })
} else { })
return Promise.resolve()
}
} }
} }
function getThreeBoxLastUpdated () { function getThreeBoxLastUpdated () {
return (dispatch, getState) => { return (dispatch) => {
const state = getState() return new Promise((resolve, reject) => {
if (getFeatureFlags(state).threeBox) { background.getThreeBoxLastUpdated((err, lastUpdated) => {
return new Promise((resolve, reject) => { if (err) {
background.getThreeBoxLastUpdated((err, lastUpdated) => { dispatch(actions.displayWarning(err.message))
if (err) { return reject(err)
dispatch(actions.displayWarning(err.message)) }
return reject(err) resolve(lastUpdated)
}
resolve(lastUpdated)
})
}) })
} else { })
return Promise.resolve()
}
} }
} }
function setThreeBoxSyncingPermission (threeBoxSyncingAllowed) { function setThreeBoxSyncingPermission (threeBoxSyncingAllowed) {
return (dispatch, getState) => { return (dispatch) => {
const state = getState() return new Promise((resolve, reject) => {
if (getFeatureFlags(state).threeBox) { background.setThreeBoxSyncingPermission(threeBoxSyncingAllowed, (err) => {
return new Promise((resolve, reject) => { if (err) {
background.setThreeBoxSyncingPermission(threeBoxSyncingAllowed, (err) => { dispatch(actions.displayWarning(err.message))
if (err) { return reject(err)
dispatch(actions.displayWarning(err.message)) }
return reject(err) resolve()
}
resolve()
})
}) })
} else { })
return Promise.resolve() }
} }
function turnThreeBoxSyncingOnAndInitialize () {
return async (dispatch) => {
await dispatch(setThreeBoxSyncingPermission(true))
await dispatch(turnThreeBoxSyncingOn())
await dispatch(initializeThreeBox(true))
} }
} }

Loading…
Cancel
Save