Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand Rewards to three decimal places #5835

Open
wants to merge 1 commit into
base: 1.11.x
from
Open
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Expand Rewards to three decimal places

  • Loading branch information
tmancey committed Jun 1, 2020
commit f29cfa79e4587e1ddb4c53b1215ee3f1842eefd5
@@ -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>
@@ -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 {
@@ -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) {
@@ -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);
@@ -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() {
@@ -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,
@@ -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,
@@ -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) {
@@ -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,
@@ -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(
@@ -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(
@@ -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>
@@ -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>
@@ -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)}
/>
@@ -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,
@@ -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>}>
@@ -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)
@@ -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) {
@@ -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}
@@ -116,7 +116,7 @@ class Promotion extends React.Component<Props, State> {
return false
}

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

render () {
@@ -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
@@ -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`}
@@ -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,
@@ -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>
@@ -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)
}
})
@@ -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}
@@ -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)
@@ -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 ||
@@ -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)
}
})

@@ -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
@@ -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) {
@@ -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}
@@ -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
@@ -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>
@@ -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) => {
@@ -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}
>
{
@@ -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,
@@ -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>
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.