Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
Fixes brave/brave-browser#4773 - adds BAT token by default to accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanml committed Jun 11, 2019
1 parent b478847 commit 1a71d39
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/scripts/controllers/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class PreferencesController {
completedUiMigration: true,
metaMetricsId: null,
metaMetricsSendCount: 0,

// Brave
batTokenAdded: false
}, opts.initState)

this.diagnostics = opts.diagnostics
Expand Down Expand Up @@ -613,6 +616,18 @@ class PreferencesController {
return Promise.resolve(true)
}

//
// Brave
//

/**
* Sets the {@code batTokenAdded} state to {@code true}, indicating that the default addition of the BAT token has completed
*/
setBatTokenAdded () {
this.store.updateState({ batTokenAdded: true })
return Promise.resolve(true)
}

//
// PRIVATE METHODS
//
Expand Down
1 change: 1 addition & 0 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ module.exports = class MetamaskController extends EventEmitter {
completeUiMigration: nodeify(preferencesController.completeUiMigration, preferencesController),
completeOnboarding: nodeify(preferencesController.completeOnboarding, preferencesController),
addKnownMethodData: nodeify(preferencesController.addKnownMethodData, preferencesController),
setBatTokenAdded: nodeify(preferencesController.setBatTokenAdded, preferencesController),

// BlacklistController
whitelistPhishingDomain: this.whitelistPhishingDomain.bind(this),
Expand Down
6 changes: 6 additions & 0 deletions ui/app/components/app/dropdowns/components/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ Item.prototype.render = function () {
text,
className = '',
onClick,
isShowing
} = this.props

if (isShowing === false) {
return h('noscript')
}

const itemClassName = `menu__item ${className} ${onClick ? 'menu__item--clickable' : ''}`
const iconComponent = icon ? h('div.menu__item__icon', [icon]) : null
const textComponent = text ? h('div.menu__item__text', text) : null
Expand Down
1 change: 1 addition & 0 deletions ui/app/components/app/dropdowns/token-menu-dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ TokenMenuDropdown.prototype.render = function () {
showHideTokenConfirmationModal(this.props.token)
this.props.onClose()
},
isShowing: (this.props.token.symbol !== 'BAT'),
text: this.context.t('hideToken'),
}),
h(Item, {
Expand Down
10 changes: 10 additions & 0 deletions ui/app/ducks/metamask/metamask.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ function reduceMetamask (state, action) {
knownMethodData: {},
participateInMetaMetrics: null,
metaMetricsSendCount: 0,

// Brave
batTokenAdded: false
}, state.metamask)

switch (action.type) {
Expand Down Expand Up @@ -415,6 +418,13 @@ function reduceMetamask (state, action) {
})
}

// Brave
case actions.SET_BAT_TOKEN_ADDED: {
return extend(metamaskState, {
batTokenAdded: action.value
})
}

default:
return metamaskState

Expand Down
8 changes: 8 additions & 0 deletions ui/app/pages/home/home.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { Redirect } from 'react-router-dom'
import WalletView from '../../components/app/wallet-view'
import TransactionView from '../../components/app/transaction-view'
import ProviderApproval from '../provider-approval'
import actions from '../../store/actions'
import batToken from '../../store/brave/bat-token'

import {
INITIALIZE_SEED_PHRASE_ROUTE,
Expand All @@ -21,11 +23,13 @@ export default class Home extends PureComponent {
suggestedTokens: PropTypes.object,
unconfirmedTransactionsCount: PropTypes.number,
providerRequests: PropTypes.array,
batTokenAdded: PropTypes.bool
}

componentDidMount () {
const {
history,
batTokenAdded,
suggestedTokens = {},
unconfirmedTransactionsCount = 0,
} = this.props
Expand All @@ -38,6 +42,10 @@ export default class Home extends PureComponent {
if (unconfirmedTransactionsCount > 0) {
history.push(CONFIRM_TRANSACTION_ROUTE)
}

if (!batTokenAdded) {
this.props.dispatch(actions.addTokens(batToken))
}
}

render () {
Expand Down
2 changes: 2 additions & 0 deletions ui/app/pages/home/home.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const mapStateToProps = state => {
seedWords,
suggestedTokens,
providerRequests,
batTokenAdded
} = metamask
const { forgottenPassword } = appState

Expand All @@ -21,6 +22,7 @@ const mapStateToProps = state => {
suggestedTokens,
unconfirmedTransactionsCount: unconfirmedTransactionsCountSelector(state),
providerRequests,
batTokenAdded
}
}

Expand Down
3 changes: 3 additions & 0 deletions ui/app/pages/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ Routes.propTypes = {
t: PropTypes.func,
providerId: PropTypes.string,
providerRequests: PropTypes.array,
batTokenAdded: PropTypes.bool
}

function mapStateToProps (state) {
Expand Down Expand Up @@ -371,6 +372,7 @@ function mapStateToProps (state) {
unapprovedPersonalMsgCount,
unapprovedTypedMessagesCount,
providerRequests,
batTokenAdded
} = metamask
const selected = address || Object.keys(accounts)[0]

Expand Down Expand Up @@ -415,6 +417,7 @@ function mapStateToProps (state) {
selected,
keyrings,
providerRequests,
batTokenAdded
}
}

Expand Down
21 changes: 21 additions & 0 deletions ui/app/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ var actions = {

setFirstTimeFlowType,
SET_FIRST_TIME_FLOW_TYPE: 'SET_FIRST_TIME_FLOW_TYPE',

// Brave
setBatTokenAdded,
SET_BAT_TOKEN_ADDED: 'SET_BAT_TOKEN_ADDED'
}

module.exports = actions
Expand Down Expand Up @@ -1758,6 +1762,8 @@ function addToken (address, symbol, decimals, image) {
if (err) {
dispatch(actions.displayWarning(err.message))
reject(err)
} else if (symbol === 'BAT') {
dispatch(actions.setBatTokenAdded())
}
dispatch(actions.updateTokens(tokens))
resolve(tokens)
Expand Down Expand Up @@ -2712,3 +2718,18 @@ function setFirstTimeFlowType (type) {
})
}
}

// Brave
function setBatTokenAdded () {
return (dispatch) => {
background.setBatTokenAdded((err) => {
if (err) {
return dispatch(actions.displayWarning(err.message))
}
})
dispatch({
type: actions.SET_BAT_TOKEN_ADDED,
value: true
})
}
}
10 changes: 10 additions & 0 deletions ui/app/store/brave/bat-token.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
'0x0D8775F648430679A709E98d2b0Cb6250d2887EF': {
'name': 'Basic Attention Token',
'logo': 'BAT_icon.svg',
'erc20': true,
'symbol': 'BAT',
'decimals': 18,
'address' :'0x0D8775F648430679A709E98d2b0Cb6250d2887EF'
}
}

0 comments on commit 1a71d39

Please sign in to comment.