Add button to remove token

This commit is contained in:
Franco Victorio 2018-07-24 08:59:24 -03:00
parent 91c255ee23
commit 1c67b39a6d
7 changed files with 104 additions and 1 deletions

View File

@ -269,6 +269,7 @@ AccountDetailScreen.prototype.tabSwitchView = function () {
network, network,
tokens, tokens,
addToken: () => this.props.dispatch(actions.showAddTokenPage()), addToken: () => this.props.dispatch(actions.showAddTokenPage()),
removeToken: (token) => this.props.dispatch(actions.showRemoveTokenPage(token)),
}) })
default: default:
return this.transactionList() return this.transactionList()

View File

@ -22,6 +22,7 @@ const generateLostAccountsNotice = require('../lib/lost-accounts-notice')
// other views // other views
const ConfigScreen = require('./config') const ConfigScreen = require('./config')
const AddTokenScreen = require('./add-token') const AddTokenScreen = require('./add-token')
const RemoveTokenScreen = require('./remove-token')
const Import = require('./accounts/import') const Import = require('./accounts/import')
const InfoScreen = require('./info') const InfoScreen = require('./info')
const Loading = require('./components/loading') const Loading = require('./components/loading')
@ -566,6 +567,10 @@ App.prototype.renderPrimary = function () {
log.debug('rendering add-token screen from unlock screen.') log.debug('rendering add-token screen from unlock screen.')
return h(AddTokenScreen, {key: 'add-token'}) return h(AddTokenScreen, {key: 'add-token'})
case 'remove-token':
log.debug('rendering remove-token screen from unlock screen.')
return h(RemoveTokenScreen, {key: 'remove-token', ...props.currentView.context })
case 'config': case 'config':
log.debug('rendering config screen') log.debug('rendering config screen')
return h(ConfigScreen, {key: 'config'}) return h(ConfigScreen, {key: 'config'})

View File

@ -31,6 +31,14 @@ TokenCell.prototype.render = function () {
h('span', { style: { flex: '1 0 auto' } }), h('span', { style: { flex: '1 0 auto' } }),
h('span.fa.fa-trash', {
style: { cursor: 'pointer' },
onClick: (event) => {
event.stopPropagation()
this.props.removeToken({ address, symbol, string, network, userAddress })
},
}, ''),
/* /*
h('button', { h('button', {
onClick: this.send.bind(this, address), onClick: this.send.bind(this, address),

View File

@ -51,7 +51,10 @@ TokenList.prototype.render = function () {
const tokenViews = tokens.map((tokenData) => { const tokenViews = tokens.map((tokenData) => {
tokenData.network = network tokenData.network = network
tokenData.userAddress = userAddress tokenData.userAddress = userAddress
return h(TokenCell, tokenData) return h(TokenCell, {
...tokenData,
removeToken: this.props.removeToken,
})
}) })
return h('.full-flex-height', [ return h('.full-flex-height', [

View File

@ -0,0 +1,67 @@
const inherits = require('util').inherits
const Component = require('react').Component
const h = require('react-hyperscript')
const connect = require('react-redux').connect
const actions = require('../../ui/app/actions')
module.exports = connect(mapStateToProps)(RemoveTokenScreen)
function mapStateToProps (state) {
return {}
}
inherits(RemoveTokenScreen, Component)
function RemoveTokenScreen () {
this.state = {}
Component.call(this)
}
RemoveTokenScreen.prototype.render = function () {
const props = this.props
const warning = `Are you sure you want to remove token "${props.symbol}"?`
return (
h('.flex-column.flex-grow', [
// subtitle and nav
h('.section-title.flex-row.flex-center', [
h('i.fa.fa-arrow-left.fa-lg.cursor-pointer', {
onClick: (event) => {
props.dispatch(actions.goHome())
},
}),
h('h2.page-subtitle', 'Remove Token'),
]),
h('div', {
style: {
display: 'inline-block',
textAlign: 'center',
},
}, [
h('p.error', warning),
]),
h('.flex-column.flex-justify-center.flex-grow.select-none', [
h('.flex-space-around', {
style: {
padding: '20px',
},
}, [
h('button', {
style: {
alignSelf: 'center',
},
onClick: (event) => {
this.props.dispatch(actions.removeToken(props.address))
.then(() => {
this.props.dispatch(actions.goHome())
})
},
}, 'Remove'),
]),
]),
])
)
}

View File

@ -209,7 +209,9 @@ var actions = {
SET_PROVIDER_TYPE: 'SET_PROVIDER_TYPE', SET_PROVIDER_TYPE: 'SET_PROVIDER_TYPE',
showConfigPage, showConfigPage,
SHOW_ADD_TOKEN_PAGE: 'SHOW_ADD_TOKEN_PAGE', SHOW_ADD_TOKEN_PAGE: 'SHOW_ADD_TOKEN_PAGE',
SHOW_REMOVE_TOKEN_PAGE: 'SHOW_REMOVE_TOKEN_PAGE',
showAddTokenPage, showAddTokenPage,
showRemoveTokenPage,
addToken, addToken,
addTokens, addTokens,
removeToken, removeToken,
@ -1391,6 +1393,14 @@ function showAddTokenPage (transitionForward = true) {
} }
} }
function showRemoveTokenPage (token, transitionForward = true) {
return {
type: actions.SHOW_REMOVE_TOKEN_PAGE,
value: transitionForward,
token,
}
}
function addToken (address, symbol, decimals) { function addToken (address, symbol, decimals) {
return (dispatch) => { return (dispatch) => {
dispatch(actions.showLoadingIndication()) dispatch(actions.showLoadingIndication())

View File

@ -181,6 +181,15 @@ function reduceApp (state, action) {
transForward: action.value, transForward: action.value,
}) })
case actions.SHOW_REMOVE_TOKEN_PAGE:
return extend(appState, {
currentView: {
name: 'remove-token',
context: action.token,
},
transForward: action.value,
})
case actions.SHOW_IMPORT_PAGE: case actions.SHOW_IMPORT_PAGE:
return extend(appState, { return extend(appState, {
currentView: { currentView: {