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

Commit

Permalink
Notify users when contribution date is pushed back
Browse files Browse the repository at this point in the history
Resolves #14000

Auditors:

Test Plan:
  • Loading branch information
NejcZdovc committed May 7, 2018
1 parent bca6936 commit 548a096
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 16 deletions.
12 changes: 8 additions & 4 deletions app/browser/api/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -2352,7 +2352,7 @@ const onInitRead = (state, parsedData) => {
// enables it again -> reconcileStamp is in the past.
// In this case reset reconcileStamp to the future.
try {
timeUntilReconcile = client.timeUntilReconcile(synopsis)
timeUntilReconcile = client.timeUntilReconcile(synopsis, onFuzzing)
} catch (ex) {}

let ledgerWindow = (ledgerState.getSynopsisOption(state, 'numFrames') - 1) * ledgerState.getSynopsisOption(state, 'frameSize')
Expand Down Expand Up @@ -2386,6 +2386,10 @@ const onInitRead = (state, parsedData) => {
return state
}

const onFuzzing = () => {
appActions.onLedgerFuzzing(client.state.reconcileStamp)
}

const onTimeUntilReconcile = (state, stateResult) => {
state = getStateInfo(state, stateResult.toJS()) // TODO optimize
muonWriter(statePath, stateResult)
Expand Down Expand Up @@ -2462,7 +2466,7 @@ const run = (state, delayTime) => {
}

const publishers = ledgerState.getAboutProp(state, 'synopsis') || Immutable.List()
if (isList(publishers) && publishers.isEmpty() && client.isReadyToReconcile(synopsis)) {
if (isList(publishers) && publishers.isEmpty() && client.isReadyToReconcile(synopsis, onFuzzing)) {
setNewTimeUntilReconcile()
}

Expand Down Expand Up @@ -2523,7 +2527,7 @@ const run = (state, delayTime) => {

if (delayTime === 0) {
try {
delayTime = client.timeUntilReconcile(synopsis)
delayTime = client.timeUntilReconcile(synopsis, onFuzzing)
} catch (ex) {
delayTime = false
}
Expand Down Expand Up @@ -2557,7 +2561,7 @@ const run = (state, delayTime) => {
return
}

if (client.isReadyToReconcile(synopsis)) {
if (client.isReadyToReconcile(synopsis, onFuzzing)) {
client.reconcile(uuid.v4().toLowerCase(), callback)
}
}
Expand Down
9 changes: 9 additions & 0 deletions app/browser/reducers/ledgerReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,15 @@ const ledgerReducer = (state, action, immutableAction) => {
state = ledgerApi.onFetchReferralHeaders(state, action.get('error'), action.get('response'), action.get('body'))
break
}
case appConstants.APP_ON_LEDGER_FUZZING:
{
state = ledgerState.setAboutProp(state, 'status', ledgerStatuses.FUZZING)
const newStamp = parseInt(action.get('newStamp'))
if (!isNaN(newStamp) && newStamp > 0) {
state = ledgerState.setInfoProp(state, 'reconcileStamp', newStamp)
}
break
}
case appConstants.APP_ON_REFERRAL_ACTIVITY:
{
state = updateState.setUpdateProp(state, 'referralTimestamp', new Date().getTime())
Expand Down
3 changes: 2 additions & 1 deletion app/common/constants/ledgerStatuses.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
const statuses = {
CORRUPTED_SEED: 'corruptedSeed',
IN_PROGRESS: 'contributionInProgress',
SERVER_PROBLEM: 'serverProblem'
SERVER_PROBLEM: 'serverProblem',
FUZZING: 'fuzzing'
}

module.exports = statuses
10 changes: 10 additions & 0 deletions app/common/lib/ledgerUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const ledgerVideoCache = require('../cache/ledgerVideoCache')
const settings = require('../../../js/constants/settings')
const ledgerMediaProviders = require('../constants/ledgerMediaProviders')
const twitchEvents = require('../constants/twitchEvents')
const ledgerStatuses = require('../constants/ledgerStatuses')

// Utils
const {responseHasContent} = require('./httpUtil')
Expand Down Expand Up @@ -98,6 +99,15 @@ const formattedDateFromTimestamp = (timestamp, dateFormat) => {
const walletStatus = (ledgerData, settings) => {
let status = {}

switch (ledgerData.get('status')) {
case ledgerStatuses.FUZZING:
{
return {
id: 'ledgerFuzzed'
}
}
}

if (ledgerData == null) {
return {
id: 'createWalletStatus'
Expand Down
1 change: 1 addition & 0 deletions app/extensions/brave/locales/en-US/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ 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
ledgerFuzzed=You haven't accrued 30 minutes of browser activity yet so we pushed back the settlement date to give you more time.
ledgerNetworkErrorMessage=The Brave Payments server is not responding. We will fix this as soon as possible.
ledgerNetworkErrorTitle=Uh oh.
ledgerNetworkErrorText=Note: This error could also be caused by a network connection problem.
Expand Down
7 changes: 7 additions & 0 deletions js/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1981,6 +1981,13 @@ const appActions = {
})
},

onLedgerFuzzing: function (newStamp) {
dispatch({
actionType: appConstants.APP_ON_LEDGER_FUZZING,
newStamp
})
},

onLedgerBackupSuccess: function () {
dispatch({
actionType: appConstants.APP_ON_LEDGER_BACKUP_SUCCESS
Expand Down
1 change: 1 addition & 0 deletions js/constants/appConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ const appConstants = {
APP_ON_LEDGER_PIN_PUBLISHER: _,
APP_ON_LEDGER_NOTIFICATION_INTERVAL: _,
APP_ON_LEDGER_MEDIA_DATA: _,
APP_ON_LEDGER_FUZZING: _,
APP_ON_PRUNE_SYNOPSIS: _,
APP_ON_HISTORY_LIMIT: _,
APP_ON_REFERRAL_CODE_READ: _,
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"aphrodite": "1.1.0",
"async": "^2.0.1",
"bat-balance": "^1.0.7",
"bat-client": "^2.2.6",
"bat-client": "^2.2.8",
"bat-publisher": "^2.0.15",
"bignumber.js": "^4.0.4",
"bloodhound-js": "brave/bloodhound",
Expand Down
66 changes: 64 additions & 2 deletions test/unit/app/browser/reducers/ledgerReducerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const sinon = require('sinon')
const appConstants = require('../../../../../js/constants/appConstants')
const settings = require('../../../../../js/constants/settings')
require('../../../braveUnit')
const ledgerStatuses = require('../../../../../app/common/constants/ledgerStatuses')
const ledgerState = require('../../../../../app/common/state/ledgerState')

describe('ledgerReducer unit tests', function () {
let ledgerReducer
Expand Down Expand Up @@ -66,11 +68,12 @@ describe('ledgerReducer unit tests', function () {
resetSynopsis: dummyModifyState,
setRecoveryStatus: dummyModifyState,
setRecoveryInProgressStatus: dummyModifyState,
setInfoProp: dummyModifyState,
setInfoProp: ledgerState.setInfoProp,
saveSynopsis: dummyModifyState,
savePromotion: dummyModifyState,
remindMeLater: dummyModifyState,
removePromotion: dummyModifyState
removePromotion: dummyModifyState,
setAboutProp: ledgerState.setAboutProp
}
fakeLedgerNotifications = {
onPromotionReceived: dummyModifyState,
Expand Down Expand Up @@ -907,4 +910,63 @@ describe('ledgerReducer unit tests', function () {
assert.equal(true, pageDataChangedSpy.getCall(1).args[2])
})
})

describe('APP_ON_LEDGER_FUZZING', function () {
let newState

before(() => {
newState = appState
.setIn(['ledger', 'about', 'status'], ledgerStatuses.FUZZING)
})

it('null case', function () {
const result = ledgerReducer(appState, Immutable.fromJS({
actionType: appConstants.APP_ON_LEDGER_FUZZING
}))

assert.deepEqual(result.toJS(), newState.toJS())
})

it('stamp is string', function () {
const result = ledgerReducer(appState, Immutable.fromJS({
actionType: appConstants.APP_ON_LEDGER_FUZZING,
newStamp: 'str'
}))

assert.deepEqual(result.toJS(), newState.toJS())
})

it('stamp is negative', function () {
const result = ledgerReducer(appState, Immutable.fromJS({
actionType: appConstants.APP_ON_LEDGER_FUZZING,
newStamp: -10
}))

assert.deepEqual(result.toJS(), newState.toJS())
})

it('stamp is number (string)', function () {
const result = ledgerReducer(appState, Immutable.fromJS({
actionType: appConstants.APP_ON_LEDGER_FUZZING,
newStamp: '10'
}))

const expectedState = newState
.setIn(['ledger', 'info', 'reconcileStamp'], 10)

assert.deepEqual(result.toJS(), expectedState.toJS())
})

it('reconcile stamp is set', function () {
const result = ledgerReducer(appState, Immutable.fromJS({
actionType: appConstants.APP_ON_LEDGER_FUZZING,
newStamp: 10
}))

const expectedState = newState
.setIn(['ledger', 'info', 'reconcileStamp'], 10)

assert.deepEqual(result.toJS(), expectedState.toJS())
})
})
})
12 changes: 11 additions & 1 deletion test/unit/app/common/lib/ledgerUtilTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const settings = require('../../../../../js/constants/settings')
const ledgerMediaProviders = require('../../../../../app/common/constants/ledgerMediaProviders')
const twitchEvents = require('../../../../../app/common/constants/twitchEvents')
const urlUtil = require('../../../../../js/lib/urlutil')
const ledgerStatuses = require('../../../../../app/common/constants/ledgerStatuses')

const defaultState = Immutable.fromJS({
ledger: {}
Expand Down Expand Up @@ -265,12 +266,21 @@ describe('ledgerUtil unit test', function () {

describe('walletStatus', function () {
it('null case', function () {
const result = ledgerUtil.walletStatus()
const result = ledgerUtil.walletStatus(Immutable.Map())
assert.deepEqual(result, {
id: 'createWalletStatus'
})
})

it('on fuzzing', function () {
const result = ledgerUtil.walletStatus(Immutable.fromJS({
status: ledgerStatuses.FUZZING
}))
assert.deepEqual(result, {
id: 'ledgerFuzzed'
})
})

it('on error', function () {
const state = Immutable.fromJS({
error: {
Expand Down

0 comments on commit 548a096

Please sign in to comment.