Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Merge pull request #11601 from brave/yodawg
Browse files Browse the repository at this point in the history
Fix ledger state persistence, add recovery for improperly persisted state
  • Loading branch information
bsclifton committed Oct 19, 2017
1 parent 7d02334 commit d357d1a
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions app/browser/api/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -2254,6 +2254,14 @@ const deleteSynopsis = () => {
synopsis.publishers = {}
}

// fix for incorrectly persisted state (see #11585)
const yoDawg = (stateState) => {
while (stateState.hasOwnProperty('state') && stateState.state.persona) {
stateState = stateState.state
}
return stateState
}

let newClient = null
const transitionWalletToBat = () => {
let newPaymentId, result
Expand All @@ -2271,9 +2279,10 @@ const transitionWalletToBat = () => {
return
}
const parsedData = JSON.parse(data)
newClient = ledgerClient(parsedData.state.personaId,
underscore.extend(parsedData.options, {roundtrip: roundtrip}, clientOptions),
parsedData)
const state = yoDawg(parsedData)
newClient = ledgerClient(state.personaId,
underscore.extend(state.options, {roundtrip: roundtrip}, clientOptions),
state)
transitionWalletToBat()
})
return
Expand All @@ -2287,7 +2296,7 @@ const transitionWalletToBat = () => {
try {
clientprep()
newClient = ledgerClient(null, underscore.extend({roundtrip: roundtrip}, clientOptions), null)
muonWriter(newClientPath, newClient)
muonWriter(newClientPath, newClient.state)
} catch (ex) {
return console.error('ledger client creation error(2): ', ex)
}
Expand All @@ -2302,7 +2311,7 @@ const transitionWalletToBat = () => {

if (typeof delayTime === 'undefined') delayTime = random.randomInt({ min: 1, max: 500 })

muonWriter(newClientPath, newClient)
muonWriter(newClientPath, newClient.state)

setTimeout(() => transitionWalletToBat(), delayTime)
})
Expand Down

0 comments on commit d357d1a

Please sign in to comment.