Skip to content

Commit

Permalink
Adds dynamic dropdown for monthly amounts
Browse files Browse the repository at this point in the history
Resolves brave#12727

Auditors:

Test Plan:
  • Loading branch information
NejcZdovc committed Jan 19, 2018
1 parent fa416ba commit 2a4c138
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
14 changes: 14 additions & 0 deletions app/browser/api/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const clientOptions = {
version: 'v2',
environment: process.env.LEDGER_ENVIRONMENT || 'production'
}

const fileTypes = {
bmp: Buffer.from([0x42, 0x4d]),
gif: Buffer.from([0x47, 0x49, 0x46, 0x38, [0x37, 0x39], 0x61]),
Expand Down Expand Up @@ -1615,6 +1616,19 @@ const onWalletProperties = (state, body) => {
}
}

// monthly amount list
const list = body.getIn(['parameters', 'adFree', 'choices', 'BAT'])
let immutableList = (list == null || list.length === 0)
? ledgerUtil.defaultMonthlyAmounts
: Immutable.List(list)

// TODO add user check when #12720 is merged
const currentAmount = getSetting(settings.PAYMENTS_CONTRIBUTION_AMOUNT)
if (!immutableList.includes(currentAmount)) {
immutableList = immutableList.push(currentAmount).sort()
}
state = ledgerState.setInfoProp(state, 'monthlyAmounts', immutableList)

// unconfirmed amount
const unconfirmed = parseFloat(body.get('unconfirmed'))
if (unconfirmed >= 0) {
Expand Down
5 changes: 4 additions & 1 deletion app/common/lib/ledgerUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ const getMediaProvider = (url) => {
return provider
}

const defaultMonthlyAmounts = Immutable.List([5.0, 7.5, 10.0, 17.5, 25.0, 50.0, 75.0, 100.0])

const milliseconds = {
year: 365 * 24 * 60 * 60 * 1000,
week: 7 * 24 * 60 * 60 * 1000,
Expand Down Expand Up @@ -330,7 +332,8 @@ const getMethods = () => {
getMediaProvider,
getMediaData,
getMediaKey,
milliseconds
milliseconds,
defaultMonthlyAmounts
}

let privateMethods = {}
Expand Down
7 changes: 5 additions & 2 deletions app/renderer/components/preferences/payment/enabledContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const Immutable = require('immutable')
// util
const {batToCurrencyString, formatCurrentBalance, formattedDateFromTimestamp, walletStatus} = require('../../../../common/lib/ledgerUtil')
const {l10nErrorText} = require('../../../../common/lib/httpUtil')
const ledgerUtil = require('../../../../common/lib/ledgerUtil')
const {changeSetting} = require('../../../lib/settingsUtil')
const getSetting = require('../../../../../js/settings').getSetting
const settings = require('../../../../../js/constants/settings')
Expand Down Expand Up @@ -267,6 +268,7 @@ class EnabledContent extends ImmutableComponent {
const ledgerData = this.props.ledgerData
const walletStatusText = walletStatus(ledgerData)
const inTransition = ledgerData.getIn(['migration', 'btc2BatTransitionPending']) === true
const amountList = ledgerData.get('monthlyAmounts') || ledgerUtil.defaultMonthlyAmounts

return <section className={css(styles.enabledContent)}>
<div className={css(
Expand Down Expand Up @@ -306,9 +308,10 @@ class EnabledContent extends ImmutableComponent {
data-isPanel
data-test-id='fundsSelectBox'
value={getSetting(settings.PAYMENTS_CONTRIBUTION_AMOUNT, this.props.settings)}
onChange={changeSetting.bind(null, this.props.onChangeSetting, settings.PAYMENTS_CONTRIBUTION_AMOUNT)}>
onChange={changeSetting.bind(null, this.props.onChangeSetting, settings.PAYMENTS_CONTRIBUTION_AMOUNT)}
>
{
[5.0, 7.5, 10.0, 17.5, 25.0, 50.0, 75.0, 100.0].map((amount) => {
amountList.map((amount) => {
let alternative = ''
if (ledgerData.has('currentRate')) {
const converted = batToCurrencyString(amount, ledgerData)
Expand Down

0 comments on commit 2a4c138

Please sign in to comment.