Skip to content

Commit

Permalink
Adds clear payments options
Browse files Browse the repository at this point in the history
Resolves brave#8537

Auditors:

Test Plan:
  • Loading branch information
NejcZdovc committed May 28, 2018
1 parent 8e9be72 commit 38a27a5
Show file tree
Hide file tree
Showing 21 changed files with 879 additions and 193 deletions.
68 changes: 60 additions & 8 deletions app/browser/api/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -1209,12 +1209,19 @@ const onWalletRecovery = (state, error, result) => {
return state
}

const resetPublishers = (state) => {
state = ledgerState.resetPublishers(state)
synopsis.publishers = {}

return state
}

const quit = (state) => {
quitP = true
state = addNewLocation(state, locationDefault)

if (!getSetting(settings.PAYMENTS_ENABLED) && getSetting(settings.SHUTDOWN_CLEAR_HISTORY)) {
state = ledgerState.resetSynopsis(state, true)
if (!getSetting(settings.PAYMENTS_ENABLED) && getSetting(settings.SHUTDOWN_CLEAR_PUBLISHERS)) {
resetPublishers(state)
}

return state
Expand Down Expand Up @@ -2721,10 +2728,6 @@ const savePublisherData = (publisherKey, prop, value) => {
synopsis.publishers[publisherKey][prop] = value
}

const deleteSynopsis = () => {
synopsis.publishers = {}
}

let currentMediaKey = null
const onMediaRequest = (state, xhr, type, details) => {
if (!xhr || type == null) {
Expand Down Expand Up @@ -3123,6 +3126,53 @@ const activityRoundTrip = (err, response, body) => {
updater.checkForUpdate(false, true)
}

const deleteWallet = (state) => {
state = ledgerState.deleteSynopsis(state)
state = state.setIn(['settings', settings.PAYMENTS_ENABLED], false)

client = null
synopsis = null

const fs = require('fs')
fs.access(pathName(statePath), fs.constants.F_OK, (err) => {
if (err) {
return
}

fs.unlink(pathName(statePath), (err) => {
if (err) {
return console.error('read error: ' + err.toString())
}
})
})

return state
}

const clearPaymentHistory = (state) => {
state = ledgerState.setInfoProp(state, 'transactions', Immutable.List())
state = ledgerState.setInfoProp(state, 'ballots', Immutable.List())
state = ledgerState.setInfoProp(state, 'batch', Immutable.List())

const fs = require('fs')
const path = pathName(statePath)
try {
fs.accessSync(path, fs.constants.W_OK)
let data = fs.readFileSync(path)
data = JSON.parse(data)
if (data) {
data.transactions = []
data.ballots = []
data.batch = []
muonWriter(statePath, data)
}
} catch (err) {
console.error(`Problem reading ${path} when clearing payment history`)
}

return state
}

const getMethods = () => {
const publicMethods = {
backupKeys,
Expand Down Expand Up @@ -3152,7 +3202,6 @@ const getMethods = () => {
onNetworkConnected,
migration,
onInitRead,
deleteSynopsis,
normalizePinned,
roundToTarget,
onFavIconReceived,
Expand Down Expand Up @@ -3180,7 +3229,10 @@ const getMethods = () => {
addSiteVisit,
getCaptcha,
onCaptchaResponse,
shouldTrackTab
shouldTrackTab,
deleteWallet,
resetPublishers,
clearPaymentHistory
}

let privateMethods = {}
Expand Down
16 changes: 12 additions & 4 deletions app/browser/reducers/ledgerReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,15 @@ const ledgerReducer = (state, action, immutableAction) => {
}
case appConstants.APP_ON_CLEAR_BROWSING_DATA:
{
const defaults = state.get('clearBrowsingDataDefaults')
const defaults = state.get('clearBrowsingDataDefaults') || Immutable.Map()
const temp = state.get('tempClearBrowsingData', Immutable.Map())
const clearData = defaults ? defaults.merge(temp) : temp
if (clearData.get('browserHistory') && !getSetting(settings.PAYMENTS_ENABLED)) {
state = ledgerState.resetSynopsis(state)
ledgerApi.deleteSynopsis()
if (clearData.get('publishersClear')) {
state = ledgerApi.resetPublishers(state)
}

if (clearData.get('paymentHistory')) {
state = ledgerApi.clearPaymentHistory(state)
}
break
}
Expand Down Expand Up @@ -555,6 +558,11 @@ const ledgerReducer = (state, action, immutableAction) => {
state = aboutPreferencesState.setBackupStatus(state, true)
break
}
case appConstants.APP_ON_WALLET_DELETE:
{
state = ledgerApi.deleteWallet(state)
break
}
case appConstants.APP_ON_PUBLISHER_TOGGLE_UPDATE:
{
const viewData = makeJS(action.get('viewData'))
Expand Down
38 changes: 27 additions & 11 deletions app/common/state/ledgerState.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,25 @@ const ledgerState = {
return state
},

resetSynopsis: (state, options = false) => {
deleteSynopsis: (state) => {
state = validateState(state)

if (options) {
state = state
.setIn(['ledger', 'synopsis', 'options'], Immutable.Map())
.setIn(['ledger', 'about', 'synopsisOptions'], Immutable.Map())
}

state = pageDataState.resetPageData(state)

return state
.setIn(['ledger', 'synopsis', 'publishers'], Immutable.Map())
.setIn(['ledger', 'locations'], Immutable.Map())
.setIn(['ledger', 'about', 'synopsis'], Immutable.List())
.setIn(['cache', 'ledgerVideos'], Immutable.Map())
.set('ledger', Immutable.fromJS({
about: {
synopsis: [],
synopsisOptions: {}
},
info: {},
locations: {},
synopsis: {
options: {},
publishers: {}
},
promotion: {}
}))
},

/**
Expand Down Expand Up @@ -195,6 +199,18 @@ const ledgerState = {
return state.setIn(['ledger', 'synopsis', 'publishers', key, prop], value)
},

resetPublishers: (state) => {
state = validateState(state)
state = pageDataState.resetPageData(state)

return state
.setIn(['ledger', 'synopsis', 'publishers'], Immutable.Map())
.setIn(['ledger', 'locations'], Immutable.Map())
.setIn(['ledger', 'about', 'synopsis'], Immutable.List())
.setIn(['ledger', 'publisherTimestamp'], 0)
.setIn(['cache', 'ledgerVideos'], Immutable.Map())
},

/**
* SYNOPSIS / PUBLISHER / OPTIONS
*/
Expand Down
1 change: 1 addition & 0 deletions app/common/state/pageDataState.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const pageDataState = {
.setIn(['pageData', 'info'], Immutable.Map())
.setIn(['pageData', 'last', 'info'], null)
.setIn(['pageData', 'last', 'tabId'], null)
.setIn(['pageData', 'last', 'closedTabValue'], null)
}
}

Expand Down
5 changes: 5 additions & 0 deletions app/extensions/brave/locales/en-US/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ clearAll=Clear all
clearBrowsingDataNow=Clear Browsing Data Now…
comingSoon=Coming soon!
compactBraveryPanel=Use compact panel
confirmPaymentsClear=A Brave Payment contribution is in progress. Brave Payment data cannot be cleared during this time. Please try again later or unselect the Brave Payments options for now.
contentSettings=Content Settings
contributionAmount=Contribution Amount
contributionDate=Contribution Date
Expand Down Expand Up @@ -226,6 +227,9 @@ paintTabs=Show tabs in page theme color
passwordManager=Password Manager
passwordsAndForms=Passwords and Forms
paymentsAllowPromotions=Notify me about token promotions
paymentsDeleteWallet=Delete wallet
paymentsDeleteWalletConfirmation=Are you sure that you want to delete your wallet? If you don't have your backup keys, your wallet will be lost forever.
paymentHistory=Brave Payments statements
paymentHistoryDueFooterText=Your next contribution is due.
paymentHistoryFooterText=Your next contribution is {{reconcileDate}}.
paymentHistoryIcon.title=Your Payment History
Expand Down Expand Up @@ -274,6 +278,7 @@ protocolRegistrationPermission=Protocol registration
publicOnly=Default public interface only
publicPrivate=Default public and private interfaces
publisher=Site
publishersClear=Brave Payments attention data
publisherMediaName={{publisherName}} on {{provider}}
publishers=Publishers
rank=Rank
Expand Down
1 change: 1 addition & 0 deletions app/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ var rendererIdentifiers = function () {
'dappDismiss',
'dappEnableExtension',
'banSiteConfirmation',
'paymentsDeleteWalletConfirmation',
'messageBoxOk',
'messageBoxCancel',
// other
Expand Down
16 changes: 16 additions & 0 deletions app/renderer/components/common/browserButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class BrowserButton extends ImmutableComponent {
styles.browserButton,
this.props.primaryColor && [styles.browserButton_default, styles.browserButton_primaryColor],
this.props.secondaryColor && [styles.browserButton_default, styles.browserButton_secondaryColor],
this.props.alertColor && [styles.browserButton_default, styles.browserButton_alertColor],
this.props.subtleItem && [styles.browserButton_default, styles.browserButton_subtleItem],
// actionItem is just subtleItem with a blue background
this.props.actionItem &&
Expand Down Expand Up @@ -195,6 +196,21 @@ const styles = StyleSheet.create({
}
},

browserButton_alertColor: {
background: globalStyles.button.alert.background,
borderLeft: `2px solid ${globalStyles.button.alert.gradientColor1}`,
borderRight: `2px solid ${globalStyles.button.alert.gradientColor2}`,
borderTop: `2px solid ${globalStyles.button.alert.gradientColor1}`,
borderBottom: `2px solid ${globalStyles.button.alert.gradientColor2}`,
cursor: 'pointer',
fontWeight: 500,

':hover': {
border: `2px solid ${globalStyles.button.alert.borderHoverColor}`,
color: globalStyles.button.alert.hoverColor
}
},

browserButton_extensionItem: {
backgroundSize: 'contain',
height: '17px',
Expand Down
Loading

0 comments on commit 38a27a5

Please sign in to comment.