Skip to content

Commit

Permalink
Adds new balance breakdown
Browse files Browse the repository at this point in the history
Resolves brave#14229

Auditors:

Test Plan:
  • Loading branch information
NejcZdovc committed May 25, 2018
1 parent d4428e0 commit 80cd075
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 30 deletions.
30 changes: 24 additions & 6 deletions app/browser/api/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -1880,15 +1880,33 @@ const onWalletProperties = (state, body) => {
state = ledgerState.setInfoProp(state, 'currentRate', rate)
}

// Probi
// Grants
const probi = parseFloat(body.get('probi'))
if (probi >= 0) {
state = ledgerState.setInfoProp(state, 'probi', probi)
let userFunded = probi
let grants = body.get('grants') || Immutable.List()
if (!grants.isEmpty()) {
let grantTotal = 0
grants = grants.map(grant => {
const amount = new BigNumber(grant.get('probi').toString()).dividedBy('1e18').toNumber()
grantTotal += parseFloat(grant.get('probi'))
return {
amount: amount,
expirationDate: grant.get('expiryTime')
}
})
state = ledgerState.setInfoProp(state, 'grants', grants)

const amount = info.get('balance')
if (!isNaN(probi)) {
userFunded = probi - grantTotal
}
}
state = ledgerState.setInfoProp(state, 'userFunded', new BigNumber(userFunded.toString()).dividedBy('1e18').toNumber())

if (amount != null && rate) {
const bigProbi = new BigNumber(probi.toString()).dividedBy('1e18')
// Probi
if (probi >= 0) {
state = ledgerState.setInfoProp(state, 'probi', probi)
if (userFunded != null && rate) {
const bigProbi = new BigNumber(userFunded.toString()).dividedBy('1e18')
const bigRate = new BigNumber(rate.toString())
const converted = bigProbi.times(bigRate).toNumber()

Expand Down
6 changes: 3 additions & 3 deletions app/common/lib/ledgerUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ const batToCurrencyString = (bat, ledgerData) => {
return `${converted} ${currency}`
}

const formatCurrentBalance = (ledgerData) => {
const formatCurrentBalance = (ledgerData, amount, showAlt = true) => {
let currency = 'USD'
let balance = 0
let converted = 0
let hasRate = false

if (ledgerData != null) {
balance = Number(ledgerData.get('balance') || 0)
balance = Number(amount || 0)
converted = Number.parseFloat(ledgerData.get('converted')) || 0
hasRate = ledgerData.has('currentRate') && ledgerData.hasIn(['rates', 'BTC'])
hasRate = showAlt ? ledgerData.has('currentRate') && ledgerData.hasIn(['rates', 'BTC']) : false
}

balance = balance.toFixed(2)
Expand Down
2 changes: 2 additions & 0 deletions app/extensions/brave/locales/en-US/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ engineGoKey=Engine Go Key (Type First)
engineGoKey=Engine Go Key (type first)
enpass=Enpass® (requires application)
extensions=Extensions
expires=expires
flash=Run Adobe Flash Player
flashAllowAlways=Allow until {{time}}
flashTroubleshooting=Flash not working? Try the troubleshooting tips on our
Expand Down Expand Up @@ -385,6 +386,7 @@ tabsSettings=Tabs Settings
termsOfService=Terms of Service
timeSpent=Time Spent
toolbarUserInterfaceScale=Toolbar and UI elements scale
total=total
totalAmount=Total Amount
update=Update
updateToPreviewReleases=Update to preview releases *
Expand Down
66 changes: 45 additions & 21 deletions app/renderer/components/preferences/payment/enabledContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const Immutable = require('immutable')
// Components
const ImmutableComponent = require('../../immutableComponent')
const BrowserButton = require('../../common/browserButton')
const {FormTextbox} = require('../../common/textbox')
const {FormDropdown} = require('../../common/dropdown')
const LedgerTable = require('./ledgerTable')
const Captcha = require('./captcha')
Expand Down Expand Up @@ -143,15 +142,31 @@ class EnabledContent extends ImmutableComponent {

fundsAmount () {
const ledgerData = this.props.ledgerData
const val = formatCurrentBalance(ledgerData) || ''
const big = val.length > 23

return <FormTextbox
readOnly
data-test-id='fundsAmount'
value={val}
customClass={big && styles.width_input}
/>
if (!ledgerData) {
return
}

const total = formatCurrentBalance(ledgerData, ledgerData.get('balance'), false) || ''
const userFunded = formatCurrentBalance(ledgerData, ledgerData.get('userFunded')) || ''
const grants = ledgerData.get('grants') || Immutable.List()

// at lest 195px width
return <div className={css(styles.fundsAmount)}>
<div className={css(styles.fundsAmount__item)}>
{userFunded}
</div>
{
grants.map(grant => {
return <div className={css(styles.fundsAmount__item)}>
{formatCurrentBalance(ledgerData, grant.get('amount'), false)}
<span> (<span data-l10n-id='expires' /> {new Date(grant.get('expirationDate') * 1000).toLocaleDateString()})</span>
</div>
})
}
<div className={css(styles.fundsAmount__item, styles.fundsAmount__total)}>
{total} (<span data-l10n-id='total' />)
</div>
</div>
}

lastReconcileMessage () {
Expand Down Expand Up @@ -179,8 +194,7 @@ class EnabledContent extends ImmutableComponent {
}

return <section>
<div data-l10n-id='lastContribution' />
<div data-l10n-id={text} data-l10n-args={JSON.stringify(l10nDataArgs)} />
<span data-l10n-id='lastContribution' /> <span data-l10n-id={text} data-l10n-args={JSON.stringify(l10nDataArgs)} />
</section>
}

Expand Down Expand Up @@ -220,8 +234,7 @@ class EnabledContent extends ImmutableComponent {
}

return <section>
<div data-l10n-id='nextContribution' />
<div data-l10n-args={JSON.stringify(l10nDataArgs)} data-l10n-id={l10nDataId} />
<span data-l10n-id='nextContribution' /> <span data-l10n-args={JSON.stringify(l10nDataArgs)} data-l10n-id={l10nDataId} />
</section>
}

Expand Down Expand Up @@ -419,7 +432,7 @@ class EnabledContent extends ImmutableComponent {
}
</FormDropdown>
</div>
<div className={css(gridStyles.row2col2)}>
<div className={css(gridStyles.row2col2, gridStyles.mergeRow23Col2)}>
{
ledgerData.get('error') && ledgerData.get('error').get('caller') === 'getWalletProperties'
? <div data-l10n-id='accountBalanceConnectionError' />
Expand All @@ -431,8 +444,6 @@ class EnabledContent extends ImmutableComponent {
</div>
<div className={css(gridStyles.row3col1, styles.enabledContent__walletBar__message)}>
{this.lastReconcileMessage()}
</div>
<div className={css(gridStyles.row3col2, styles.enabledContent__walletBar__message)}>
{
ledgerData.get('error') && ledgerData.get('error').get('caller') === 'getWalletProperties'
? <div data-l10n-id={this.ledgerDataErrorText()} />
Expand Down Expand Up @@ -524,6 +535,10 @@ const gridStyles = StyleSheet.create({
gridColumn: 3,
marginRight: globalStyles.spacing.panelPadding,
marginBottom: globalStyles.spacing.panelPadding
},

mergeRow23Col2: {
gridRow: '2 / span 2'
}
})

Expand All @@ -532,10 +547,6 @@ const styles = StyleSheet.create({
marginTop: '10px'
},

width_input: {
width: '195px'
},

iconLink: {
color: globalStyles.color.mediumGray,
fontSize: globalStyles.payments.fontSize.regular,
Expand Down Expand Up @@ -679,6 +690,19 @@ const styles = StyleSheet.create({
fontSize: globalStyles.payments.fontSize.regular,
lineHeight: 1.5,
marginTop: globalStyles.spacing.panelPadding
},

fundsAmount__item: {
marginBottom: '4px',
width: '215px',
fontSize: '14.5px'
},

fundsAmount__total: {
marginTop: '10px',
paddingTop: '12px',
borderTop: '1px solid #999',
fontSize: '15px'
}
})

Expand Down
5 changes: 5 additions & 0 deletions docs/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ AppStore
created, boolean, // wallet is created
creating: boolean, // wallet is being created
currentRate: number,
grants: [{
amount: number,
expirationDate: number
}]
hasBitcoinHandler: boolean, // brave browser has a `bitcoin:` URI handler
monthlyAmounts: Array<float> // list of all monthly amounts for the contribution
passphrase: string, // the BAT wallet passphrase
Expand Down Expand Up @@ -245,6 +249,7 @@ AppStore
viewingId: string, // UUIDv4 for this contribution
}],
unconfirmed: string, // unconfirmed balance in BAT.toFixed(2)
userFunded: number, // amount funded by the user
userHasFunded: boolean // permanently true once user funds wallet
},
locations: {
Expand Down

0 comments on commit 80cd075

Please sign in to comment.