Skip to content

Commit

Permalink
Merge pull request #3963 from brave/bat-points-android
Browse files Browse the repository at this point in the history
Port BAT Points work
  • Loading branch information
emerick authored Nov 13, 2019
2 parents f69be6c + 6e0b0dc commit f120d2b
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,9 @@ export const onBalance = (status: number, balance: Rewards.Balance) => action(ty
status,
balance
})

export const onlyAnonWallet = () => action(types.ONLY_ANON_WALLET)

export const onOnlyAnonWallet = (only: boolean) => action(types.ON_ONLY_ANON_WALLET, {
only
})
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ window.cr.define('brave_rewards', function () {
getActions().getWalletProperties()
}

function onlyAnonWallet (only: boolean) {
getActions().onOnlyAnonWallet(only)
}

return {
initialize,
walletCreated,
Expand Down Expand Up @@ -196,7 +200,8 @@ window.cr.define('brave_rewards', function () {
excludedList,
excludedSiteChanged,
balance,
reconcileComplete
reconcileComplete,
onlyAnonWallet
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class AdsBox extends React.Component<Props, {}> {
balance,
safetyNetFailed
} = this.props.rewardsData
const { onlyAnonWallet } = this.props.rewardsData.ui

if (adsData) {
adsEnabled = adsData.adsEnabled
Expand Down Expand Up @@ -117,17 +118,20 @@ class AdsBox extends React.Component<Props, {}> {
boxPropsExtra.extraDescriptionChild = <AdsOnboarding />
}

const tokenString = getLocale(onlyAnonWallet ? 'points' : 'tokens')

return (
<BoxMobile
title={getLocale('adsTitle')}
type={'ads'}
description={getLocale('adsDesc')}
description={getLocale('adsDesc', { currency : tokenString })}
settingsChild={this.adsSettings(adsEnabled && enabledMain)}
{...boxPropsExtra}
>
<List title={<StyledListContent>{getLocale('adsCurrentEarnings')}</StyledListContent>}>
<StyledTotalContent>
<Tokens
onlyAnonWallet={onlyAnonWallet}
value={estimatedPendingRewards}
converted={utils.convertBalance(estimatedPendingRewards, balance.rates)}
/>
Expand All @@ -143,6 +147,7 @@ class AdsBox extends React.Component<Props, {}> {
<List title={<StyledListContent>{getLocale('adsNotificationsReceived')}</StyledListContent>}>
<StyledListContent>
<Tokens
onlyAnonWallet={onlyAnonWallet}
value={adNotificationsReceivedThisMonth.toString()}
hideText={true}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export class App extends React.Component<Props, State> {
this.props.actions.onAdsSettingSave('adsEnabledMigrated', adsEnabled)
}
}

this.actions.onlyAnonWallet()
}

componentDidUpdate (prevProps: Props, prevState: State) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class ContributeBox extends React.Component<Props, State> {
contributionMonthly,
enabledMain
} = this.props.rewardsData
const { onlyAnonWallet } = this.props.rewardsData.ui

if (!enabledMain) {
return null
Expand All @@ -120,6 +121,7 @@ class ContributeBox extends React.Component<Props, State> {
<Column size={1} customStyle={{ justifyContent: 'center', flexWrap: 'wrap' }}>
<ControlWrapper text={getLocale('contributionMonthly')}>
<SelectMobile
onlyAnonWallet={onlyAnonWallet}
amountOptions={this.getAmountOptions(monthlyList)}
onChange={this.onSelectSettingChange.bind(this, 'contributionMonthly')}
value={parseFloat((contributionMonthly.toString() || '0')).toFixed(1)}
Expand Down Expand Up @@ -194,6 +196,7 @@ class ContributeBox extends React.Component<Props, State> {
excludedList,
balance
} = this.props.rewardsData
const { onlyAnonWallet } = this.props.rewardsData.ui
const prefix = this.state.allSitesShown ? 'Hide all' : 'Show all'
const monthlyList: MonthlyChoice[] = utils.generateContributionMonthly(walletInfo.choices, balance.rates)
const contributeRows = this.getContributeRows(autoContributeList)
Expand All @@ -215,6 +218,7 @@ class ContributeBox extends React.Component<Props, State> {
<StyledListContent>
<SelectMobile
floating={true}
onlyAnonWallet={onlyAnonWallet}
amountOptions={this.getAmountOptions(monthlyList)}
onChange={this.onSelectSettingChange.bind(this, 'contributionMonthly')}
value={parseFloat((contributionMonthly.toString() || '0')).toFixed(1)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ interface State {

interface Props extends Rewards.ComponentProps {
grant: Rewards.Grant
onlyAnonWallet?: boolean
}

type GrantWrapperContentProps = {
Expand Down Expand Up @@ -114,6 +115,7 @@ class Grant extends React.Component<Props, State> {

render () {
const { grant } = this.props
const { onlyAnonWallet } = this.props

if (!grant) {
return null
Expand Down Expand Up @@ -163,6 +165,7 @@ class Grant extends React.Component<Props, State> {
onClose={this.onSuccess}
amount={tokens}
date={date}
onlyAnonWallet={onlyAnonWallet}
{...getGrantCompleteContentProps(type)}
/>
</GrantWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,15 @@ class PageWallet extends React.Component<Props, State> {
ui,
pendingContributionTotal
} = this.props.rewardsData
const { emptyWallet } = ui
const { emptyWallet, onlyAnonWallet } = ui
const { total } = balance
const pendingTotal = parseFloat((pendingContributionTotal || 0).toFixed(1))

let showCopy = false
if (!onlyAnonWallet) {
showCopy = true
}

if (!visible) {
return null
}
Expand All @@ -133,17 +138,19 @@ class PageWallet extends React.Component<Props, State> {
actions={[]}
compact={true}
isMobile={true}
showCopy={true}
showCopy={showCopy}
showSecActions={false}
grants={this.getGrants()}
alert={this.walletAlerts()}
onlyAnonWallet={onlyAnonWallet}
>
{
enabledMain
? emptyWallet
? <WalletEmpty hideAddFundsText={true} />
: <WalletSummary
reservedAmount={pendingTotal}
onlyAnonWallet={onlyAnonWallet}
reservedMoreLink={'https://brave.com/faq-rewards/#unclaimed-funds'}
{...this.getWalletSummary()}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class SettingsPage extends React.Component<Props, State> {
}

getGrantClaims = () => {
const { grants } = this.props.rewardsData
const { grants, ui } = this.props.rewardsData

if (!grants) {
return null
Expand All @@ -140,7 +140,7 @@ class SettingsPage extends React.Component<Props, State> {

return (
<div key={`grant-${index}`}>
<Grant grant={grant} />
<Grant grant={grant} onlyAnonWallet={ui.onlyAnonWallet} />
</div>
)
})}
Expand All @@ -154,6 +154,7 @@ class SettingsPage extends React.Component<Props, State> {

render () {
const { enabledMain, balance } = this.props.rewardsData
const { onlyAnonWallet } = this.props.rewardsData.ui
const { total } = balance
const convertedBalance = utils.convertBalance((total || 0).toString(), balance.rates)

Expand Down Expand Up @@ -187,6 +188,7 @@ class SettingsPage extends React.Component<Props, State> {
onClick={this.onToggleWallet}
balance={total.toFixed(1).toString()}
id={'mobile-wallet'}
onlyAnonWallet={onlyAnonWallet}
converted={`${convertedBalance} USD`}
/>
<AdsBox />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class TipBox extends React.Component<Props, State> {
ui,
tipsList
} = this.props.rewardsData
const { walletImported } = ui
const { walletImported, onlyAnonWallet } = ui
const showDisabled = firstLoad !== false || !enabledMain
const tipRows = this.getTipsRows()
const topRows = tipRows.slice(0, 5)
Expand Down Expand Up @@ -207,13 +207,14 @@ class TipBox extends React.Component<Props, State> {
: null
}
<List title={getLocale('donationTotalDonations')}>
<Tokens value={total} converted={converted} />
<Tokens onlyAnonWallet={onlyAnonWallet} value={total} converted={converted} />
</List>
<TableDonation
rows={topRows}
allItems={allSites}
numItems={numRows}
headerColor={true}
onlyAnonWallet={onlyAnonWallet}
onShowAll={this.onModalToggle}
>
{getLocale('donationVisitSome')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,7 @@ export const enum types {
GET_EXCLUDED_SITES = '@@rewards/GET_EXCLUDED_SITES',
ON_EXCLUDED_LIST = '@@rewards/ON_EXCLUDED_LIST',
GET_BALANCE = '@@rewards/GET_BALANCE',
ON_BALANCE = '@@rewards/ON_BALANCE'
ON_BALANCE = '@@rewards/ON_BALANCE',
ONLY_ANON_WALLET = '@@rewards/ONLY_ANON_WALLET',
ON_ONLY_ANON_WALLET = '@@rewards/ON_ONLY_ANON_WALLET'
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,21 @@ const rewardsReducer: Reducer<Rewards.State | undefined> = (state: Rewards.State
chrome.send('brave_rewards.getRewardsMainEnabled', [])
break
}
case types.ONLY_ANON_WALLET: {
chrome.send('brave_rewards.onlyAnonWallet')
break
}
case types.ON_ONLY_ANON_WALLET: {
const ui = state.ui

ui.onlyAnonWallet = !!action.payload.only

state = {
...state,
ui
}
break
}
}

return state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default class SelectMobile extends React.PureComponent<Props, {}> {
return null
}

const batFormatString = onlyAnonWallet ? 'bap' : 'bat'
const batFormatString = onlyAnonWallet ? getLocale('batPoints') : getLocale('bat')

return (
<>
Expand All @@ -74,7 +74,7 @@ export default class SelectMobile extends React.PureComponent<Props, {}> {
key={`k-${amount.value}`}
value={amount.dataValue}
>
{amount.value} {getLocale(batFormatString)} ({amount.converted} USD)
{amount.value} {batFormatString} ({amount.converted} USD)
</option>
)
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class WalletInfoHeader extends React.PureComponent<Props, {}> {

render () {
const { id, balance, converted, onlyAnonWallet, onClick } = this.props
const batFormatString = onlyAnonWallet ? 'bap' : 'bat'
const batFormatString = onlyAnonWallet ? getLocale('batPoints') : getLocale('bat')

return (
<StyledWrapper
Expand All @@ -37,7 +37,7 @@ export default class WalletInfoHeader extends React.PureComponent<Props, {}> {
<StyledTitle>{getLocale('yourWallet')}</StyledTitle>
<StyledBalance>
<StyledBalanceTokens>
{balance} <StyledBalanceCurrency>{getLocale(batFormatString)}</StyledBalanceCurrency>
{balance} <StyledBalanceCurrency>{batFormatString}</StyledBalanceCurrency>
</StyledBalanceTokens>
{
converted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const StyledBalanceTokens = styled<{}, 'div'>('div')`
letter-spacing: -0.4px;
color: #fff;
font-weight: 300;
margin-top: 10px;
margin-top: 25px;
`

export const StyledBalanceConverted = styled<{}, 'div'>('div')`
Expand Down

0 comments on commit f120d2b

Please sign in to comment.