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 3e1f025
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 10 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
27 changes: 25 additions & 2 deletions app/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,14 @@ var ledgerInfo = {

hasBitcoinHandler: false,

_internal: {}
_internal: {},

// if the last updateLedgerInfo happened concurrently with an error, this
// saves it for UI or debugging
error: null // {
// caller: function in which error was handled
// error: error object returned
// }
}

var updateLedgerInfo = () => {
Expand Down Expand Up @@ -1013,6 +1020,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 +1049,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
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 3e1f025

Please sign in to comment.