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

Commit

Permalink
Simplify bitcoin protocol handler check
Browse files Browse the repository at this point in the history
Auditors: @bbondy, @mrose17
  • Loading branch information
diracdeltas committed Aug 24, 2016
1 parent 7013381 commit bbc4d90
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 40 deletions.
6 changes: 0 additions & 6 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,12 +501,6 @@ app.on('ready', () => {
downloadActions.openDownloadPath(Immutable.fromJS(download))
})

ipcMain.on(messages.CHECK_BITCOIN_HANDLER, () => {
electron.protocol.isProtocolHandled('bitcoin', (handled) => {
appActions.setBitcoinHandled(handled)
})
})

ipcMain.on(messages.CERT_ERROR_ACCEPTED, (event, url) => {
try {
let host = urlParse(url).host
Expand Down
13 changes: 9 additions & 4 deletions app/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ var boot = () => {
*/

if (ipc) {
ipc.on(messages.CHECK_BITCOIN_HANDLER, () => {
if (typeof protocolHandler.isNavigatorProtocolHandled === 'function') {
ledgerInfo.hasBitcoinHandler = protocolHandler.isNavigatorProtocolHandled('', 'bitcoin')
appActions.updateLedgerInfo(underscore.omit(ledgerInfo, [ '_internal' ]))
}
})

ipc.on(messages.LEDGER_PUBLISHER, (event, location) => {
var ctx

Expand Down Expand Up @@ -695,6 +702,8 @@ var ledgerInfo = {
buyURL: undefined,
bravery: undefined,

hasBitcoinHandler: false,

_internal: {}
}

Expand All @@ -709,10 +718,6 @@ var updateLedgerInfo = () => {
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 (typeof protocolHandler.isNavigatorProtocolHandled === 'function') {
if (!protocolHandler.isNavigatorProtocolHandled('', 'bitcoin')) delete ledgerInfo.paymentURL
}
}

if (clientOptions.debugP) {
Expand Down
10 changes: 0 additions & 10 deletions docs/appActions.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,16 +322,6 @@ Clears the data specified in dataDetail



### setBitcoinHandled()

Sets whether the bitcoin protocol is handled.

**Parameters**

**setBitcoinHandled**: `boolean`, Sets whether the bitcoin protocol is handled.



### addAutofillAddress(detail, originalDetail)

Add address data
Expand Down
4 changes: 2 additions & 2 deletions docs/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,8 @@ WindowStore
currency: string,
amount: number
}
}
},
hasBitcoinHandler: boolean, // Whether Brave has a bitcoin: protocol handler
},
publisherInfo: {
synopsis: {
Expand All @@ -420,7 +421,6 @@ WindowStore
score: ?
}
},
hasBitcoinHandler: boolean, // Whether Brave has a bitcoin: protocol handler
autofillAddressDetail: {
name: string,
organization: string,
Expand Down
2 changes: 1 addition & 1 deletion js/about/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ class BitcoinDashboard extends ImmutableComponent {
</a>
<div data-l10n-id='bitcoinAddress' className='labelText' />
<span className='fa fa-clipboard settingsListCopy alt' title='Copy to clipboard' onClick={this.copyToClipboard.bind(this, this.ledgerData.get('address'))} />
<span>{this.ledgerData.get('address')}</span>
<span className='smallText'>{this.ledgerData.get('address')}</span>
</div>
: <div>
<div data-l10n-id='bitcoinPaymentURL' className='labelText' />
Expand Down
11 changes: 0 additions & 11 deletions js/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,17 +369,6 @@ const appActions = {
})
},

/**
* Sets whether the bitcoin protocol is handled.
* @param {boolean}
*/
setBitcoinHandled: function (handled) {
AppDispatcher.dispatch({
actionType: AppConstants.APP_SET_BITCOIN_HANDLED,
handled
})
},

/**
* Add address data
* @param {object} detail - the address to add as per doc/state.md's autofillAddressDetail
Expand Down
1 change: 0 additions & 1 deletion js/components/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ class Frame extends ImmutableComponent {
if (location === 'about:preferences') {
ipc.send(messages.CHECK_BITCOIN_HANDLER)
const ledgerData = this.props.ledgerInfo.merge(this.props.publisherInfo).toJS()
ledgerData.hasBitcoinHandler = this.props.hasBitcoinHandler
this.webview.send(messages.LEDGER_UPDATED, ledgerData)
this.webview.send(messages.SETTINGS_UPDATED, this.props.settings ? this.props.settings.toJS() : null)
this.webview.send(messages.SITE_SETTINGS_UPDATED, this.props.allSiteSettings ? this.props.allSiteSettings.toJS() : null)
Expand Down
1 change: 0 additions & 1 deletion js/components/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,6 @@ class Main extends ImmutableComponent {
flash={this.props.appState.get('flash')}
cookieblock={this.props.appState.get('cookieblock')}
flashInitialized={this.props.appState.get('flashInitialized')}
hasBitcoinHandler={this.props.appState.get('hasBitcoinHandler')}
allSiteSettings={allSiteSettings}
ledgerInfo={this.props.appState.get('ledgerInfo') || new Immutable.Map()}
publisherInfo={this.props.appState.get('publisherInfo') || new Immutable.Map()}
Expand Down
1 change: 0 additions & 1 deletion js/constants/appConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const AppConstants = {
APP_CLEAR_MESSAGE_BOXES: _, /** @param {string} origin */
APP_ADD_WORD: _, /** @param {string} word, @param {boolean} learn */
APP_SET_DICTIONARY: _, /** @param {string} locale */
APP_SET_BITCOIN_HANDLED: _, /** @param {boolean} handled */
APP_ADD_AUTOFILL_ADDRESS: _,
APP_REMOVE_AUTOFILL_ADDRESS: _,
APP_ADD_AUTOFILL_CREDIT_CARD: _,
Expand Down
3 changes: 0 additions & 3 deletions js/stores/appStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,9 +542,6 @@ const handleAppAction = (action) => {
Filtering.clearStorageData()
}
break
case AppConstants.APP_SET_BITCOIN_HANDLED:
appState = appState.set('hasBitcoinHandler', action.handled)
break
case AppConstants.APP_ADD_AUTOFILL_ADDRESS:
{
const Filtering = require('../../app/filtering')
Expand Down
3 changes: 3 additions & 0 deletions less/about/preferences.less
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,9 @@ table.sortableTable {
}
font-size: 0.9em;
}
.smallText {
font-size: 0.9em;
}
.settingsListTitle {
font-weight: 600;
font-size: 1em;
Expand Down

2 comments on commit bbc4d90

@mrose17
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm? ready for commit?

@diracdeltas
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrose17 this is already committed to master

Please sign in to comment.