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

Commit

Permalink
Merge pull request #3470 from brave/additional-optional-ledger-logging
Browse files Browse the repository at this point in the history
updateLedgerInfo should run before client is assigned if previous state is present
  • Loading branch information
bbondy authored Aug 27, 2016
2 parents fc84905 + 060c3c3 commit 1ea3954
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions app/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const session = electron.session

const acorn = require('acorn')
const ledgerBalance = require('ledger-balance')
const ledgerClient = require('ledger-client')
const ledgerPublisher = require('ledger-publisher')
const qr = require('qr-image')
const random = require('random-lib')
Expand Down Expand Up @@ -115,6 +116,9 @@ const doAction = (action) => {
*/
var init = () => {
try {
ledgerInfo._internal.debugP = ledgerClient.prototype.boolion(process.env.LEDGER_INFO_DEBUG)
publisherInfo._internal.debugP = ledgerClient.prototype.boolion(process.env.LEDGER_PUBLISHER_DEBUG)

appDispatcher.register(doAction)
initialize(getSetting(settings.PAYMENTS_ENABLED))
} catch (ex) { console.log('initialization failed: ' + ex.toString() + '\n' + ex.stack) }
Expand All @@ -136,7 +140,7 @@ var boot = () => {
ledgerInfo.creating = true
appActions.updateLedgerInfo({ creating: true })
try {
client = (require('ledger-client'))(null, underscore.extend({ roundtrip: roundtrip }, clientOptions), null)
client = ledgerClient(null, underscore.extend({ roundtrip: roundtrip }, clientOptions), null)
} catch (ex) {
appActions.updateLedgerInfo({})

Expand Down Expand Up @@ -351,7 +355,7 @@ var initialize = (onoff) => {

getStateInfo(state)
try {
client = (require('ledger-client'))(state.personaId,
client = ledgerClient(state.personaId,
underscore.extend(state.options, { roundtrip: roundtrip }, clientOptions), state)
} catch (ex) {
return console.log('ledger client creation error: ' + ex.toString() + '\n' + ex.stack)
Expand Down Expand Up @@ -466,7 +470,7 @@ var updatePublisherInfo = () => {
syncWriter(synopsisPath, synopsis, () => {})
publisherInfo.synopsis = synopsisNormalizer()

if (clientOptions.debugP) {
if (publisherInfo._internal.debugP) {
console.log('\nupdatePublisherInfo: ' + JSON.stringify(underscore.omit(publisherInfo, [ '_internal' ])))
}

Expand Down Expand Up @@ -732,16 +736,14 @@ var updateLedgerInfo = () => {
var info = ledgerInfo._internal.paymentInfo
var now = underscore.now()

if (!client) return

if (info) {
underscore.extend(ledgerInfo,
underscore.pick(info, [ 'address', 'balance', 'unconfirmed', 'satoshis', 'btc', 'amount', 'currency' ]))
if ((!info.buyURLExpires) || (info.buyURLExpires > now)) ledgerInfo.buyURL = info.buyURL
underscore.extend(ledgerInfo, ledgerInfo._internal.cache || {})
}

if (clientOptions.debugP) {
if (ledgerInfo._internal.debugP) {
console.log('\nupdateLedgerInfo: ' + JSON.stringify(underscore.omit(ledgerInfo, [ '_internal' ]), null, 2))
}

Expand Down Expand Up @@ -826,6 +828,7 @@ var roundtrip = (params, options, callback) => {
var payload

if ((response) && (options.verboseP)) {
console.log('[ response for ' + params.method + ' ' + parts.protocol + '//' + parts.hostname + params.path + ' ]')
console.log('>>> HTTP/' + response.httpVersionMajor + '.' + response.httpVersionMinor + ' ' + response.statusCode +
' ' + (response.statusMessage || ''))
underscore.keys(response.headers).forEach((header) => { console.log('>>> ' + header + ': ' + response.headers[header]) })
Expand Down Expand Up @@ -959,7 +962,7 @@ var getBalance = () => {
setTimeout(getBalance, msecs.minute)
if (!ledgerInfo.address) return

ledgerBalance.getBalance(ledgerInfo.address, underscore.extend({ balancesP: true, roundtrip: roundtrip }, clientOptions),
ledgerBalance.getBalance(ledgerInfo.address, underscore.extend({ balancesP: true }, client.options),
(err, provider, result) => {
if (err) return console.log('ledger balance error: ' + JSON.stringify(err, null, 2))

Expand Down

0 comments on commit 1ea3954

Please sign in to comment.