From ccee1223cbe565c546b6f103b661ae749bc85971 Mon Sep 17 00:00:00 2001 From: NejcZdovc Date: Tue, 6 Feb 2018 16:46:07 +0100 Subject: [PATCH 1/2] Removes transition btc->bat code Resolves #12712 Auditors: Test Plan: --- app/browser/api/ledger.js | 166 ------------- app/browser/api/ledgerNotifications.js | 53 +---- app/browser/reducers/ledgerReducer.js | 21 -- app/common/state/migrationState.js | 69 ------ .../brave/locales/en-US/app.properties | 4 - .../locales/en-US/preferences.properties | 2 - app/locale.js | 4 - .../preferences/payment/enabledContent.js | 91 ------- .../components/preferences/paymentsTab.js | 8 +- app/renderer/components/styles/animations.js | 17 +- app/sessionStore.js | 6 - docs/state.md | 6 - js/actions/appActions.js | 18 -- js/constants/appConstants.js | 3 - .../browser/api/ledgerNotificationsTest.js | 225 +----------------- test/unit/app/browser/api/ledgerTest.js | 214 +---------------- .../app/browser/reducers/ledgerReducerTest.js | 42 +--- 17 files changed, 20 insertions(+), 929 deletions(-) delete mode 100644 app/common/state/migrationState.js diff --git a/app/browser/api/ledger.js b/app/browser/api/ledger.js index e9a0bafa1b8..b5f3369b822 100644 --- a/app/browser/api/ledger.js +++ b/app/browser/api/ledger.js @@ -26,7 +26,6 @@ const appActions = require('../../../js/actions/appActions') // State const ledgerState = require('../../common/state/ledgerState') const pageDataState = require('../../common/state/pageDataState') -const migrationState = require('../../common/state/migrationState') const updateState = require('../../common/state/updateState') // Constants @@ -85,7 +84,6 @@ let verifiedTimeoutId = false let v2RulesetDB const v2RulesetPath = 'ledger-rulesV2.leveldb' const statePath = 'ledger-state.json' -const newClientPath = 'ledger-newstate.json' // Definitions const clientOptions = { @@ -1223,8 +1221,6 @@ const checkPromotions = () => { const enable = (state, paymentsEnabled) => { if (paymentsEnabled) { - state = checkBtcBatMigrated(state, paymentsEnabled) - if (!getSetting(settings.PAYMENTS_NOTIFICATION_TRY_PAYMENTS_DISMISSED)) { appActions.changeSetting(settings.PAYMENTS_NOTIFICATION_TRY_PAYMENTS_DISMISSED, true) } @@ -1915,19 +1911,6 @@ const onCallback = (state, result, delayTime) => { // persist the new ledger state muonWriter(statePath, regularResults) - // delete the temp file used during transition (if it still exists) - if (client && client.options && client.options.version === 'v2') { - const fs = require('fs') - fs.access(pathName(newClientPath), fs.FF_OK, (err) => { - if (err) { - return - } - fs.unlink(pathName(newClientPath), (err) => { - if (err) console.error('unlink error: ' + err.toString()) - }) - }) - } - run(state, delayTime) return state @@ -2019,7 +2002,6 @@ const initialize = (state, paymentsEnabled) => { if (!paymentsEnabled) { client = null - newClient = false return ledgerState.resetInfo(state, true) } @@ -2393,147 +2375,6 @@ 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 -} - -const checkBtcBatMigrated = (state, paymentsEnabled) => { - if (!paymentsEnabled) { - return state - } - - // One time conversion of wallet - const isNewInstall = migrationState.isNewInstall(state) - const hasUpgradedWallet = migrationState.hasUpgradedWallet(state) - if (!isNewInstall && !hasUpgradedWallet) { - state = migrationState.setTransitionStatus(state, true) - module.exports.transitionWalletToBat() - } else { - state = migrationState.setTransitionStatus(state, false) - } - - return state -} - -let newClient = null -const getNewClient = () => { - return newClient -} - -let busyRetryCount = 0 - -const transitionWalletToBat = () => { - let newPaymentId, result - - if (newClient === true) return - clientprep() - - if (!client) { - console.log('Client is not initialized, will try again') - return - } - - // only attempt this transition if the wallet is v1 - if (client.options && client.options.version !== 'v1') { - // older versions incorrectly marked this for transition - // this will clean them up (no more bouncy ball) - appActions.onBitcoinToBatTransitioned() - return - } - - // Restore newClient from the file (if one exists) - if (!newClient) { - const fs = require('fs') - try { - fs.accessSync(pathName(newClientPath), fs.FF_OK) - fs.readFile(pathName(newClientPath), (error, data) => { - if (error) { - console.error(`ledger client: can't read ${newClientPath} to restore newClient`) - return - } - const parsedData = JSON.parse(data) - const state = yoDawg(parsedData) - newClient = ledgerClient(state.personaId, - underscore.extend(state.options, {roundtrip: module.exports.roundtrip}, clientOptions), - state) - transitionWalletToBat() - }) - return - } catch (err) {} - } - - // Create new client - if (!newClient) { - try { - newClient = ledgerClient(null, underscore.extend({roundtrip: module.exports.roundtrip}, clientOptions), null) - muonWriter(newClientPath, newClient.state) - } catch (ex) { - console.error('ledger client creation error(2): ', ex) - return - } - } - - newPaymentId = newClient.getPaymentId() - if (!newPaymentId) { - newClient.sync((err, result, delayTime) => { - if (err) { - return console.error('ledger client error(3): ' + JSON.stringify(err, null, 2) + (err.stack ? ('\n' + err.stack) : '')) - } - - if (typeof delayTime === 'undefined') delayTime = random.randomInt({ min: 1, max: 500 }) - - if (newClient) { - muonWriter(newClientPath, newClient.state) - } - - setTimeout(() => transitionWalletToBat(), delayTime) - }) - return - } - - if (client.busyP()) { - if (++busyRetryCount > 3) { - console.log('ledger client is currently busy; transition will be retried on next launch') - return - } - const delayTime = random.randomInt({ - min: ledgerUtil.milliseconds.minute, - max: 10 * ledgerUtil.milliseconds.minute - }) - console.log('ledger client is currently busy; transition will be retried shortly (this was attempt ' + busyRetryCount + ')') - setTimeout(() => transitionWalletToBat(), delayTime) - return - } - - appActions.onBitcoinToBatBeginTransition() - - try { - client.transition(newPaymentId, (err, properties) => { - if (err || !newClient) { - console.error('ledger client transition error: ', err) - } else { - result = newClient.transitioned(properties) - client = newClient - newClient = true - // NOTE: onLedgerCallback will save latest client to disk as ledger-state.json - appActions.onLedgerCallback(result, random.randomInt({ - min: ledgerUtil.milliseconds.minute, - max: 10 * ledgerUtil.milliseconds.minute - })) - appActions.onBitcoinToBatTransitioned() - ledgerNotifications.showBraveWalletUpdated() - getPublisherTimestamp() - } - }) - } catch (ex) { - console.error('exception during ledger client transition: ', ex) - } -} - let currentMediaKey = null const onMediaRequest = (state, xhr, type, tabId) => { if (!xhr || type == null) { @@ -2872,13 +2713,10 @@ const getMethods = () => { migration, onInitRead, deleteSynopsis, - transitionWalletToBat, - getNewClient, normalizePinned, roundToTarget, savePublisherData, pruneSynopsis, - checkBtcBatMigrated, onMediaRequest, onMediaPublisher, saveVisit, @@ -2900,7 +2738,6 @@ const getMethods = () => { privateMethods = { enable, addSiteVisit, - checkBtcBatMigrated, clearVisitsByPublisher: function () { visitsByPublisher = {} }, @@ -2911,9 +2748,6 @@ const getMethods = () => { setSynopsis: (data) => { synopsis = data }, - resetNewClient: () => { - newClient = false - }, getClient: () => { return client }, diff --git a/app/browser/api/ledgerNotifications.js b/app/browser/api/ledgerNotifications.js index 3fdf8f78a01..5387b6f5374 100644 --- a/app/browser/api/ledgerNotifications.js +++ b/app/browser/api/ledgerNotifications.js @@ -12,7 +12,6 @@ const settings = require('../../../js/constants/settings') // State const ledgerState = require('../../common/state/ledgerState') -const migrationState = require('../../common/state/migrationState') // Actions const appActions = require('../../../js/actions/appActions') @@ -27,8 +26,7 @@ const text = { paymentDone: undefined, addFunds: locale.translation('addFundsNotification'), tryPayments: locale.translation('notificationTryPayments'), - reconciliation: locale.translation('reconciliationNotification'), - walletConvertedToBat: locale.translation('walletConvertedToBat') + reconciliation: locale.translation('reconciliationNotification') } const pollingInterval = 15 * ledgerUtil.milliseconds.minute // 15 * minutes @@ -76,28 +74,11 @@ const onLaunch = (state) => { return state } - const ledger = require('./ledger') - state = ledger.checkBtcBatMigrated(state, enabled) - if (hasFunds(state)) { // Don't bother processing the rest, which are only if (!getSetting(settings.PAYMENTS_NOTIFICATIONS)) { return state } - - // Show one-time BAT conversion message: - // - if payments are enabled - // - user has a positive balance - // - this is an existing profile (new profiles will have firstRunTimestamp matching batMercuryTimestamp) - // - wallet has been transitioned - // - notification has not already been shown yet - // (see https://github.com/brave/browser-laptop/issues/11021) - const isNewInstall = migrationState.isNewInstall(state) - const hasUpgradedWallet = migrationState.hasUpgradedWallet(state) - const hasBeenNotified = migrationState.hasBeenNotified(state) - if (!isNewInstall && hasUpgradedWallet && !hasBeenNotified) { - module.exports.showBraveWalletUpdated() - } } return state @@ -181,16 +162,6 @@ const onResponse = (message, buttonIndex, activeWindow) => { appActions.changeSetting(settings.PAYMENTS_NOTIFICATION_TRY_PAYMENTS_DISMISSED, true) break - case text.walletConvertedToBat: - if (buttonIndex === 0) { - // Open backup modal - appActions.createTabRequested({ - url: 'about:preferences#payments?ledgerBackupOverlayVisible', - windowId: activeWindow.id - }) - } - break - default: return } @@ -324,27 +295,6 @@ const showPaymentDone = (transactionContributionFiat) => { }) } -const showBraveWalletUpdated = () => { - appActions.onBitcoinToBatNotified() - - appActions.showNotification({ - position: 'global', - greeting: text.hello, - message: text.walletConvertedToBat, - // Learn More. - buttons: [ - {text: locale.translation('walletConvertedBackup')}, - {text: locale.translation('walletConvertedDismiss')} - ], - options: { - style: 'greetingStyle', - persist: false, - advancedLink: 'https://brave.com/faq-payments/#brave-payments', - advancedText: locale.translation('walletConvertedLearnMore') - } - }) -} - const onPromotionReceived = (state) => { const promotion = ledgerState.getPromotionNotification(state) @@ -410,7 +360,6 @@ const getMethods = () => { showPaymentDone, init, onLaunch, - showBraveWalletUpdated, onInterval, onPromotionReceived, removePromotionNotification, diff --git a/app/browser/reducers/ledgerReducer.js b/app/browser/reducers/ledgerReducer.js index ed4e3b74589..c75ab61cf57 100644 --- a/app/browser/reducers/ledgerReducer.js +++ b/app/browser/reducers/ledgerReducer.js @@ -13,7 +13,6 @@ const settings = require('../../../js/constants/settings') // State const ledgerState = require('../../common/state/ledgerState') const pageDataState = require('../../common/state/pageDataState') -const migrationState = require('../../common/state/migrationState') const updateState = require('../../common/state/updateState') // Utils @@ -230,10 +229,6 @@ const ledgerReducer = (state, action, immutableAction) => { case appConstants.APP_ON_LEDGER_WALLET_CREATE: { ledgerApi.boot() - if (ledgerApi.getNewClient() === null) { - state = migrationState.setConversionTimestamp(state, new Date().getTime()) - state = migrationState.setTransitionStatus(state, false) - } break } case appConstants.APP_ON_BOOT_STATE_FILE: @@ -307,22 +302,6 @@ const ledgerReducer = (state, action, immutableAction) => { state = ledgerApi.onInitRead(state, action.parsedData) break } - case appConstants.APP_ON_BTC_TO_BAT_NOTIFIED: - { - state = migrationState.setNotifiedTimestamp(state, new Date().getTime()) - break - } - case appConstants.APP_ON_BTC_TO_BAT_BEGIN_TRANSITION: - { - state = migrationState.setTransitionStatus(state, true) - break - } - case appConstants.APP_ON_BTC_TO_BAT_TRANSITIONED: - { - state = migrationState.setConversionTimestamp(state, new Date().getTime()) - state = migrationState.setTransitionStatus(state, false) - break - } case appConstants.APP_ON_LEDGER_QR_GENERATED: { state = ledgerState.saveQRCode(state, action.get('currency'), action.get('image')) diff --git a/app/common/state/migrationState.js b/app/common/state/migrationState.js deleted file mode 100644 index 06f8985527d..00000000000 --- a/app/common/state/migrationState.js +++ /dev/null @@ -1,69 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -const assert = require('assert') - -const {makeImmutable, isMap} = require('../../common/state/immutableUtil') - -const validateState = function (state) { - state = makeImmutable(state) - assert.ok(isMap(state), 'state must be an Immutable.Map') - assert.ok(isMap(state.get('migrations')), 'state must contain an Immutable.Map of migrations') - return state -} - -const migrationState = { - setTransitionStatus: (state, value) => { - state = validateState(state) - if (value == null) { - return state - } - - return state.setIn(['migrations', 'btc2BatTransitionPending'], value) - }, - - inTransition: (state) => { - state = validateState(state) - return state.getIn(['migrations', 'btc2BatTransitionPending']) === true - }, - - setConversionTimestamp: (state, value) => { - state = validateState(state) - if (value == null) { - return state - } - - return state.setIn(['migrations', 'btc2BatTimestamp'], value) - }, - - setNotifiedTimestamp: (state, value) => { - state = validateState(state) - if (value == null) { - return state - } - - return state.setIn(['migrations', 'btc2BatNotifiedTimestamp'], value) - }, - - isNewInstall: (state) => { - state = validateState(state) - return state.get('firstRunTimestamp') === state.getIn(['migrations', 'batMercuryTimestamp']) - }, - - // we set this values when we initialize 0.19 state and this will be only true when transition is done - // or when you create wallet on 0.19+ version - hasUpgradedWallet: (state) => { - state = validateState(state) - return state.getIn(['migrations', 'batMercuryTimestamp']) !== state.getIn(['migrations', 'btc2BatTimestamp']) - }, - - // we set this values when we initialize 0.19 state and this will be only true when transition is done - // or when you create wallet on 0.19+ version - hasBeenNotified: (state) => { - state = validateState(state) - return state.getIn(['migrations', 'batMercuryTimestamp']) !== state.getIn(['migrations', 'btc2BatNotifiedTimestamp']) - } -} - -module.exports = migrationState diff --git a/app/extensions/brave/locales/en-US/app.properties b/app/extensions/brave/locales/en-US/app.properties index 283a1de9e02..f4df1bb2d58 100644 --- a/app/extensions/brave/locales/en-US/app.properties +++ b/app/extensions/brave/locales/en-US/app.properties @@ -260,10 +260,6 @@ versionInformation=Version Information videoCapturePermission=Video Capture viewCertificate=View Certificate viewPageSource=View Page Source -walletConvertedBackup=Back up your new wallet -walletConvertedDismiss=Later -walletConvertedLearnMore=Learn More -walletConvertedToBat=Your BTC will be converted to BAT and will appear in your Brave wallet within approximately 30 minutes. widevinePanelTitle=Brave needs to install Google Widevine to proceed windowCaptionButtonClose=Close windowCaptionButtonMaximize=Maximize diff --git a/app/extensions/brave/locales/en-US/preferences.properties b/app/extensions/brave/locales/en-US/preferences.properties index 34e8ba44a26..ea203fa450a 100644 --- a/app/extensions/brave/locales/en-US/preferences.properties +++ b/app/extensions/brave/locales/en-US/preferences.properties @@ -160,8 +160,6 @@ lastPass=LastPass® ledgerBackupText1=Below, you will find the anonymized recovery key that is required if you ever lose access to this computer. ledgerBackupText2=Make sure you keep this key private, or else your wallet will be compromised. ledgerBackupTitle=Backup your Brave wallet -leaderLoaderText1=Please wait while we convert your Bitcoin to BAT. -leaderLoaderText2=This can take anywhere from a few minutes to several hours, due to the Bitcoin transaction confirmation process, and will continue normally even if you quit Brave. ledgerPaymentsShown=Brave Payments ledgerRecoveryContent=Your previous wallet will now be used. Your new wallet will be discarded. ledgerRecoveryFailedMessage=Please re-enter keys or try different keys. diff --git a/app/locale.js b/app/locale.js index b76e0320a77..f88494c4b2b 100644 --- a/app/locale.js +++ b/app/locale.js @@ -226,10 +226,6 @@ var rendererIdentifiers = function () { 'no', 'noThanks', 'neverForThisSite', - 'walletConvertedBackup', - 'walletConvertedDismiss', - 'walletConvertedLearnMore', - 'walletConvertedToBat', 'dappDetected', 'dappDismiss', 'dappEnableExtension', diff --git a/app/renderer/components/preferences/payment/enabledContent.js b/app/renderer/components/preferences/payment/enabledContent.js index 7bce55ffc36..8c907d750d0 100644 --- a/app/renderer/components/preferences/payment/enabledContent.js +++ b/app/renderer/components/preferences/payment/enabledContent.js @@ -28,7 +28,6 @@ const LedgerTable = require('./ledgerTable') // style const globalStyles = require('../../styles/global') const {paymentStylesVariables} = require('../../styles/payment') -const {loaderAnimation} = require('../../styles/animations') const closeButton = require('../../../../../img/toolbar/stoploading_btn.svg') const cx = require('../../../../../js/lib/classSet') @@ -287,36 +286,9 @@ class EnabledContent extends ImmutableComponent { const ledgerData = this.props.ledgerData const walletStatusText = walletStatus(ledgerData) const contributionAmount = ledgerState.getContributionAmount(null, ledgerData.get('contributionAmount'), this.props.settings) - const inTransition = ledgerData.getIn(['migration', 'btc2BatTransitionPending']) === true const amountList = ledgerData.get('monthlyAmounts') || ledgerUtil.defaultMonthlyAmounts return
-
-
-

