Skip to content

Commit

Permalink
Expand Rewards to three decimal places
Browse files Browse the repository at this point in the history
  • Loading branch information
tmancey committed Jun 13, 2020
1 parent 2e2ceab commit f29cfa7
Show file tree
Hide file tree
Showing 25 changed files with 72 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class Rewards extends React.PureComponent<RewardsProps, {}> {
{
!showEnableAds && !(type === AmountItemType.ADS && !adsSupported)
? <div data-test-id={`widget-amount-total-${type}`}>
<Amount>{amount.toFixed(1)}</Amount>
<Amount>{amount.toFixed(3)}</Amount>
<ConvertedAmount>
{batFormatString}<AmountUSD>{converted} USD</AmountUSD>
</ConvertedAmount>
Expand Down
26 changes: 13 additions & 13 deletions components/brave_rewards/browser/rewards_service_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ class BraveRewardsBrowserTest
}

static std::string BalanceDoubleToString(double amount) {
return base::StringPrintf("%.1f", amount);
return base::StringPrintf("%.3f", amount);
}

std::string GetBalance() const {
Expand Down Expand Up @@ -856,7 +856,7 @@ class BraveRewardsBrowserTest
rewards_service_browsertest_utils::WaitForElementToContain(
contents,
selector,
"30.0 BAT");
"30.000 BAT");

// Dismiss the promotion notification
if (use_panel) {
Expand Down Expand Up @@ -1018,9 +1018,9 @@ class BraveRewardsBrowserTest
std::vector<double> tip_options =
GetSiteBannerTipOptions(site_banner_contents);
const double amount = tip_options.at(selection);
const std::string amount_str = base::StringPrintf("%2.1f", amount);
const std::string amount_str = base::StringPrintf("%.3f", amount);

// Select the tip amount (default is 1.0 BAT)
// Select the tip amount (default is 1.000 BAT)
std::string amount_selector = base::StringPrintf(
"div:nth-of-type(%u)>[data-test-id=amount-wrapper]",
selection + 1);
Expand Down Expand Up @@ -1134,7 +1134,7 @@ class BraveRewardsBrowserTest
rewards_service_browsertest_utils::WaitForElementToEqual(
contents(),
"#tip-box-total",
"0.0BAT0.00 USD");
"0.000BAT0.00 USD");
}

void IsBalanceCorrect() {
Expand Down Expand Up @@ -1819,7 +1819,7 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, AutoContribution) {
rewards_service_browsertest_utils::WaitForElementToContain(
contents(),
"[color=contribute]",
"-20.0BAT");
"-20.000BAT");
}

IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest,
Expand Down Expand Up @@ -1848,7 +1848,7 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest,
rewards_service_browsertest_utils::WaitForElementToContain(
contents(),
"[color=contribute]",
"-20.0BAT");
"-20.000BAT");
}

IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest,
Expand Down Expand Up @@ -1894,7 +1894,7 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest,
rewards_service_browsertest_utils::WaitForElementToContain(
contents(),
"[color=contribute]",
"-20.0BAT");
"-20.000BAT");
}

IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest, AutoContributeWhenACOff) {
Expand Down Expand Up @@ -2681,7 +2681,7 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest,
rewards_service_browsertest_utils::WaitForElementToContain(
contents(),
"[color='contribute']",
"-5.0BAT");
"-5.000BAT");
}

IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest,
Expand Down Expand Up @@ -2743,7 +2743,7 @@ IN_PROC_BROWSER_TEST_F(BraveRewardsBrowserTest,
rewards_service_browsertest_utils::WaitForElementToContain(
contents(),
"[color='contribute']",
"-5.0BAT");
"-5.000BAT");
}

IN_PROC_BROWSER_TEST_F(
Expand Down Expand Up @@ -2851,18 +2851,18 @@ IN_PROC_BROWSER_TEST_F(
rewards_service_browsertest_utils::WaitForElementToContain(
contents(),
"#transactionTable",
"-30.0BAT");
"-30.000BAT");

rewards_service_browsertest_utils::WaitForElementToContain(
contents(),
"#transactionTable",
"-20.0BAT");
"-20.000BAT");

// Check that summary table shows the appropriate contribution
rewards_service_browsertest_utils::WaitForElementToContain(
contents(),
"[color=contribute]",
"-50.0BAT");
"-50.000BAT");
}

