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 5, 2018
1 parent bca6936 commit e1934d9
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 14 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 = (delay) => {
appActions.onFuzzing(delay)
}

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
5 changes: 5 additions & 0 deletions app/browser/reducers/ledgerReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,11 @@ const ledgerReducer = (state, action, immutableAction) => {
state = ledgerApi.onFetchReferralHeaders(state, action.get('error'), action.get('response'), action.get('body'))
break
}
case appConstants.APP_ON_FUZZING:
{
state = ledgerState.setAboutProp(state, 'status', ledgerStatuses.FUZZING)
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=Your contribution date was pushed back, because minimum browsing time (30min) was not met.
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 = {
})
},

onFuzzing: function (delay) {
dispatch({
actionType: appConstants.APP_ON_FUZZING,
delay
})
},

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_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
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 e1934d9

Please sign in to comment.