Skip to content

Commit

Permalink
Turn off threebox by default
Browse files Browse the repository at this point in the history
  • Loading branch information
danjm committed Sep 26, 2019
1 parent f717ec9 commit 03820be
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 11 deletions.
29 changes: 21 additions & 8 deletions app/scripts/controllers/threebox.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ThreeBoxController {
})

const initState = {
threeBoxSyncingAllowed: true,
threeBoxSyncingAllowed: false,
restoredFromThreeBox: null,
threeBoxLastUpdated: 0,
...opts.initState,
Expand All @@ -60,7 +60,9 @@ class ThreeBoxController {
this.registeringUpdates = false
this.lastMigration = migrations.sort((a, b) => a.version - b.version).slice(-1)[0]

this.init()
if (initState.threeBoxSyncingAllowed) {
this.init()
}
}

async init () {
Expand All @@ -83,6 +85,7 @@ class ThreeBoxController {
}

await this.space.private.set('metamaskBackup', JSON.stringify(newState))
await this.setRestoredFromThreeBoxToFalse()
}
} catch (error) {
console.error(error)
Expand All @@ -107,13 +110,23 @@ class ThreeBoxController {
})
}

async _checkThreeBoxBackupExistance () {

}

async new3Box () {
const accounts = await this.keyringController.getAccounts()
const address = accounts[0]

if (this.getThreeBoxSyncingState()) {
this.address = await this.keyringController.getAppKeyAddress(accounts[0], 'wallet://3box.metamask.io')
let backupExists
try {
const threeBoxConfig = await Box.getConfig(this.address)
backupExists = threeBoxConfig.spaces && threeBoxConfig.spaces.metamask
} catch (e) {
log.error(e)
backupExists = false
}
if (this.getThreeBoxSyncingState() || backupExists) {
this.store.updateState({ threeBoxSynced: false })
this.address = await this.keyringController.getAppKeyAddress(address, 'wallet://3box.metamask.io')

let timedOut = false
const syncTimeout = setTimeout(() => {
Expand All @@ -125,13 +138,13 @@ class ThreeBoxController {
})
}, SYNC_TIMEOUT)
try {
this.box = await Box.openBox(address, this.provider)
this.box = await Box.openBox(this.address, this.provider)
await this._waitForOnSyncDone()
this.space = await this.box.openSpace('metamask', {
onSyncDone: async () => {
const stateUpdate = {
threeBoxSynced: true,
threeBoxAddress: address,
threeBoxAddress: this.address,
}
if (timedOut) {
log.info(`3Box sync completed after timeout; no longer disabled`)
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1699,7 +1699,7 @@ module.exports = class MetamaskController extends EventEmitter {
}

async initializeThreeBox () {
await this.threeBoxController.new3Box()
await this.threeBoxController.init()
}

/**
Expand Down
7 changes: 7 additions & 0 deletions development/mock-3box.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ class Mock3Box {
logout: () => {},
})
}

static async getConfig (address) {
const backup = await loadFromMock3Box(`${address}-metamask-metamaskBackup`)
return backup
? { spaces: { metamask: {} } }
: {}
}
}

module.exports = Mock3Box
19 changes: 18 additions & 1 deletion test/e2e/threebox.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('MetaMask', function () {
})
})

describe('updates settings and address book', () => {
describe('turns on threebox syncing', () => {
it('goes to the settings screen', async () => {
await driver.findElement(By.css('.account-menu__icon')).click()
await delay(regularDelayMs)
Expand All @@ -111,6 +111,23 @@ describe('MetaMask', function () {
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 () => {
const toggleButton = await findElement(driver, By.css('.toggle-button > div'))
await toggleButton.click()
Expand Down
9 changes: 8 additions & 1 deletion ui/app/pages/settings/advanced-tab/advanced-tab.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
setShowFiatConversionOnTestnetsPreference,
setAutoLogoutTimeLimit,
setThreeBoxSyncingPermission,
turnThreeBoxSyncingOnAndInitialize,
} from '../../../store/actions'
import {preferencesSelector} from '../../../selectors/selectors'

Expand Down Expand Up @@ -49,7 +50,13 @@ export const mapDispatchToProps = dispatch => {
setAutoLogoutTimeLimit: value => {
return dispatch(setAutoLogoutTimeLimit(value))
},
setThreeBoxSyncingPermission: newThreeBoxSyncingState => dispatch(setThreeBoxSyncingPermission(newThreeBoxSyncingState)),
setThreeBoxSyncingPermission: newThreeBoxSyncingState => {
if (newThreeBoxSyncingState) {
dispatch(turnThreeBoxSyncingOnAndInitialize())
} else {
dispatch(setThreeBoxSyncingPermission(newThreeBoxSyncingState))
}
},
}
}

Expand Down
9 changes: 9 additions & 0 deletions ui/app/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ var actions = {
setThreeBoxSyncingPermission,
setRestoredFromThreeBoxToFalse,
turnThreeBoxSyncingOn,
turnThreeBoxSyncingOnAndInitialize,
}

module.exports = actions
Expand Down Expand Up @@ -2879,3 +2880,11 @@ function setThreeBoxSyncingPermission (threeBoxSyncingAllowed) {
})
}
}

function turnThreeBoxSyncingOnAndInitialize () {
return async (dispatch) => {
await dispatch(setThreeBoxSyncingPermission(true))
await dispatch(turnThreeBoxSyncingOn())
await dispatch(initializeThreeBox(true))
}
}

0 comments on commit 03820be

Please sign in to comment.