This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes brave/brave-browser#4773 - adds BAT token by default to accounts
- Loading branch information
Showing
16 changed files
with
635 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const PreferencesController = require('../../../../app/scripts/controllers/preferences') | ||
|
||
module.exports = class BravePreferencesController extends PreferencesController { | ||
constructor (opts = {}) { | ||
if (opts.initState === undefined) { | ||
opts['initState'] = {} | ||
} | ||
opts.initState.batTokenAdded = false | ||
super(opts) | ||
} | ||
|
||
setBatTokenAdded () { | ||
this.store.updateState({ batTokenAdded: true }) | ||
return Promise.resolve(true) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const MetamaskController = require('../../../app/scripts/metamask-controller') | ||
const nodeify = require('../../../app/scripts/lib/nodeify') | ||
|
||
module.exports = class BraveController extends MetamaskController { | ||
constructor (opts) { | ||
super(opts) | ||
} | ||
|
||
getApi () { | ||
const api = super.getApi() | ||
api.setBatTokenAdded = nodeify(this.preferencesController.setBatTokenAdded, this.preferencesController) | ||
return api | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
const gulp = require('gulp') | ||
const replace = require('gulp-replace') | ||
|
||
/* | ||
* Brave | ||
*/ | ||
|
||
const overrideDirs = [ | ||
'ui/app/**/*', | ||
'app/scripts/**/*' | ||
] | ||
|
||
const bravePrefix = '~/brave/' | ||
|
||
/* | ||
* ToDo(ryanml) - Write a method to convert simple paths to a Regex obj | ||
* then a simple mapping can be created for these replacements. | ||
* Ex (psuedo-ish): | ||
* const replacements = [ | ||
* { | ||
* target: 'actions', | ||
* replace: 'ui/app/store/actions' | ||
* } | ||
* ] | ||
* | ||
* replacements.map((item) => { | ||
* .pipe( | ||
* replace(convertToRegex(item.target), fmtPath(item.replace)) | ||
* ) | ||
* }) | ||
*/ | ||
module.exports = function () { | ||
return gulp.src(overrideDirs) | ||
.pipe( | ||
replace( | ||
/\'(.*)\/home\'/gm, | ||
`'${bravePrefix}ui/app/pages/home'` | ||
) | ||
) | ||
.pipe( | ||
replace( | ||
/\'\.\/routes\'/gm, | ||
`'${bravePrefix}ui/app/pages/routes'` | ||
) | ||
) | ||
.pipe( | ||
replace( | ||
/\'(.*)\/actions\'/gm, | ||
`'${bravePrefix}ui/app/store/actions'` | ||
) | ||
) | ||
.pipe( | ||
replace( | ||
/\'(.*)\/preferences\'/gm, | ||
`'${bravePrefix}app/scripts/controllers/preferences'` | ||
) | ||
) | ||
.pipe( | ||
replace( | ||
/\'(.*)\/metamask-controller\'/gm, | ||
`'${bravePrefix}app/scripts/metamask-controller'` | ||
) | ||
) | ||
.pipe( | ||
replace( | ||
/\'(.*)\/metamask\/metamask\'/gm, | ||
`'${bravePrefix}ui/app/ducks/metamask/metamask'` | ||
) | ||
) | ||
.pipe( | ||
replace( | ||
/\'(.*)\/components\/menu\'/gm, | ||
`'${bravePrefix}ui/app/components/app/dropdowns/components/menu'` | ||
) | ||
) | ||
.pipe( | ||
replace( | ||
/\'(.*)\/token-menu-dropdown\.js\'/gm, | ||
`'${bravePrefix}ui/app/components/app/dropdowns/token-menu-dropdown'` | ||
) | ||
) | ||
.pipe(gulp.dest(file => file.base)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const h = require('react-hyperscript') | ||
|
||
import { Menu, Item, Divider, CloseArea } from '../../../../../../../ui/app/components/app/dropdowns/components/menu' | ||
|
||
Item.prototype.render = function () { | ||
const { | ||
icon, | ||
children, | ||
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 | ||
|
||
return children | ||
? h('div', { className: itemClassName, onClick }, children) | ||
: h('div.menu__item', { className: itemClassName, onClick }, [ iconComponent, textComponent ] | ||
.filter(d => Boolean(d)) | ||
) | ||
} | ||
|
||
module.exports = { Menu, Item, Divider, CloseArea } |
74 changes: 74 additions & 0 deletions
74
brave/ui/app/components/app/dropdowns/token-menu-dropdown.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
const Component = require('react').Component | ||
const PropTypes = require('prop-types') | ||
const h = require('react-hyperscript') | ||
const inherits = require('util').inherits | ||
const connect = require('react-redux').connect | ||
const genAccountLink = require('etherscan-link').createAccountLink | ||
const { Menu, Item, CloseArea } = require('./components/menu') | ||
|
||
import actions from '../../../store/actions' | ||
|
||
function mapStateToProps(state) { | ||
return { | ||
network: state.metamask.network, | ||
} | ||
} | ||
|
||
function mapDispatchToProps(dispatch) { | ||
return { | ||
showHideTokenConfirmationModal: (token) => { | ||
dispatch(actions.showModal({ | ||
name: 'HIDE_TOKEN_CONFIRMATION', | ||
token | ||
})) | ||
}, | ||
} | ||
} | ||
|
||
BraveTokenMenuDropdown.contextTypes = { | ||
t: PropTypes.func, | ||
} | ||
|
||
inherits(BraveTokenMenuDropdown, Component) | ||
function BraveTokenMenuDropdown () { | ||
Component.call(this) | ||
|
||
this.onClose = this.onClose.bind(this) | ||
} | ||
|
||
BraveTokenMenuDropdown.prototype.onClose = function (e) { | ||
e.stopPropagation() | ||
this.props.onClose() | ||
} | ||
|
||
BraveTokenMenuDropdown.prototype.render = function() { | ||
const { showHideTokenConfirmationModal } = this.props | ||
|
||
return h(Menu, { className: 'token-menu-dropdown', isShowing: true }, [ | ||
h(CloseArea, { | ||
onClick: this.onClose, | ||
}), | ||
h(Item, { | ||
onClick: (e) => { | ||
e.stopPropagation() | ||
showHideTokenConfirmationModal(this.props.token) | ||
this.props.onClose() | ||
}, | ||
isShowing: (this.props.token.symbol !== 'BAT'), | ||
text: 'Hide Tokens', | ||
}), | ||
h(Item, { | ||
onClick: (e) => { | ||
e.stopPropagation() | ||
const url = genAccountLink(this.props.token.address, this.props.network) | ||
global.platform.openWindow({ | ||
url | ||
}) | ||
this.props.onClose() | ||
}, | ||
text: 'View on Etherscan', | ||
}), | ||
]) | ||
} | ||
|
||
module.exports = connect(mapStateToProps, mapDispatchToProps)(BraveTokenMenuDropdown) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const reduceMetamask = require('../../../../../ui/app/ducks/metamask/metamask') | ||
|
||
module.exports = function (state, action) { | ||
const newState = reduceMetamask(state, action) | ||
newState.batTokenAdded = newState.batTokenAdded || false | ||
|
||
if (action.type === 'SET_BAT_TOKEN_ADDED') { | ||
newState.batTokenAdded = action.value | ||
} | ||
|
||
return newState | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import Home from '../../../../../ui/app/pages/home/home.component' | ||
import PropTypes from 'prop-types' | ||
import actions from '../../store/actions' | ||
import batToken from '../../store/bat-token' | ||
|
||
const BraveHome = class BraveHome extends Home { | ||
constructor (props) { | ||
super(props) | ||
} | ||
|
||
componentDidMount () { | ||
super.componentDidMount() | ||
|
||
const { batTokenAdded } = this.props | ||
|
||
if (!batTokenAdded) { | ||
this.props.dispatch(actions.addTokens(batToken)) | ||
} | ||
} | ||
} | ||
|
||
BraveHome.propTypes.batTokenAdded = PropTypes.bool | ||
|
||
module.exports = BraveHome |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import Home from './home.component' | ||
import { compose } from 'recompose' | ||
import { connect } from 'react-redux' | ||
import { withRouter } from 'react-router-dom' | ||
import { unconfirmedTransactionsCountSelector } from '../../../../../ui/app/selectors/confirm-transaction' | ||
|
||
const mapStateToProps = state => { | ||
const { metamask, appState } = state | ||
const { | ||
lostAccounts, | ||
seedWords, | ||
suggestedTokens, | ||
providerRequests, | ||
batTokenAdded | ||
} = metamask | ||
const { forgottenPassword } = appState | ||
|
||
return { | ||
lostAccounts, | ||
forgottenPassword, | ||
seedWords, | ||
suggestedTokens, | ||
unconfirmedTransactionsCount: unconfirmedTransactionsCountSelector(state), | ||
providerRequests, | ||
batTokenAdded | ||
} | ||
} | ||
|
||
export default compose( | ||
withRouter, | ||
connect(mapStateToProps) | ||
)(Home) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './home.container' |
Oops, something went wrong.