IN_PROC_BROWSER_TEST_F(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class AdsBox extends React.Component<Props, {}> {
<StyledTotalContent>
<Tokens
onlyAnonWallet={onlyAnonWallet}
value={estimatedPendingRewards.toFixed(1)}
value={estimatedPendingRewards.toFixed(3)}
converted={utils.convertBalance(estimatedPendingRewards, parameters.rate)}
/>
</StyledTotalContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class ContributeBox extends React.Component<Props, State> {
<SelectMobile
onlyAnonWallet={onlyAnonWallet}
onChange={this.onSelectSettingChange.bind(this, 'contributionMonthly')}
value={parseFloat((contributionMonthly.toString() || '0')).toFixed(1)}
value={parseFloat((contributionMonthly.toString() || '0')).toFixed(3)}
amountOptions={this.getAmountOptions(monthlyList)}
/>
</ControlWrapper>
Expand Down Expand Up @@ -282,7 +282,7 @@ class ContributeBox extends React.Component<Props, State> {
<SelectMobile
floating={true}
onChange={this.onSelectSettingChange.bind(this, 'contributionMonthly')}
value={parseFloat((contributionMonthly.toString() || '0')).toFixed(1)}
value={parseFloat((contributionMonthly.toString() || '0')).toFixed(3)}
onlyAnonWallet={onlyAnonWallet}
amountOptions={this.getAmountOptions(monthlyList)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class MonthlyContributionBox extends React.Component<Props, State> {
src: faviconUrl
},
contribute: {
tokens: item.percentage.toFixed(1),
tokens: item.percentage.toFixed(3),
converted: utils.convertBalance(item.percentage, parameters.rate)
},
url: item.url,
Expand Down Expand Up @@ -115,7 +115,7 @@ class MonthlyContributionBox extends React.Component<Props, State> {
}
<List title={<StyledListContent>{getLocale('donationTotalMonthlyContribution')}</StyledListContent>}>
<StyledTotalContent>
<Tokens value={total.toFixed(1)} converted={converted} />
<Tokens value={total.toFixed(3)} converted={converted} />
</StyledTotalContent>
</List>
<List title={<StyledListContent>{getLocale('donationNextDate')}</StyledListContent>}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class PageWallet extends React.Component<Props, State> {
const item = balanceReport[key]

if (item !== 0) {
const tokens = item.toFixed(1)
const tokens = item.toFixed(3)
props[key] = {
tokens,
converted: utils.convertBalance(item, parameters.rate)
Expand All @@ -115,7 +115,7 @@ class PageWallet extends React.Component<Props, State> {
} = this.props.rewardsData
const { emptyWallet, onlyAnonWallet } = ui
const { total } = balance
const pendingTotal = parseFloat((pendingContributionTotal || 0).toFixed(1))
const pendingTotal = parseFloat((pendingContributionTotal || 0).toFixed(3))

let showCopy = false
if (!onlyAnonWallet) {
Expand All @@ -134,7 +134,7 @@ class PageWallet extends React.Component<Props, State> {
</StyledWalletClose>
<StyledWalletWrapper>
<WalletWrapper
balance={total.toFixed(1)}
balance={total.toFixed(3)}
converted={utils.formatConverted(this.getConversion())}
actions={[]}
compact={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class Promotion extends React.Component<Props, State> {
return false
}

return tokens !== '0.0'
return tokens !== '0.000'
}

render () {
Expand All @@ -130,15 +130,15 @@ class Promotion extends React.Component<Props, State> {
// Handle that ugp type string can actually be 'android' on android
let type: PromotionType = promotion.type === 1 ? 'ads' : 'ugp'
let promoId
let tokens = '0.0'
let tokens = '0.000'
let date = ''

if (promotion.promotionId) {
promoId = promotion.promotionId
}

if (promotion.amount) {
tokens = promotion.amount.toFixed(1)
tokens = promotion.amount.toFixed(3)
}

if (promotion.type !== 1) { // Rewards.PromotionTypes.ADS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class SettingsPage extends React.Component<Props, State> {
}
<WalletInfoHeader
onClick={this.onToggleWallet}
balance={total.toFixed(1).toString()}
balance={total.toFixed(3).toString()}
id={'mobile-wallet'}
onlyAnonWallet={onlyAnonWallet}
converted={`${convertedBalance} USD`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class TipBox extends React.Component<Props, State> {
src: faviconUrl
},
contribute: {
tokens: item.percentage.toFixed(1),
tokens: item.percentage.toFixed(3),
converted: utils.convertBalance(item.percentage, parameters.rate)
},
url: item.url,
Expand Down Expand Up @@ -121,7 +121,7 @@ class TipBox extends React.Component<Props, State> {
}
<List title={<StyledListContent>{getLocale('donationTotalDonations')}</StyledListContent>}>
<StyledTotalContent>
<Tokens onlyAnonWallet={onlyAnonWallet} value={total.toFixed(1)} converted={converted} />
<Tokens onlyAnonWallet={onlyAnonWallet} value={total.toFixed(3)} converted={converted} />
</StyledTotalContent>
</List>
<StyledListContent>
Expand Down
2 changes: 1 addition & 1 deletion components/brave_rewards/resources/android_page/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const generateContributionMonthly = (properties: Rewards.RewardsParameter

return properties.autoContributeChoices.map((item: number) => {
return {
tokens: item.toFixed(1),
tokens: item.toFixed(3),
converted: convertBalance(item, properties.rate)
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ export class RewardsPanel extends React.Component<Props, State> {
compact={true}
contentPadding={false}
gradientTop={'249,251,252'}
balance={total.toFixed(1)}
balance={total.toFixed(3)}
showSecActions={false}
showCopy={false}
onlyAnonWallet={this.state.onlyAnonWallet}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export class Panel extends React.Component<Props, State> {
const item = balanceReport[key]

if (item !== 0) {
const tokens = item.toFixed(1)
const tokens = item.toFixed(3)
props[key] = {
tokens,
converted: utils.convertBalance(item, parameters.rate)
Expand Down Expand Up @@ -533,15 +533,15 @@ export class Panel extends React.Component<Props, State> {

return amounts.map((value: number) => {
return {
tokens: value.toFixed(1),
tokens: value.toFixed(3),
converted: utils.convertBalance(value, parameters.rate),
selected: false
}
})
}

getContribution = (publisher?: RewardsExtension.Publisher) => {
let defaultContribution = '0.0'
let defaultContribution = '0.000'
const { recurringTips } = this.props.rewardsPanelData

if (!recurringTips ||
Expand All @@ -551,7 +551,7 @@ export class Panel extends React.Component<Props, State> {

recurringTips.map((tip: any) => {
if (tip.publisherKey === publisher.publisher_key) {
defaultContribution = tip.amount.toFixed(1)
defaultContribution = tip.amount.toFixed(3)
}
})

Expand Down Expand Up @@ -691,7 +691,7 @@ export class Panel extends React.Component<Props, State> {
const notificationClick = this.getNotificationClickEvent(notificationType, notificationId)
const defaultContribution = this.getContribution(publisher)
const checkmark = publisher && utils.isPublisherConnectedOrVerified(publisher.status)
const tipAmounts = defaultContribution !== '0.0'
const tipAmounts = defaultContribution !== '0.000'
? this.generateAmounts(publisher)
: undefined
const { onlyAnonWallet } = this.props
Expand All @@ -703,7 +703,7 @@ export class Panel extends React.Component<Props, State> {
}

const pendingTotal = parseFloat(
(pendingContributionTotal || 0).toFixed(1))
(pendingContributionTotal || 0).toFixed(3))

let faviconUrl
if (publisher && publisher.url) {
Expand All @@ -727,7 +727,7 @@ export class Panel extends React.Component<Props, State> {
compact={true}
contentPadding={false}
gradientTop={this.gradientColor}
balance={total.toFixed(1)}
balance={total.toFixed(3)}
converted={utils.formatConverted(converted)}
actions={this.getActions()}
showCopy={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ export const formatConverted = (converted: string, currency: string = 'USD'): st
}

export const handleContributionAmount = (amount: string) => {
let result = '0.0'
let result = '0.000'
const amountSplit = amount.split('.')
if (amountSplit && amountSplit[0].length > 18) {
const result = new BigNumber(amount).dividedBy('1e18').toFixed(1, BigNumber.ROUND_UP)
const result = new BigNumber(amount).dividedBy('1e18').toFixed(3, BigNumber.ROUND_UP)

return result
} else {
result = parseFloat(amount).toFixed(1)
result = parseFloat(amount).toFixed(3)
}

if (result === 'NaN') {
return '0.0'
return '0.000'
}

return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ class AdsBox extends React.Component<Props, State> {
<List title={getLocale('adsCurrentEarnings')}>
<Tokens
onlyAnonWallet={onlyAnonWallet}
value={estimatedPendingRewards.toFixed(1)}
value={estimatedPendingRewards.toFixed(3)}
converted={utils.convertBalance(estimatedPendingRewards, parameters.rate)}
/>
</List>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class ContributeBox extends React.Component<Props, State> {
<ControlWrapper text={getLocale('contributionMonthly')}>
<Select
onChange={this.onSelectSettingChange.bind(this, 'contributionMonthly')}
value={parseFloat((contributionMonthly.toString() || '0')).toFixed(1)}
value={parseFloat((contributionMonthly.toString() || '0')).toFixed(3)}
>
{
monthlyList.map((choice: MonthlyChoice) => {
Expand Down Expand Up @@ -271,7 +271,7 @@ class ContributeBox extends React.Component<Props, State> {
<Select
floating={true}
onChange={this.onSelectSettingChange.bind(this, 'contributionMonthly')}
value={parseFloat((contributionMonthly.toString() || '0')).toFixed(1)}
value={parseFloat((contributionMonthly.toString() || '0')).toFixed(3)}
showAllContents={true}
>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class MonthlyContributionBox extends React.Component<Props, State> {
src: faviconUrl
},
contribute: {
tokens: item.percentage.toFixed(1),
tokens: item.percentage.toFixed(3),
converted: utils.convertBalance(item.percentage, parameters.rate)
},
url: item.url,
Expand Down Expand Up @@ -126,7 +126,7 @@ class MonthlyContributionBox extends React.Component<Props, State> {
: null
}
<List title={getLocale('donationTotalMonthlyContribution')}>
<Tokens onlyAnonWallet={onlyAnonWallet} value={total.toFixed(1)} converted={converted} />
<Tokens onlyAnonWallet={onlyAnonWallet} value={total.toFixed(3)} converted={converted} />
</List>
<List title={getLocale('donationNextDate')}>
<NextContribution>
Expand Down
Loading

0 comments on commit f29cfa7

Please sign in to comment.