mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Implement tokens list UI
This commit is contained in:
parent
562d2fadae
commit
06b2a04a42
@ -18,9 +18,11 @@ function IdenticonComponent () {
|
|||||||
|
|
||||||
IdenticonComponent.prototype.render = function () {
|
IdenticonComponent.prototype.render = function () {
|
||||||
var props = this.props
|
var props = this.props
|
||||||
|
const { className = '' } = props
|
||||||
var diameter = props.diameter || this.defaultDiameter
|
var diameter = props.diameter || this.defaultDiameter
|
||||||
return (
|
return (
|
||||||
h('div.identicon', {
|
h('div', {
|
||||||
|
className: `${className} identicon`,
|
||||||
key: 'identicon-' + this.props.address,
|
key: 'identicon-' + this.props.address,
|
||||||
style: {
|
style: {
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
|
@ -13,23 +13,34 @@ function TokenCell () {
|
|||||||
|
|
||||||
TokenCell.prototype.render = function () {
|
TokenCell.prototype.render = function () {
|
||||||
const props = this.props
|
const props = this.props
|
||||||
const { address, symbol, string, network, userAddress } = props
|
const {
|
||||||
|
address,
|
||||||
|
symbol,
|
||||||
|
string,
|
||||||
|
network,
|
||||||
|
// userAddress,
|
||||||
|
} = props
|
||||||
|
|
||||||
return (
|
return (
|
||||||
h('li.token-cell', {
|
h('div.token-list-item', {
|
||||||
style: { cursor: network === '1' ? 'pointer' : 'default' },
|
style: { cursor: network === '1' ? 'pointer' : 'default' },
|
||||||
onClick: this.view.bind(this, address, userAddress, network),
|
// onClick: this.view.bind(this, address, userAddress, network),
|
||||||
}, [
|
}, [
|
||||||
|
|
||||||
h(Identicon, {
|
h(Identicon, {
|
||||||
diameter: 50,
|
className: 'token-list-item__identicon',
|
||||||
|
diameter: 45,
|
||||||
address,
|
address,
|
||||||
network,
|
network,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
h('h3', `${string || 0} ${symbol}`),
|
h('h.token-list-item__balance-wrapper', null, [
|
||||||
|
h('h3.token-list-item__token-balance', `${string || 0} ${symbol}`),
|
||||||
|
|
||||||
h('span', { style: { flex: '1 0 auto' } }),
|
h('div.token-list-item__fiat-amount', {
|
||||||
|
style: {},
|
||||||
|
}, '210 FPO'),
|
||||||
|
]),
|
||||||
|
|
||||||
/*
|
/*
|
||||||
h('button', {
|
h('button', {
|
||||||
|
@ -4,6 +4,17 @@ const inherits = require('util').inherits
|
|||||||
const TokenTracker = require('eth-token-tracker')
|
const TokenTracker = require('eth-token-tracker')
|
||||||
const TokenCell = require('./token-cell.js')
|
const TokenCell = require('./token-cell.js')
|
||||||
const normalizeAddress = require('eth-sig-util').normalize
|
const normalizeAddress = require('eth-sig-util').normalize
|
||||||
|
const connect = require('react-redux').connect
|
||||||
|
const selectors = require('../selectors')
|
||||||
|
|
||||||
|
function mapStateToProps (state) {
|
||||||
|
|
||||||
|
return {
|
||||||
|
network: state.metamask.network,
|
||||||
|
tokens: state.metamask.tokens,
|
||||||
|
userAddress: selectors.getSelectedAddress(state),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const defaultTokens = []
|
const defaultTokens = []
|
||||||
const contracts = require('eth-contract-metadata')
|
const contracts = require('eth-contract-metadata')
|
||||||
@ -15,7 +26,8 @@ for (const address in contracts) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = TokenList
|
module.exports = connect(mapStateToProps)(TokenList)
|
||||||
|
|
||||||
|
|
||||||
inherits(TokenList, Component)
|
inherits(TokenList, Component)
|
||||||
function TokenList () {
|
function TokenList () {
|
||||||
@ -47,81 +59,7 @@ TokenList.prototype.render = function () {
|
|||||||
return h(TokenCell, tokenData)
|
return h(TokenCell, tokenData)
|
||||||
})
|
})
|
||||||
|
|
||||||
return h('.full-flex-height', [
|
return h('div', tokenViews)
|
||||||
this.renderTokenStatusBar(),
|
|
||||||
|
|
||||||
h('ol.full-flex-height.flex-column', {
|
|
||||||
style: {
|
|
||||||
overflowY: 'auto',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
},
|
|
||||||
}, [
|
|
||||||
h('style', `
|
|
||||||
|
|
||||||
li.token-cell {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
align-items: center;
|
|
||||||
padding: 10px;
|
|
||||||
min-height: 50px;
|
|
||||||
}
|
|
||||||
|
|
||||||
li.token-cell > h3 {
|
|
||||||
margin-left: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
li.token-cell:hover {
|
|
||||||
background: white;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
`),
|
|
||||||
...tokenViews,
|
|
||||||
h('.flex-grow'),
|
|
||||||
]),
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
TokenList.prototype.renderTokenStatusBar = function () {
|
|
||||||
const { tokens } = this.state
|
|
||||||
|
|
||||||
let msg
|
|
||||||
if (tokens.length === 1) {
|
|
||||||
msg = `You own 1 token`
|
|
||||||
} else if (tokens.length === 1) {
|
|
||||||
msg = `You own ${tokens.length} tokens`
|
|
||||||
} else {
|
|
||||||
msg = `No tokens found`
|
|
||||||
}
|
|
||||||
|
|
||||||
return h('div', {
|
|
||||||
style: {
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'space-between',
|
|
||||||
alignItems: 'center',
|
|
||||||
minHeight: '70px',
|
|
||||||
padding: '10px',
|
|
||||||
},
|
|
||||||
}, [
|
|
||||||
h('span', msg),
|
|
||||||
h('button', {
|
|
||||||
key: 'reveal-account-bar',
|
|
||||||
onClick: (event) => {
|
|
||||||
event.preventDefault()
|
|
||||||
this.props.addToken()
|
|
||||||
},
|
|
||||||
style: {
|
|
||||||
display: 'flex',
|
|
||||||
height: '40px',
|
|
||||||
padding: '10px',
|
|
||||||
justifyContent: 'center',
|
|
||||||
alignItems: 'center',
|
|
||||||
},
|
|
||||||
}, [
|
|
||||||
'ADD TOKEN',
|
|
||||||
]),
|
|
||||||
])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TokenList.prototype.message = function (body) {
|
TokenList.prototype.message = function (body) {
|
||||||
@ -150,6 +88,7 @@ TokenList.prototype.createFreshTokenTracker = function () {
|
|||||||
|
|
||||||
if (!global.ethereumProvider) return
|
if (!global.ethereumProvider) return
|
||||||
const { userAddress } = this.props
|
const { userAddress } = this.props
|
||||||
|
|
||||||
this.tracker = new TokenTracker({
|
this.tracker = new TokenTracker({
|
||||||
userAddress,
|
userAddress,
|
||||||
provider: global.ethereumProvider,
|
provider: global.ethereumProvider,
|
||||||
@ -188,10 +127,10 @@ TokenList.prototype.componentWillUpdate = function (nextProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TokenList.prototype.updateBalances = function (tokens) {
|
TokenList.prototype.updateBalances = function (tokens) {
|
||||||
const heldTokens = tokens.filter(token => {
|
// const heldTokens = tokens.filter(token => {
|
||||||
return token.balance !== '0' && token.string !== '0.000'
|
// return token.balance !== '0' && token.string !== '0.000'
|
||||||
})
|
// })
|
||||||
this.setState({ tokens: heldTokens, isLoading: false })
|
this.setState({ tokens: tokens, isLoading: false })
|
||||||
}
|
}
|
||||||
|
|
||||||
TokenList.prototype.componentWillUnmount = function () {
|
TokenList.prototype.componentWillUnmount = function () {
|
||||||
@ -199,7 +138,7 @@ TokenList.prototype.componentWillUnmount = function () {
|
|||||||
this.tracker.stop()
|
this.tracker.stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
function uniqueMergeTokens (tokensA, tokensB) {
|
function uniqueMergeTokens (tokensA, tokensB = []) {
|
||||||
const uniqueAddresses = []
|
const uniqueAddresses = []
|
||||||
const result = []
|
const result = []
|
||||||
tokensA.concat(tokensB).forEach((token) => {
|
tokensA.concat(tokensB).forEach((token) => {
|
||||||
|
@ -40,7 +40,7 @@ TxList.prototype.render = function () {
|
|||||||
}, [
|
}, [
|
||||||
|
|
||||||
h('div', {
|
h('div', {
|
||||||
style: {}
|
style: {},
|
||||||
}, 'transactions'),
|
}, 'transactions'),
|
||||||
|
|
||||||
]),
|
]),
|
||||||
@ -64,45 +64,52 @@ TxList.prototype.renderTransactionListItem = function (transaction) {
|
|||||||
transactionStatus: transaction.status,
|
transactionStatus: transaction.status,
|
||||||
transactionAmount: formatBalance(transaction.txParams.value, 6),
|
transactionAmount: formatBalance(transaction.txParams.value, 6),
|
||||||
}
|
}
|
||||||
const { address, transactionStatus, transactionAmount, dateString } = props
|
const {
|
||||||
|
address = '',
|
||||||
|
transactionStatus,
|
||||||
|
transactionAmount,
|
||||||
|
dateString,
|
||||||
|
} = props
|
||||||
|
|
||||||
return h('div', {}, [
|
return h('div', {
|
||||||
|
key: transaction.id,
|
||||||
|
}, [
|
||||||
h('div.flex-column.tx-list-item-wrapper', {
|
h('div.flex-column.tx-list-item-wrapper', {
|
||||||
style: {}
|
style: {},
|
||||||
}, [
|
}, [
|
||||||
|
|
||||||
h('div.tx-list-date-wrapper', {
|
h('div.tx-list-date-wrapper', {
|
||||||
style: {}
|
style: {},
|
||||||
}, [
|
}, [
|
||||||
h('span.tx-list-date', {}, [
|
h('span.tx-list-date', {}, [
|
||||||
dateString,
|
dateString,
|
||||||
])
|
]),
|
||||||
]),
|
]),
|
||||||
|
|
||||||
h('div.flex-row.tx-list-content-wrapper', {
|
h('div.flex-row.tx-list-content-wrapper', {
|
||||||
style: {}
|
style: {},
|
||||||
}, [
|
}, [
|
||||||
|
|
||||||
h('div.tx-list-identicon-wrapper', {
|
h('div.tx-list-identicon-wrapper', {
|
||||||
style: {}
|
style: {},
|
||||||
}, [
|
}, [
|
||||||
h(Identicon, {
|
h(Identicon, {
|
||||||
address,
|
address,
|
||||||
diameter: 28,
|
diameter: 28,
|
||||||
})
|
}),
|
||||||
]),
|
]),
|
||||||
|
|
||||||
h('div.tx-list-account-and-status-wrapper', {}, [
|
h('div.tx-list-account-and-status-wrapper', {}, [
|
||||||
h('div.tx-list-account-wrapper', {
|
h('div.tx-list-account-wrapper', {
|
||||||
style: {}
|
style: {},
|
||||||
}, [
|
}, [
|
||||||
h('span.tx-list-account', {}, [
|
h('span.tx-list-account', {}, [
|
||||||
`${address.slice(0, 10)}...${address.slice(-4)}`
|
`${address.slice(0, 10)}...${address.slice(-4)}`,
|
||||||
]),
|
]),
|
||||||
]),
|
]),
|
||||||
|
|
||||||
h('div.tx-list-status-wrapper', {
|
h('div.tx-list-status-wrapper', {
|
||||||
style: {}
|
style: {},
|
||||||
}, [
|
}, [
|
||||||
h('span.tx-list-status', {}, [
|
h('span.tx-list-status', {}, [
|
||||||
transactionStatus,
|
transactionStatus,
|
||||||
@ -111,7 +118,7 @@ TxList.prototype.renderTransactionListItem = function (transaction) {
|
|||||||
]),
|
]),
|
||||||
|
|
||||||
h('div.flex-column.tx-list-details-wrapper', {
|
h('div.flex-column.tx-list-details-wrapper', {
|
||||||
style: {}
|
style: {},
|
||||||
}, [
|
}, [
|
||||||
|
|
||||||
h('span.tx-list-value', {}, [
|
h('span.tx-list-value', {}, [
|
||||||
@ -126,7 +133,7 @@ TxList.prototype.renderTransactionListItem = function (transaction) {
|
|||||||
|
|
||||||
]),
|
]),
|
||||||
]),
|
]),
|
||||||
contentDivider
|
contentDivider,
|
||||||
|
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ const Identicon = require('./identicon')
|
|||||||
const AccountDropdowns = require('./dropdowns/index.js').AccountDropdowns
|
const AccountDropdowns = require('./dropdowns/index.js').AccountDropdowns
|
||||||
const actions = require('../actions')
|
const actions = require('../actions')
|
||||||
const BalanceComponent = require('./balance-component')
|
const BalanceComponent = require('./balance-component')
|
||||||
|
const TokenList = require('./token-list')
|
||||||
const selectors = require('../selectors')
|
const selectors = require('../selectors')
|
||||||
|
|
||||||
module.exports = connect(mapStateToProps, mapDispatchToProps)(WalletView)
|
module.exports = connect(mapStateToProps, mapDispatchToProps)(WalletView)
|
||||||
@ -17,6 +18,7 @@ function mapStateToProps (state) {
|
|||||||
sidebarOpen: state.appState.sidebarOpen,
|
sidebarOpen: state.appState.sidebarOpen,
|
||||||
identities: state.metamask.identities,
|
identities: state.metamask.identities,
|
||||||
accounts: state.metamask.accounts,
|
accounts: state.metamask.accounts,
|
||||||
|
tokens: state.metamask.tokens,
|
||||||
selectedAddress: selectors.getSelectedAddress(state),
|
selectedAddress: selectors.getSelectedAddress(state),
|
||||||
selectedIdentity: selectors.getSelectedIdentity(state),
|
selectedIdentity: selectors.getSelectedIdentity(state),
|
||||||
selectedAccount: selectors.getSelectedAccount(state),
|
selectedAccount: selectors.getSelectedAccount(state),
|
||||||
@ -35,8 +37,23 @@ function WalletView () {
|
|||||||
Component.call(this)
|
Component.call(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WalletView.prototype.renderTokenBalances = function () {
|
||||||
|
// const { tokens = [] } = this.props
|
||||||
|
// return tokens.map(({ address, decimals, symbol }) => (
|
||||||
|
// h(BalanceComponent, {
|
||||||
|
// balanceValue: 0,
|
||||||
|
// style: {},
|
||||||
|
// })
|
||||||
|
// ))
|
||||||
|
return h(TokenList)
|
||||||
|
}
|
||||||
|
|
||||||
WalletView.prototype.render = function () {
|
WalletView.prototype.render = function () {
|
||||||
const { network, responsiveDisplayClassname, identities, selectedAddress, selectedAccount, accounts, selectedIdentity } = this.props
|
const {
|
||||||
|
network, responsiveDisplayClassname, identities,
|
||||||
|
selectedAddress, selectedAccount, accounts,
|
||||||
|
selectedIdentity,
|
||||||
|
} = this.props
|
||||||
// temporary logs + fake extra wallets
|
// temporary logs + fake extra wallets
|
||||||
console.log('walletview, selectedAccount:', selectedAccount)
|
console.log('walletview, selectedAccount:', selectedAccount)
|
||||||
|
|
||||||
@ -134,8 +151,11 @@ WalletView.prototype.render = function () {
|
|||||||
|
|
||||||
]),
|
]),
|
||||||
|
|
||||||
|
|
||||||
]),
|
]),
|
||||||
|
|
||||||
|
this.renderTokenBalances(),
|
||||||
|
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,3 +23,5 @@
|
|||||||
@import './transaction-list.scss';
|
@import './transaction-list.scss';
|
||||||
|
|
||||||
@import './sections.scss';
|
@import './sections.scss';
|
||||||
|
|
||||||
|
@import './token-list.scss';
|
||||||
|
@ -6,6 +6,13 @@
|
|||||||
$tx-view-bg: $white;
|
$tx-view-bg: $white;
|
||||||
$wallet-view-bg: $wild-sand;
|
$wallet-view-bg: $wild-sand;
|
||||||
|
|
||||||
|
html {
|
||||||
|
|
||||||
|
@media screen and (max-width: 575px) {
|
||||||
|
height: 500px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Main container
|
// Main container
|
||||||
.main-container {
|
.main-container {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
@ -37,6 +44,7 @@ $wallet-view-bg: $wild-sand;
|
|||||||
|
|
||||||
@media screen and (min-width: 576px) {
|
@media screen and (min-width: 576px) {
|
||||||
overflow-y: scroll;
|
overflow-y: scroll;
|
||||||
|
overflow-x: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.wallet-view-account-details {
|
.wallet-view-account-details {
|
||||||
@ -142,7 +150,10 @@ $wallet-view-bg: $wild-sand;
|
|||||||
|
|
||||||
.main-container {
|
.main-container {
|
||||||
margin-top: 35px;
|
margin-top: 35px;
|
||||||
|
height: calc(100% - 34px);
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
overflow-y: auto;
|
||||||
|
background-color: $white;
|
||||||
}
|
}
|
||||||
|
|
||||||
button.btn-clear {
|
button.btn-clear {
|
||||||
|
21
ui/app/css/itcss/components/token-list.scss
Normal file
21
ui/app/css/itcss/components/token-list.scss
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
.token-list-item {
|
||||||
|
display: flex;
|
||||||
|
flex-flow: row nowrap;
|
||||||
|
align-items: center;
|
||||||
|
padding: 20px 24px;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
&__identicon {
|
||||||
|
margin-right: 15px;
|
||||||
|
border: '1px solid #dedede';
|
||||||
|
}
|
||||||
|
|
||||||
|
&__token-balance {
|
||||||
|
font-size: 130%;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__fiat-amount {
|
||||||
|
margin-top: .25%;
|
||||||
|
font-size: 105%;
|
||||||
|
}
|
||||||
|
}
|
@ -3,7 +3,7 @@ $wallet-balance-breakpoint: 890px;
|
|||||||
$wallet-balance-breakpoint-range: "screen and (min-width: #{$break-large}) and (max-width: #{$wallet-balance-breakpoint})";
|
$wallet-balance-breakpoint-range: "screen and (min-width: #{$break-large}) and (max-width: #{$wallet-balance-breakpoint})";
|
||||||
|
|
||||||
.wallet-balance-wrapper {
|
.wallet-balance-wrapper {
|
||||||
flex: 0 0 80px;
|
flex: 0 0 auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.wallet-balance {
|
.wallet-balance {
|
||||||
@ -12,6 +12,8 @@ $wallet-balance-breakpoint-range: "screen and (min-width: #{$break-large}) and (
|
|||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
justify-content: flex-start;
|
justify-content: flex-start;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
flex: 0 0 auto;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
.balance-container {
|
.balance-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
@ -53,7 +53,7 @@ function imageElFor (address) {
|
|||||||
const path = `images/contract/${fileName}`
|
const path = `images/contract/${fileName}`
|
||||||
const img = document.createElement('img')
|
const img = document.createElement('img')
|
||||||
img.src = path
|
img.src = path
|
||||||
img.style.width = '75%'
|
img.style.width = '100%'
|
||||||
return img
|
return img
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user