Skip to content

Commit

Permalink
Adds transition for disabled wallets
Browse files Browse the repository at this point in the history
Resolves brave#11611

Auditors:

Test Plan:
  • Loading branch information
NejcZdovc committed Oct 20, 2017
1 parent 153f110 commit c18ba1d
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions app/browser/api/ledger.js
Expand Up @@ -155,17 +155,12 @@ const notifications = {
}, notifications.pollingInterval, state)
},
onLaunch: (state) => {
if (!getSetting(settings.PAYMENTS_ENABLED)) {
const enabled = getSetting(settings.PAYMENTS_ENABLED)
if (!enabled) {
return state
}

// One time conversion of wallet
const isNewInstall = state.get('firstRunTimestamp') === state.getIn(['migrations', 'batMercuryTimestamp'])
const hasUpgradedWallet = state.getIn(['migrations', 'batMercuryTimestamp']) !== state.getIn(['migrations', 'btc2BatTimestamp'])
if (!isNewInstall && !hasUpgradedWallet) {
state = state.setIn(['migrations', 'btc2BatTransitionPending'], true)
module.exports.transitionWalletToBat()
}
checkBtcBatMigrated(state, enabled)

if (hasFunds(state)) {
// Don't bother processing the rest, which are only notifications.
Expand Down Expand Up @@ -1306,8 +1301,12 @@ const initSynopsis = (state) => {
}

const enable = (state, paymentsEnabled) => {
if (paymentsEnabled && !getSetting(settings.PAYMENTS_NOTIFICATION_TRY_PAYMENTS_DISMISSED)) {
appActions.changeSetting(settings.PAYMENTS_NOTIFICATION_TRY_PAYMENTS_DISMISSED, true)
if (paymentsEnabled) {
checkBtcBatMigrated(state, paymentsEnabled)

if (!getSetting(settings.PAYMENTS_NOTIFICATION_TRY_PAYMENTS_DISMISSED)) {
appActions.changeSetting(settings.PAYMENTS_NOTIFICATION_TRY_PAYMENTS_DISMISSED, true)
}
}

if (synopsis) {
Expand Down Expand Up @@ -2262,6 +2261,20 @@ const yoDawg = (stateState) => {
return stateState
}

const checkBtcBatMigrated = (state, status) => {
if (!status) {
return state
}

// One time conversion of wallet
const isNewInstall = state.get('firstRunTimestamp') === state.getIn(['migrations', 'batMercuryTimestamp'])
const hasUpgradedWallet = state.getIn(['migrations', 'batMercuryTimestamp']) !== state.getIn(['migrations', 'btc2BatTimestamp'])
if (!isNewInstall && !hasUpgradedWallet) {
state = state.setIn(['migrations', 'btc2BatTransitionPending'], true)
module.exports.transitionWalletToBat()
}
}

let newClient = null
const transitionWalletToBat = () => {
let newPaymentId, result
Expand Down

0 comments on commit c18ba1d

Please sign in to comment.