Skip to content

Commit

Permalink
Get and update sync code only after sync chain is created
Browse files Browse the repository at this point in the history
Otherwise, we end up caching wrong sync code when page is loaded and it
will only be updated after a page refresh
  • Loading branch information
darkdh committed Jul 27, 2020
1 parent 87e6d0e commit 4a22990
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions browser/resources/settings/brave_sync_page/brave_sync_configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ Polymer({
},

attached: async function() {
const [syncCode, deviceList] = await Promise.all([
this.browserProxy_.getSyncCode(),
this.browserProxy_.getDeviceList()
])
this.syncCode = syncCode
const deviceList = await this.browserProxy_.getDeviceList()
this.addWebUIListener('device-info-changed', this.handleDeviceInfo_.bind(this))
this.handleDeviceInfo_(deviceList)
},
Expand All @@ -82,11 +78,24 @@ Polymer({
return displayDate.toDateString()
},

onViewSyncCode_: function() {
/*
* This only sets sync code when it is not already set. It needs to be cleared
* when sync chain reset
*/
ensureSetSyncCode_: async function() {
if (!!this.syncCode)
return
const syncCode = await this.browserProxy_.getSyncCode()
this.syncCode = syncCode
},

onViewSyncCode_: async function() {
await this.ensureSetSyncCode_()
this.syncCodeDialogType_ = 'words'
},

onAddDevice_: function() {
onAddDevice_: async function() {
await this.ensureSetSyncCode_()
this.syncCodeDialogType_ = 'choose'
},

Expand All @@ -101,6 +110,9 @@ Polymer({
return
}
await this.browserProxy_.resetSyncChain();
// Clear sync code because user might use the same page to create a new sync
// chain without reload
this.syncCode = undefined
const router = Router.getInstance();
router.navigateTo(router.getRoutes().BRAVE_SYNC);
}
Expand Down

0 comments on commit 4a22990

Please sign in to comment.