Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Improve UX of unavailable ledger balance
Browse files Browse the repository at this point in the history
Fix #3778
Fix #3785 or at least a gentle fallback
  • Loading branch information
ayumi committed Sep 8, 2016
1 parent 8d0dd96 commit fffa903
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 13 deletions.
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 @@ -24,6 +24,8 @@ paymentsSidebarText2=All transaction IP addresses are anonymized with technology
paymentsSidebarText3=Brave Bitcoin Wallets are provided through a partnership with:
paymentsSidebarText4=Your contributions in the form of credit cards and bank cards are handled by:
accountBalance=account balance
accountBalanceConnectionError=error, can't retreive data
accountBalanceLoading=loading...
monthlyBudget=monthly budget
status=status
createWallet=create wallet
Expand Down
21 changes: 19 additions & 2 deletions app/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,8 @@ var ledgerInfo = {

hasBitcoinHandler: false,

_internal: {}
_internal: {},
error: null
}

var updateLedgerInfo = () => {
Expand Down Expand Up @@ -1013,6 +1014,20 @@ var getBalance = () => {
})
}

var logError = (err, caller) => {
if (err) {
ledgerInfo.error = {
caller: caller,
error: err
}
console.log('Error in %j: %j', caller, err)
return true
} else {
ledgerInfo.error = null
return false
}
}

var getPaymentInfo = () => {
var amount, currency

Expand All @@ -1028,7 +1043,9 @@ var getPaymentInfo = () => {
client.getWalletProperties(amount, currency, function (err, body) {
var info = ledgerInfo._internal.paymentInfo || {}

if (err) return console.log('getWalletProperties error: ' + err.toString())
if (logError(err, 'getWalletProperties')) {
return
}

info = underscore.extend(info, underscore.pick(body, [ 'buyURL', 'buyURLExpires', 'balance', 'unconfirmed', 'satoshis' ]))
info.address = client.getWalletAddress()
Expand Down
10 changes: 7 additions & 3 deletions docs/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ WindowStore
reconcileStamp: number, // timestamp for the next reconcilation
transactions: [ { // contributions reconciling/reconciled
viewingId: string, // UUIDv4 for this contribution
contribution: { //
contribution: { //
fiat: { // roughly-equivalent fiat amount
amount: number, // e.g., 5
currency: string // e.g., "USD"
Expand All @@ -411,7 +411,7 @@ WindowStore
[currency]: number // e.g., { "USD": 575.45 }
},
satoshis: number, // actual number of satoshis transferred
fee: number // bitcoin transaction fee
fee: number // bitcoin transaction fee
},
submissionStamp: number, // timestamp for this contribution
count: number, // total number of ballots allowed to be cast
Expand All @@ -435,7 +435,11 @@ WindowStore
}
},
hasBitcoinHandler: boolean, // brave browser has a `bitcoin:` URI handler
paymentIMG: string // the QR code equivalent of `paymentURL` expressed as "data:image/...;base64,..."
paymentIMG: string, // the QR code equivalent of `paymentURL` expressed as "data:image/...;base64,..."
error: { // non-null if the last updateLedgerInfo happened concurrently with an error
caller: string // function in which error was handled
error: object // error object returned
}
},
publisherInfo: [ // one entry for each publisher having a non-zero `score`
{
Expand Down
36 changes: 28 additions & 8 deletions js/about/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,25 @@ class PaymentsTab extends ImmutableComponent {
return getSetting(settings.PAYMENTS_ENABLED, this.props.settings)
}

get fundsAmount () {
if (!this.props.ledgerData.get('created')) {
return null
}

return <span id='fundsAmount'>
{
!(this.props.ledgerData.get('balance') === undefined || this.props.ledgerData.get('balance') === null)
? <span>
{this.btcToCurrencyString(this.props.ledgerData.get('balance'))}
<a href='https://brave.com/Payments_FAQ.html' target='_blank'>
<span className='fa fa-question-circle fundsFAQ' />
</a>
</span>
: <span><span data-l10n-id='accountBalanceLoading' /></span>
}
</span>
}

get walletButton () {
const buttonText = this.props.ledgerData.get('created')
? 'addFundsTitle'
Expand Down Expand Up @@ -708,14 +727,15 @@ class PaymentsTab extends ImmutableComponent {
<tbody>
<tr>
<td>
<span id='fundsAmount'>
{this.btcToCurrencyString(this.props.ledgerData.get('balance'))}
<a href='https://brave.com/Payments_FAQ.html' target='_blank'>
<span className='fa fa-question-circle fundsFAQ' />
</a>
</span>
{this.walletButton}
{this.paymentHistoryButton}
{
this.props.ledgerData.get('error') && this.props.ledgerData.get('error').get('caller') === 'getWalletProperties'
? <span data-l10n-id='accountBalanceConnectionError' />
: <span>
{this.fundsAmount}
{this.walletButton}
{this.paymentHistoryButton}
</span>
}
</td>
<td>
<SettingsList>
Expand Down

0 comments on commit fffa903

Please sign in to comment.