-

-

-
-
-
-
-
-
@@ -491,69 +463,6 @@ const styles = StyleSheet.create({ padding: '0 10px' }, - enabledContent__loader: { - background: '#fafafa', - zIndex: 3, - position: 'absolute', - left: 0, - top: 0, - width: '100%', - height: '100%', - margin: 0, - opacity: 0, - transform: 'translateX(-1000%)', - transition: 'opacity .4s ease-out, transform .1s .4s ease' - }, - - enabledContent__loader_show: { - opacity: 1, - transform: 'translateX(0)', - transition: 'opacity .4s ease-out' - }, - - enabledContent__loader__text: { - textAlign: 'center', - padding: '50px 0 20px', - display: 'block', - color: '#444' - }, - - enabledContent__loader__wrap: { - width: '45px', - left: 0, - right: 0, - margin: '50px auto 0' - }, - - enabledContent__loader__wrap__line: { - display: 'inline-block', - width: '15px', - height: '15px', - borderRadius: '15px', - animationName: [loaderAnimation], - animationDuration: '.6s', - animationIterationCount: 'infinite' - }, - - enabledContent__loader__wrap__line_1: { - backgroundColor: '#FF5000', - animationDelay: '.1s' - }, - - enabledContent__loader__wrap__line_2: { - backgroundColor: '#9E1F63', - animationDelay: '.2s' - }, - - enabledContent__loader__wrap__line_3: { - backgroundColor: '#662D91', - animationDelay: '.3s' - }, - - enabledContent__loader__wrap__line_off: { - animationName: 'none' - }, - enabledContent__grant: { position: 'absolute', zIndex: 3, diff --git a/app/renderer/components/preferences/paymentsTab.js b/app/renderer/components/preferences/paymentsTab.js index 3a6cd924840..b7cb9f97301 100644 --- a/app/renderer/components/preferences/paymentsTab.js +++ b/app/renderer/components/preferences/paymentsTab.js @@ -165,8 +165,6 @@ class PaymentsTab extends ImmutableComponent { render () { const enabled = this.props.ledgerData.get('created') - const inTransition = this.props.ledgerData.getIn(['migration', 'btc2BatTransitionPending']) === true - const enableSettings = enabled && !inTransition const deletedSites = this.deletedSites const showDeletedSites = deletedSites.length > 0 @@ -332,11 +330,11 @@ class PaymentsTab extends ImmutableComponent { {}} + onClick={enabled ? this.props.showOverlay.bind(this, 'advancedSettings') : () => {}} />
diff --git a/app/renderer/components/styles/animations.js b/app/renderer/components/styles/animations.js index ceef54f3a12..8c10a2ea28a 100644 --- a/app/renderer/components/styles/animations.js +++ b/app/renderer/components/styles/animations.js @@ -42,20 +42,6 @@ const widthIncreaseElementKeyframes = (start, end) => ({ width: [start, end] }) -const loaderAnimation = { - '0': { - transform: 'translate(0,0)' - }, - - '50%': { - transform: 'translate(0,15px)' - }, - - '100%': { - transform: 'translate(0,0)' - } -} - const tabFadeInKeyframes = { '0%': { opacity: 0.5 @@ -76,6 +62,5 @@ module.exports = { opacityIncreaseElementKeyframes, widthIncreaseKeyframes, widthIncreaseElementKeyframes, - tabFadeInKeyframes, - loaderAnimation + tabFadeInKeyframes } diff --git a/app/sessionStore.js b/app/sessionStore.js index 62a4e55c881..a5af649227e 100644 --- a/app/sessionStore.js +++ b/app/sessionStore.js @@ -1084,12 +1084,6 @@ module.exports.defaultAppState = () => { publishers: {} }, promotion: {} - }, - migrations: { - batMercuryTimestamp: now, - btc2BatTimestamp: now, - btc2BatNotifiedTimestamp: now, - btc2BatTransitionPending: false } } } diff --git a/docs/state.md b/docs/state.md index f02a7ce1799..565e7d91923 100644 --- a/docs/state.md +++ b/docs/state.md @@ -374,12 +374,6 @@ AppStore } } }, - migrations: { - batMercuryTimestamp: integer, // when session is upgraded (and this new schema added) - btc2BatTimestamp: integer, // when call was made to backend to convert BTC => BAT - btc2BatNotifiedTimestamp: integer, // when user was shown "wallet upgraded" notification - btc2BatTransitionPending: boolean // true if user is being shown transition screen - }, menu: { template: object // used on Windows and by our tests: template object with Menubar control }, diff --git a/js/actions/appActions.js b/js/actions/appActions.js index 14672b77253..f1fbcb330b8 100644 --- a/js/actions/appActions.js +++ b/js/actions/appActions.js @@ -1825,24 +1825,6 @@ const appActions = { }) }, - onBitcoinToBatNotified: function () { - dispatch({ - actionType: appConstants.APP_ON_BTC_TO_BAT_NOTIFIED - }) - }, - - onBitcoinToBatTransitioned: function () { - dispatch({ - actionType: appConstants.APP_ON_BTC_TO_BAT_TRANSITIONED - }) - }, - - onBitcoinToBatBeginTransition: function () { - dispatch({ - actionType: appConstants.APP_ON_BTC_TO_BAT_BEGIN_TRANSITION - }) - }, - onPublisherTimestamp: function (timestamp, updateList) { dispatch({ actionType: appConstants.APP_ON_PUBLISHER_TIMESTAMP, diff --git a/js/constants/appConstants.js b/js/constants/appConstants.js index 84b1fc166c5..0594e4b5545 100644 --- a/js/constants/appConstants.js +++ b/js/constants/appConstants.js @@ -178,10 +178,7 @@ const appConstants = { APP_ON_NETWORK_CONNECTED: _, APP_ON_RESET_RECOVERY_STATUS: _, APP_ON_LEDGER_INIT_READ: _, - APP_ON_BTC_TO_BAT_NOTIFIED: _, - APP_ON_BTC_TO_BAT_TRANSITIONED: _, APP_ON_LEDGER_QR_GENERATED: _, - APP_ON_BTC_TO_BAT_BEGIN_TRANSITION: _, APP_ON_PUBLISHER_TIMESTAMP: _, APP_SAVE_LEDGER_PROMOTION: _, APP_ON_PROMOTION_CLAIM: _, diff --git a/test/unit/app/browser/api/ledgerNotificationsTest.js b/test/unit/app/browser/api/ledgerNotificationsTest.js index fb785866c43..c09a3999b19 100644 --- a/test/unit/app/browser/api/ledgerNotificationsTest.js +++ b/test/unit/app/browser/api/ledgerNotificationsTest.js @@ -11,19 +11,17 @@ const settings = require('../../../../../js/constants/settings') describe('ledgerNotifications unit test', function () { let fakeClock - let ledgerApi let ledgerNotificationsApi let appAction let paymentsEnabled - let paymentsNotifications + let paymentsNotifications = true let paymentsMinVisitTime = 5000 let paymentsContributionAmount = 25 let paymentsAllowPromotions = true const defaultAppState = Immutable.fromJS({ - ledger: {}, - migrations: {} + ledger: {} }) before(function () { @@ -58,7 +56,6 @@ describe('ledgerNotifications unit test', function () { }) fakeClock = sinon.useFakeTimers() - ledgerApi = require('../../../../../app/browser/api/ledger') ledgerNotificationsApi = require('../../../../../app/browser/api/ledgerNotifications') appAction = require('../../../../../js/actions/appActions') }) @@ -94,224 +91,6 @@ describe('ledgerNotifications unit test', function () { }) }) - describe('onLaunch', function () { - let showBraveWalletUpdatedStub - let transitionWalletToBatStub - beforeEach(function () { - showBraveWalletUpdatedStub = sinon.stub(ledgerNotificationsApi, 'showBraveWalletUpdated') - transitionWalletToBatStub = sinon.stub(ledgerApi, 'transitionWalletToBat') - }) - afterEach(function () { - showBraveWalletUpdatedStub.restore() - transitionWalletToBatStub.restore() - }) - - describe('with BAT Mercury', function () { - let ledgerStateWithBalance - - before(function () { - ledgerStateWithBalance = defaultAppState.merge(Immutable.fromJS({ - ledger: { - info: { - balance: 200 - } - }, - firstRunTimestamp: 12345, - migrations: { - batMercuryTimestamp: 12345, - btc2BatTimestamp: 12345, - btc2BatNotifiedTimestamp: 12345 - } - })) - }) - - describe('with wallet update message', function () { - describe('when payment notifications are disabled', function () { - before(function () { - paymentsEnabled = true - paymentsNotifications = false - }) - it('does not notify the user', function () { - const targetSession = ledgerStateWithBalance - .setIn(['migrations', 'batMercuryTimestamp'], 32145) - .setIn(['migrations', 'btc2BatTimestamp'], 54321) - .setIn(['migrations', 'btc2BatNotifiedTimestamp'], 32145) - ledgerNotificationsApi.onLaunch(targetSession) - assert(showBraveWalletUpdatedStub.notCalled) - }) - }) - - describe('when payments are disabled', function () { - before(function () { - paymentsEnabled = false - paymentsNotifications = true - }) - it('does not notify the user', function () { - const targetSession = ledgerStateWithBalance - .setIn(['migrations', 'batMercuryTimestamp'], 32145) - .setIn(['migrations', 'btc2BatTimestamp'], 54321) - .setIn(['migrations', 'btc2BatNotifiedTimestamp'], 32145) - ledgerNotificationsApi.onLaunch(targetSession) - assert(showBraveWalletUpdatedStub.notCalled) - }) - }) - - describe('user does not have funds', function () { - before(function () { - paymentsEnabled = true - paymentsNotifications = true - }) - it('does not notify the user', function () { - const targetSession = ledgerStateWithBalance - .setIn(['ledger', 'info', 'balance'], 0) - .setIn(['migrations', 'batMercuryTimestamp'], 32145) - .setIn(['migrations', 'btc2BatTimestamp'], 54321) - .setIn(['migrations', 'btc2BatNotifiedTimestamp'], 32145) - ledgerNotificationsApi.onLaunch(targetSession) - assert(showBraveWalletUpdatedStub.notCalled) - }) - }) - - describe('user did not have a session before BAT Mercury', function () { - before(function () { - paymentsEnabled = true - paymentsNotifications = true - }) - it('does not notify the user', function () { - ledgerNotificationsApi.onLaunch(ledgerStateWithBalance) - assert(showBraveWalletUpdatedStub.notCalled) - }) - }) - - describe('user has not had the wallet transitioned from BTC to BAT', function () { - before(function () { - paymentsEnabled = true - paymentsNotifications = true - }) - it('does not notify the user', function () { - const targetSession = ledgerStateWithBalance - .setIn(['migrations', 'batMercuryTimestamp'], 32145) - .setIn(['migrations', 'btc2BatTimestamp'], 32145) - .setIn(['migrations', 'btc2BatNotifiedTimestamp'], 32145) - ledgerNotificationsApi.onLaunch(targetSession) - assert(showBraveWalletUpdatedStub.notCalled) - }) - }) - - describe('user has already seen the notification', function () { - before(function () { - paymentsEnabled = true - paymentsNotifications = true - }) - it('does not notify the user', function () { - const targetSession = ledgerStateWithBalance - .setIn(['migrations', 'batMercuryTimestamp'], 32145) - .setIn(['migrations', 'btc2BatTimestamp'], 54321) - .setIn(['migrations', 'btc2BatNotifiedTimestamp'], 54321) - ledgerNotificationsApi.onLaunch(targetSession) - assert(showBraveWalletUpdatedStub.notCalled) - }) - }) - - describe('when payment notifications are enabled, payments are enabled, user has funds, user had wallet before BAT Mercury, wallet has been transitioned, and user not been shown message yet', function () { - before(function () { - paymentsEnabled = true - paymentsNotifications = true - }) - it('notifies the user', function () { - const targetSession = ledgerStateWithBalance - .setIn(['migrations', 'batMercuryTimestamp'], 32145) - .setIn(['migrations', 'btc2BatTimestamp'], 54321) - .setIn(['migrations', 'btc2BatNotifiedTimestamp'], 32145) - ledgerNotificationsApi.onLaunch(targetSession) - assert(showBraveWalletUpdatedStub.calledOnce) - }) - }) - }) - - describe('with the wallet transition from bitcoin to BAT', function () { - describe('when payment notifications are disabled', function () { - before(function () { - paymentsEnabled = true - paymentsNotifications = false - }) - it('calls ledger.transitionWalletToBat', function () { - const targetSession = ledgerStateWithBalance - .setIn(['migrations', 'batMercuryTimestamp'], 32145) - .setIn(['migrations', 'btc2BatTimestamp'], 32145) - ledgerNotificationsApi.onLaunch(targetSession) - assert(transitionWalletToBatStub.calledOnce) - }) - }) - - describe('when payments are disabled', function () { - before(function () { - paymentsEnabled = false - paymentsNotifications = true - }) - it('does not call ledger.transitionWalletToBat', function () { - ledgerNotificationsApi.onLaunch(ledgerStateWithBalance) - assert(transitionWalletToBatStub.notCalled) - }) - }) - - describe('user does not have funds', function () { - before(function () { - paymentsEnabled = true - paymentsNotifications = true - }) - it('calls ledger.transitionWalletToBat', function () { - const ledgerStateWithoutBalance = ledgerStateWithBalance - .setIn(['ledger', 'info', 'balance'], 0) - .setIn(['migrations', 'batMercuryTimestamp'], 32145) - .setIn(['migrations', 'btc2BatTimestamp'], 32145) - ledgerNotificationsApi.onLaunch(ledgerStateWithoutBalance) - assert(transitionWalletToBatStub.calledOnce) - }) - }) - - describe('user did not have a session before BAT Mercury', function () { - before(function () { - paymentsEnabled = true - paymentsNotifications = true - }) - it('does not call ledger.transitionWalletToBat', function () { - ledgerNotificationsApi.onLaunch(ledgerStateWithBalance) - assert(transitionWalletToBatStub.notCalled) - }) - }) - - describe('user has already upgraded', function () { - before(function () { - paymentsEnabled = true - paymentsNotifications = true - }) - it('does not call ledger.transitionWalletToBat', function () { - const ledgerStateSeenNotification = ledgerStateWithBalance - .setIn(['migrations', 'batMercuryTimestamp'], 32145) - .setIn(['migrations', 'btc2BatTimestamp'], 54321) - ledgerNotificationsApi.onLaunch(ledgerStateSeenNotification) - assert(transitionWalletToBatStub.notCalled) - }) - }) - - describe('when payments are enabled and user had wallet before BAT Mercury', function () { - before(function () { - paymentsEnabled = true - paymentsNotifications = true - }) - it('calls ledger.transitionWalletToBat', function () { - const targetSession = ledgerStateWithBalance - .setIn(['migrations', 'batMercuryTimestamp'], 32145) - .setIn(['migrations', 'btc2BatTimestamp'], 32145) - ledgerNotificationsApi.onLaunch(targetSession) - assert(transitionWalletToBatStub.calledOnce) - }) - }) - }) - }) - }) - describe('onInterval', function () { let showEnabledNotificationsSpy, showDisabledNotificationsSpy, onIntervalDynamicSpy diff --git a/test/unit/app/browser/api/ledgerTest.js b/test/unit/app/browser/api/ledgerTest.js index 688bd0a94ef..ef4d114fb16 100644 --- a/test/unit/app/browser/api/ledgerTest.js +++ b/test/unit/app/browser/api/ledgerTest.js @@ -9,7 +9,6 @@ const sinon = require('sinon') const mockery = require('mockery') const settings = require('../../../../../js/constants/settings') const appActions = require('../../../../../js/actions/appActions') -const migrationState = require('../../../../../app/common/state/migrationState') const batPublisher = require('bat-publisher') const ledgerMediaProviders = require('../../../../../app/common/constants/ledgerMediaProviders') const fs = require('fs') @@ -22,6 +21,7 @@ describe('ledger api unit tests', function () { let ledgerUtil let isBusy = false let ledgerClient + let ledgerClientObject let ledgerPublisher let tabState = Immutable.fromJS({ partition: 'persist:partition-1' @@ -43,11 +43,7 @@ describe('ledger api unit tests', function () { let contributionAmountSet = true // spies - let ledgerTransitionSpy - let ledgerTransitionedSpy - let onBitcoinToBatTransitionedSpy let onLedgerCallbackSpy - let onBitcoinToBatBeginTransitionSpy let onChangeSettingSpy let ledgersetPromotionSpy let ledgergetPromotionSpy @@ -57,8 +53,7 @@ describe('ledger api unit tests', function () { cache: { ledgerVideos: {} }, - ledger: {}, - migrations: {} + ledger: {} }) before(function () { @@ -96,9 +91,7 @@ describe('ledger api unit tests', function () { request = require('../../../../../js/lib/request') mockery.registerMock('../../../js/lib/request', request) mockery.registerMock('../../../js/actions/appActions', appActions) - onBitcoinToBatTransitionedSpy = sinon.spy(appActions, 'onBitcoinToBatTransitioned') onLedgerCallbackSpy = sinon.spy(appActions, 'onLedgerCallback') - onBitcoinToBatBeginTransitionSpy = sinon.spy(appActions, 'onBitcoinToBatBeginTransition') onChangeSettingSpy = sinon.spy(appActions, 'changeSetting') mockery.registerMock('fs', fs) @@ -109,7 +102,7 @@ describe('ledger api unit tests', function () { // ledger client stubbing ledgerClient = sinon.stub() - const lc = { + ledgerClientObject = { sync: function (callback) { return false }, getBraveryProperties: function () { return { @@ -131,9 +124,6 @@ describe('ledger api unit tests', function () { getWalletProperties: function (amount, currency, callback) { callback(null, {}) }, - transition: function (paymentId, callback) { - callback() - }, getPaymentId: function () { return 'payementIdGoesHere' }, @@ -142,9 +132,6 @@ describe('ledger api unit tests', function () { paymentId: 12345 } }, - transitioned: function () { - return {} - }, setBraveryProperties: function (clientProperties, callback) { if (typeof callback === 'function') { const err = undefined @@ -172,12 +159,10 @@ describe('ledger api unit tests', function () { ledgerClient.prototype.getWalletPassphrase = function (parsedData) { return window.getWalletPassphrase(parsedData) } - ledgerTransitionSpy = sinon.spy(lc, 'transition') - ledgerTransitionedSpy = sinon.spy(lc, 'transitioned') - ledgersetPromotionSpy = sinon.spy(lc, 'setPromotion') - ledgergetPromotionSpy = sinon.spy(lc, 'getPromotion') - ledgerSetTimeUntilReconcile = sinon.spy(lc, 'setTimeUntilReconcile') - ledgerClient.returns(lc) + ledgersetPromotionSpy = sinon.spy(ledgerClientObject, 'setPromotion') + ledgergetPromotionSpy = sinon.spy(ledgerClientObject, 'getPromotion') + ledgerSetTimeUntilReconcile = sinon.spy(ledgerClientObject, 'setTimeUntilReconcile') + ledgerClient.returns(ledgerClientObject) mockery.registerMock('bat-client', ledgerClient) // ledger publisher stubbing @@ -212,9 +197,7 @@ describe('ledger api unit tests', function () { ledgerApi = require('../../../../../app/browser/api/ledger') }) after(function () { - onBitcoinToBatTransitionedSpy.restore() onLedgerCallbackSpy.restore() - onBitcoinToBatBeginTransitionSpy.restore() onChangeSettingSpy.restore() mockery.deregisterAll() mockery.disable() @@ -286,77 +269,6 @@ describe('ledger api unit tests', function () { }) }) - describe('checkBtcBatMigrated', function () { - let transitionWalletToBatStub - before(function () { - transitionWalletToBatStub = sinon.stub(ledgerApi, 'transitionWalletToBat') - }) - after(function () { - transitionWalletToBatStub.restore() - }) - - describe('when not a new install and wallet has not been upgraded', function () { - let result - before(function () { - const notMigratedYet = defaultAppState.merge(Immutable.fromJS({ - firstRunTimestamp: 12345, - migrations: { - batMercuryTimestamp: 34512, - btc2BatTimestamp: 34512, - btc2BatNotifiedTimestamp: 34512, - btc2BatTransitionPending: false - } - })) - assert.equal(migrationState.inTransition(notMigratedYet), false) - transitionWalletToBatStub.reset() - result = ledgerApi.checkBtcBatMigrated(notMigratedYet, true) - }) - it('sets transition status to true', function () { - assert(migrationState.inTransition(result)) - }) - it('calls transitionWalletToBat', function () { - assert(transitionWalletToBatStub.calledOnce) - }) - }) - - describe('when a transition is already being shown', function () { - it('sets transition to false if new install', function () { - const stuckOnMigrate = defaultAppState.merge(Immutable.fromJS({ - firstRunTimestamp: 12345, - migrations: { - batMercuryTimestamp: 12345, - btc2BatTimestamp: 12345, - btc2BatNotifiedTimestamp: 12345, - btc2BatTransitionPending: true - } - })) - assert(migrationState.isNewInstall(stuckOnMigrate)) - assert.equal(migrationState.hasUpgradedWallet(stuckOnMigrate), false) - assert(migrationState.inTransition(stuckOnMigrate)) - - const result = ledgerApi.checkBtcBatMigrated(stuckOnMigrate, true) - assert.equal(migrationState.inTransition(result), false) - }) - it('sets transition to false if wallet has been upgraded', function () { - const stuckOnMigrate = defaultAppState.merge(Immutable.fromJS({ - firstRunTimestamp: 12345, - migrations: { - batMercuryTimestamp: 34512, - btc2BatTimestamp: 54321, - btc2BatNotifiedTimestamp: 34512, - btc2BatTransitionPending: true - } - })) - assert.equal(migrationState.isNewInstall(stuckOnMigrate), false) - assert(migrationState.hasUpgradedWallet(stuckOnMigrate)) - assert(migrationState.inTransition(stuckOnMigrate)) - - const result = ledgerApi.checkBtcBatMigrated(stuckOnMigrate, true) - assert.equal(migrationState.inTransition(result), false) - }) - }) - }) - describe('synopsisNormalizer', function () { after(function () { ledgerApi.setSynopsis(undefined) @@ -546,8 +458,7 @@ describe('ledger api unit tests', function () { } } } - }, - migrations: {} + } } const result = ledgerApi.pruneSynopsis(defaultAppState) @@ -814,8 +725,7 @@ describe('ledger api unit tests', function () { } } } - }, - migrations: {} + } }) const response = Immutable.fromJS({ @@ -915,8 +825,7 @@ describe('ledger api unit tests', function () { } } } - }, - migrations: {} + } }) const state = ledgerApi.onMediaPublisher(newState, videoId, response, 1000, false) @@ -959,8 +868,7 @@ describe('ledger api unit tests', function () { } } } - }, - migrations: {} + } }) const state = ledgerApi.onMediaPublisher(newState, videoId, response, 1000, false) @@ -1124,105 +1032,6 @@ describe('ledger api unit tests', function () { assert(visitsByPublisher['clifton.io']) }) }) - - describe('transitionWalletToBat', function () { - let fakeClock - - before(function () { - fakeClock = sinon.useFakeTimers() - }) - after(function () { - ledgerApi.setSynopsis(undefined) - fakeClock.restore() - }) - - describe('when client is not busy', function () { - before(function () { - ledgerApi.onBootStateFile(defaultAppState) - ledgerTransitionSpy.reset() - onBitcoinToBatTransitionedSpy.reset() - onLedgerCallbackSpy.reset() - ledgerTransitionedSpy.reset() - onBitcoinToBatBeginTransitionSpy.reset() - ledgerClient.reset() - ledgerApi.resetNewClient() - isBusy = false - ledgerApi.transitionWalletToBat() - }) - it('creates a new instance of ledgerClient', function () { - assert(ledgerClient.calledOnce) - }) - it('calls AppActions.onBitcoinToBatBeginTransition', function () { - assert(onBitcoinToBatBeginTransitionSpy.calledOnce) - }) - it('calls client.transition', function () { - assert(ledgerTransitionSpy.calledOnce) - }) - describe('when transition completes', function () { - it('calls client.transitioned', function () { - assert(ledgerTransitionedSpy.calledOnce) - }) - it('calls AppActions.onLedgerCallback', function () { - assert(onLedgerCallbackSpy.calledOnce) - }) - it('calls AppActions.onBitcoinToBatTransitioned', function () { - assert(onBitcoinToBatTransitionedSpy.calledOnce) - }) - }) - }) - describe('when client is busy', function () { - before(function () { - ledgerApi.onBootStateFile(defaultAppState) - ledgerTransitionSpy.reset() - onBitcoinToBatTransitionedSpy.reset() - onLedgerCallbackSpy.reset() - ledgerTransitionedSpy.reset() - onBitcoinToBatBeginTransitionSpy.reset() - ledgerClient.reset() - ledgerApi.resetNewClient() - isBusy = true - ledgerApi.transitionWalletToBat() - }) - after(function () { - isBusy = false - }) - it('does not call AppActions.onBitcoinToBatBeginTransition', function () { - assert(onBitcoinToBatBeginTransitionSpy.notCalled) - }) - it('does not call client.transition', function () { - assert(ledgerTransitionSpy.notCalled) - }) - }) - describe('when client is not v1', function () { - let oldClient - before(function () { - const batState = ledgerApi.onBootStateFile(defaultAppState) - ledgerTransitionSpy.reset() - onBitcoinToBatTransitionedSpy.reset() - onLedgerCallbackSpy.reset() - ledgerTransitionedSpy.reset() - onBitcoinToBatBeginTransitionSpy.reset() - ledgerClient.reset() - oldClient = ledgerApi.getClient() - ledgerApi.setClient({ - options: { - version: 'v2' - } - }) - ledgerApi.resetNewClient() - ledgerApi.transitionWalletToBat(batState) - }) - after(function () { - ledgerApi.setClient(oldClient) - }) - it('calls AppActions.onBitcoinToBatTransitioned', function () { - assert(onBitcoinToBatTransitionedSpy.calledOnce) - }) - it('does not call client.transition', function () { - assert(ledgerTransitionSpy.notCalled) - }) - }) - }) }) describe('observeTransactions', function () { @@ -1663,6 +1472,7 @@ describe('ledger api unit tests', function () { .setIn(['ledger', 'promotion', 'promotionId'], '1') before(function () { + ledgerApi.setClient(ledgerClientObject) ledgersetPromotionSpy.reset() }) diff --git a/test/unit/app/browser/reducers/ledgerReducerTest.js b/test/unit/app/browser/reducers/ledgerReducerTest.js index 0f34ff8554a..7f7367bc7e0 100644 --- a/test/unit/app/browser/reducers/ledgerReducerTest.js +++ b/test/unit/app/browser/reducers/ledgerReducerTest.js @@ -88,8 +88,7 @@ describe('ledgerReducer unit tests', function () { ledgerReducer = require('../../../../../app/browser/reducers/ledgerReducer') appState = Immutable.fromJS({ - ledger: {}, - migrations: {} + ledger: {} }) }) @@ -287,9 +286,6 @@ describe('ledgerReducer unit tests', function () { it('calls ledgerApi.boot', function () { assert(bootSpy.calledOnce) }) - it('returns a non-modified state, if no transition in progress', function () { - assert.deepEqual(returnedState, appState) - }) }) describe('APP_ON_BOOT_STATE_FILE', function () { @@ -532,42 +528,6 @@ describe('ledgerReducer unit tests', function () { }) }) - describe('APP_ON_BTC_TO_BAT_NOTIFIED', function () { - before(function () { - returnedState = ledgerReducer(appState, Immutable.fromJS({ - actionType: appConstants.APP_ON_BTC_TO_BAT_NOTIFIED - })) - }) - it('sets the notification timestamp', function () { - assert.notDeepEqual(returnedState, appState) - assert(returnedState.getIn(['migrations', 'btc2BatNotifiedTimestamp'])) - }) - }) - - describe('APP_ON_BTC_TO_BAT_TRANSITIONED', function () { - before(function () { - returnedState = ledgerReducer(appState, Immutable.fromJS({ - actionType: appConstants.APP_ON_BTC_TO_BAT_TRANSITIONED - })) - }) - it('sets the timestamp', function () { - assert.notDeepEqual(returnedState, appState) - assert(returnedState.getIn(['migrations', 'btc2BatTimestamp'])) - }) - }) - - describe('APP_ON_BTC_TO_BAT_BEGIN_TRANSITION', function () { - before(function () { - returnedState = ledgerReducer(appState, Immutable.fromJS({ - actionType: appConstants.APP_ON_BTC_TO_BAT_BEGIN_TRANSITION - })) - }) - it('sets the state variable', function () { - assert.notDeepEqual(returnedState, appState) - assert.equal(returnedState.getIn(['migrations', 'btc2BatTransitionPending']), true) - }) - }) - describe('APP_ON_PRUNE_SYNOPSIS', function () { let ledgerStateSpy From c8d0d7f53a94920e2f356b70d15bbbe074bc22c9 Mon Sep 17 00:00:00 2001 From: NejcZdovc Date: Wed, 7 Feb 2018 10:14:41 +0100 Subject: [PATCH 2/2] Adds new wallet creation for old btc wallets --- app/browser/api/ledger.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/browser/api/ledger.js b/app/browser/api/ledger.js index b5f3369b822..0662750c659 100644 --- a/app/browser/api/ledger.js +++ b/app/browser/api/ledger.js @@ -1501,7 +1501,7 @@ const getStateInfo = (state, parsedData) => { const info = parsedData.paymentInfo const then = new Date().getTime() - ledgerUtil.milliseconds.year - if (!parsedData.properties.wallet) { + if (!parsedData.properties || !parsedData.properties.wallet) { return state } @@ -2057,6 +2057,22 @@ const getContributionAmount = (state) => { } const onInitRead = (state, parsedData) => { + const isBTC = parsedData && + parsedData.properties && + parsedData.properties.wallet && + parsedData.properties.wallet.keychains + + if (isBTC) { + const fs = require('fs') + fs.renameSync(pathName(statePath), pathName('ledger-state-btc.json')) + state = ledgerState.resetInfo(state) + clientprep() + client = ledgerClient(null, underscore.extend({roundtrip: roundtrip}, clientOptions), null) + parsedData = client.state + getPaymentInfo(state) + muonWriter(statePath, parsedData) + } + if (Array.isArray(parsedData.transactions)) { parsedData.transactions.sort((transaction1, transaction2) => { return transaction1.submissionStamp - transaction2.submissionStamp