Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Hotfix to correct gaiaHubConfig info in profile.json #1776

Merged
merged 8 commits into from Jan 8, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/js/store/reducers.js
Expand Up @@ -39,7 +39,7 @@ export function initializeStateVersion() {
* and other state is regenerated.
* @type {number}
*/
export const CURRENT_VERSION: number = 16
export const CURRENT_VERSION: number = 17

const AppReducer = combineReducers({
account: AccountReducer,
Expand Down
127 changes: 82 additions & 45 deletions app/js/update/index.js
Expand Up @@ -10,7 +10,8 @@ import { AppHomeWrapper, ShellParent } from '@blockstack/ui'
import {
selectAccountCreated,
selectEncryptedBackupPhrase,
selectIdentityAddresses
selectIdentityAddresses,
selectIdentityKeypairs
} from '@common/store/selectors/account'
import {
selectDefaultIdentity,
Expand All @@ -28,7 +29,8 @@ import {
hasLegacyCoreStateVersion,
migrateLegacyCoreEndpoints
} from '@utils/api-utils'
import { decrypt } from '@utils'
import { uploadProfile } from '../account/utils'
import { decrypt, signProfileForUpload } from '@utils'
const VIEWS = {
INITIAL: 0,
SUCCESS: 1,
Expand All @@ -43,7 +45,8 @@ const mapStateToProps = state => ({
localIdentities: selectLocalIdentities(state),
defaultIdentityIndex: selectDefaultIdentity(state),
accountCreated: selectAccountCreated(state),
identityAddresses: selectIdentityAddresses(state)
identityAddresses: selectIdentityAddresses(state),
identityKeypairs: selectIdentityKeypairs(state)
})

const mapDispatchToProps = dispatch =>
Expand Down Expand Up @@ -137,51 +140,85 @@ class UpdatePage extends React.Component {
const dataBuffer = new Buffer(encryptedBackupPhrase, 'hex')
const { password } = this.state

return decrypt(dataBuffer, password)
.then(backupPhraseBuffer => {
this.setState(
{
upgradeInProgress: true
},
() =>
setTimeout(() => {
console.debug('decryptKeyAndResetState: correct password!')
const backupPhrase = backupPhraseBuffer.toString()
const numberOfIdentities =
localIdentities.length >= 1 ? localIdentities.length : 1
this.setState({
encryptedBackupPhrase,
backupPhrase,
defaultIdentityIndex,
numberOfIdentities
})
if (hasLegacyCoreStateVersion()) {
const migratedApi = migrateLegacyCoreEndpoints(api)
this.props.migrateAPIEndpoints(migratedApi)
}
// clear our state
this.props.updateState()
const updateProfileUrls = localIdentities.map((identity, index) =>
new Promise(async (resolve, reject) => {
try {
const signedProfileTokenData = signProfileForUpload(
identity.profile,
this.props.identityKeypairs[index],
this.props.api
)
console.log('newProfile', signedProfileTokenData)
hstove marked this conversation as resolved.
Show resolved Hide resolved
uploadProfile(
this.props.api,
identity,
this.props.identityKeypairs[index],
signedProfileTokenData
).then(resolve).catch(reject)
} catch (error) {
reject(error)
}

}))

// generate new account and IDs
this.createAccount().then(() => this.createNewIds())
.then(() => this.props.refreshIdentities(
this.props.api,
this.props.identityAddresses
))
}, 150)
)
})
.catch(error => {
console.error('decryptKeyAndResetState: invalid password', error)
this.setState({
loading: false,
password: null,
errors: {
password: 'Incorrect Password'
},
status: 'error'
return Promise.all(updateProfileUrls).then(() => {
console.log('updated profile URLs')
return decrypt(dataBuffer, password)
.then(backupPhraseBuffer => {
this.setState(
{
upgradeInProgress: true
},
() =>
setTimeout(() => {
console.debug('decryptKeyAndResetState: correct password!')
const backupPhrase = backupPhraseBuffer.toString()
const numberOfIdentities =
localIdentities.length >= 1 ? localIdentities.length : 1
this.setState({
encryptedBackupPhrase,
backupPhrase,
defaultIdentityIndex,
numberOfIdentities
})
if (hasLegacyCoreStateVersion()) {
const migratedApi = migrateLegacyCoreEndpoints(api)
this.props.migrateAPIEndpoints(migratedApi)
}
// clear our state
this.props.updateState()

// generate new account and IDs
this.createAccount().then(() => this.createNewIds())
.then(() => this.props.refreshIdentities(
this.props.api,
this.props.identityAddresses
))
}, 150)
)
})
.catch(error => {
console.error('decryptKeyAndResetState: invalid password', error)
this.setState({
loading: false,
password: null,
errors: {
password: 'Incorrect Password'
},
status: 'error'
})
})
}).catch(error => {
console.error('upgradeBlockstackState: error updating profile', error)
this.setState({
loading: false,
password: null,
errors: {
password: 'Unable to update profile'
},
status: 'error'
})
})
}

/**
Expand Down
4 changes: 3 additions & 1 deletion app/js/utils/profile-utils.js
Expand Up @@ -175,7 +175,9 @@ export function signProfileForUpload(profile, keypair, api) {
profile = {
hstove marked this conversation as resolved.
Show resolved Hide resolved
...profile,
api: {
gaiaHubConfig: api.gaiaHubConfig,
gaiaHubConfig: {
url_prefix: api.gaiaHubConfig.url_prefix
},
gaiaHubUrl: api.gaiaHubUrl
}
}
Expand Down