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 acc9e1e commit cb56e03
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 @@ -621,6 +624,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 @@ -457,6 +457,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,6 +23,7 @@ export default class Home extends PureComponent {
suggestedTokens: PropTypes.object,
unconfirmedTransactionsCount: PropTypes.number,
providerRequests: PropTypes.array,
batTokenAdded: PropTypes.bool
}

componentWillMount () {
Expand All @@ -37,13 +40,18 @@ export default class Home extends PureComponent {
componentDidMount () {
const {
history,
batTokenAdded,
suggestedTokens = {},
} = this.props

// suggested new tokens
if (Object.keys(suggestedTokens).length > 0) {
history.push(CONFIRM_ADD_SUGGESTED_TOKEN_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 @@ -359,6 +359,7 @@ Routes.propTypes = {
providerId: PropTypes.string,
providerRequests: PropTypes.array,
autoLogoutTimeLimit: PropTypes.number,
batTokenAdded: PropTypes.bool
}

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

Expand Down Expand Up @@ -432,6 +434,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 @@ -360,6 +360,10 @@ var actions = {
// AppStateController-related actions
SET_LAST_ACTIVE_TIME: 'SET_LAST_ACTIVE_TIME',
setLastActiveTime,

// Brave
setBatTokenAdded,
SET_BAT_TOKEN_ADDED: 'SET_BAT_TOKEN_ADDED'
}

module.exports = actions
Expand Down Expand Up @@ -1768,6 +1772,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 @@ -2774,3 +2780,18 @@ function setLastActiveTime () {
})
}
}

// 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 cb56e03

Please sign in to comment.