From 1f1549904650af2e5502d2d4781a555386dfd084 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 22 Dec 2016 17:17:20 -0800 Subject: Show a "LOOSE" warning on accounts not belonging to HD Seed phrase --- ui/app/accounts/account-list-item.js | 18 ++++++++++++++---- ui/app/accounts/index.js | 14 +++++++++++--- ui/app/css/lib.css | 17 +++++++++++++++++ 3 files changed, 42 insertions(+), 7 deletions(-) (limited to 'ui/app') diff --git a/ui/app/accounts/account-list-item.js b/ui/app/accounts/account-list-item.js index ef7b749e4..624e34581 100644 --- a/ui/app/accounts/account-list-item.js +++ b/ui/app/accounts/account-list-item.js @@ -15,19 +15,21 @@ function AccountListItem () { } AccountListItem.prototype.render = function () { - const identity = this.props.identity - var isSelected = this.props.selectedAccount === identity.address - var account = this.props.accounts[identity.address] + const { identity, selectedAccount, accounts, onShowDetail } = this.props + + const isSelected = selectedAccount === identity.address + const account = accounts[identity.address] const selectedClass = isSelected ? '.selected' : '' return ( h(`.accounts-list-option.flex-row.flex-space-between.pointer.hover-white${selectedClass}`, { key: `account-panel-${identity.address}`, - onClick: (event) => this.props.onShowDetail(identity.address, event), + onClick: (event) => onShowDetail(identity.address, event), }, [ h('.identicon-wrapper.flex-column.flex-center.select-none', [ this.pendingOrNot(), + this.indicateIfLoose(), h(Identicon, { address: identity.address, imageify: true, @@ -70,6 +72,14 @@ AccountListItem.prototype.render = function () { ) } +AccountListItem.prototype.indicateIfLoose = function () { + try { // Sometimes keyrings aren't loaded yet: + const type = this.props.keyring.type + const isLoose = type !== 'HD Key Tree' + return isLoose ? h('.pending-dot', 'LOOSE') : null + } catch (e) { return } +} + AccountListItem.prototype.pendingOrNot = function () { const pending = this.props.pending if (pending.length === 0) return null diff --git a/ui/app/accounts/index.js b/ui/app/accounts/index.js index fcb3a7b0f..edb15eafe 100644 --- a/ui/app/accounts/index.js +++ b/ui/app/accounts/index.js @@ -22,6 +22,7 @@ function mapStateToProps (state) { selectedAccount: state.metamask.selectedAccount, scrollToBottom: state.appState.scrollToBottom, pending, + keyrings: state.metamask.keyrings, } } @@ -31,9 +32,10 @@ function AccountsScreen () { } AccountsScreen.prototype.render = function () { - var state = this.props - var identityList = valuesFor(state.identities) - var unconfTxList = valuesFor(state.unconfTxs) + const props = this.props + const { keyrings } = props + const identityList = valuesFor(props.identities) + const unconfTxList = valuesFor(props.unconfTxs) return ( @@ -69,6 +71,11 @@ AccountsScreen.prototype.render = function () { } }) + const simpleAddress = identity.address.substring(2).toLowerCase() + const keyring = keyrings.find((kr) => { + return kr.accounts.includes(simpleAddress) + }) + return h(AccountListItem, { key: `acct-panel-${identity.address}`, identity, @@ -76,6 +83,7 @@ AccountsScreen.prototype.render = function () { accounts: this.props.accounts, onShowDetail: this.onShowDetail.bind(this), pending, + keyring, }) }), diff --git a/ui/app/css/lib.css b/ui/app/css/lib.css index f5f602729..abbf8667e 100644 --- a/ui/app/css/lib.css +++ b/ui/app/css/lib.css @@ -196,6 +196,23 @@ hr.horizontal-line { align-items: center; justify-content: center; padding: 4px; + z-index: 1; +} + +.keyring-label { + z-index: 1; + font-size: 11px; + background: rgba(255,0,0,0.8); + bottom: -47px; + color: white; + border-radius: 10px; + height: 20px; + min-width: 20px; + position: relative; + display: flex; + align-items: center; + justify-content: center; + padding: 4px; } .ether-balance { -- cgit From c05e04c611f44ff8bef2f1d617cb79d2a5157f2a Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Fri, 23 Dec 2016 17:22:46 -0800 Subject: Fix rendering of loose accounts --- ui/app/accounts/account-list-item.js | 4 ++-- ui/app/components/eth-balance.js | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'ui/app') diff --git a/ui/app/accounts/account-list-item.js b/ui/app/accounts/account-list-item.js index 624e34581..16019c88a 100644 --- a/ui/app/accounts/account-list-item.js +++ b/ui/app/accounts/account-list-item.js @@ -50,7 +50,7 @@ AccountListItem.prototype.render = function () { }, }, ethUtil.toChecksumAddress(identity.address)), h(EthBalance, { - value: account.balance, + value: account && account.balance, style: { lineHeight: '7px', marginTop: '10px', @@ -76,7 +76,7 @@ AccountListItem.prototype.indicateIfLoose = function () { try { // Sometimes keyrings aren't loaded yet: const type = this.props.keyring.type const isLoose = type !== 'HD Key Tree' - return isLoose ? h('.pending-dot', 'LOOSE') : null + return isLoose ? h('.keyring-label', 'LOOSE') : null } catch (e) { return } } diff --git a/ui/app/components/eth-balance.js b/ui/app/components/eth-balance.js index 46127bed5..57ca84564 100644 --- a/ui/app/components/eth-balance.js +++ b/ui/app/components/eth-balance.js @@ -15,9 +15,10 @@ function EthBalanceComponent () { EthBalanceComponent.prototype.render = function () { var props = this.props + let { value } = props var style = props.style var needsParse = this.props.needsParse !== undefined ? this.props.needsParse : true - const value = formatBalance(props.value, 6, needsParse) + value = value ? formatBalance(value, 6, needsParse) : '...' var width = props.width return ( @@ -38,6 +39,7 @@ EthBalanceComponent.prototype.render = function () { EthBalanceComponent.prototype.renderBalance = function (value) { var props = this.props if (value === 'None') return value + if (value === '...') return value var balanceObj = generateBalanceObject(value, props.shorten ? 1 : 3) var balance var splitBalance = value.split(' ') -- cgit From 3ebf029c04b15599f571a19524474df9680efa7d Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 3 Jan 2017 10:39:34 -0800 Subject: Update account list after adding account Fixed by finally making a function generator for a pattern we use frequently, communicating to the background process. Fixes #961 --- ui/app/actions.js | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'ui/app') diff --git a/ui/app/actions.js b/ui/app/actions.js index 606460314..018baff73 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -153,7 +153,7 @@ var actions = { SHOW_NEW_KEYCHAIN: 'SHOW_NEW_KEYCHAIN', showNewKeychain: showNewKeychain, - + callBackgroundThenUpdate, } module.exports = actions @@ -269,15 +269,7 @@ function addNewKeyring (type, opts) { } function addNewAccount (ringNumber = 0) { - return (dispatch) => { - dispatch(actions.showLoadingIndication()) - background.addNewAccount(ringNumber, (err) => { - dispatch(this.hideLoadingIndication()) - if (err) { - return dispatch(actions.showWarning(err)) - } - }) - } + return callBackgroundThenUpdate(background.addNewAccount, ringNumber) } function showInfoPage () { @@ -476,6 +468,7 @@ function updateMetamaskState (newState) { function lockMetamask () { return (dispatch) => { + dispatch(actions.showLoadingIndication()) background.setLocked((err, newState) => { dispatch(actions.hideLoadingIndication()) if (err) { @@ -857,3 +850,24 @@ function shapeShiftRequest (query, options, cb) { return shapShiftReq.send() } } + +// Call Background Then Update +// +// A function generator for a common pattern wherein: +// We show loading indication. +// We call a background method. +// We hide loading indication. +// If it errored, we show a warning. +// If it didn't, we update the state. +function callBackgroundThenUpdate (method, ...args) { + return (dispatch) => { + dispatch(actions.showLoadingIndication()) + method.call(background, ...args, (err, newState) => { + dispatch(actions.hideLoadingIndication()) + if (err) { + return dispatch(actions.displayWarning(err.message)) + } + dispatch(actions.updateMetamaskState(newState)) + }) + } +} -- cgit From 8b7b097034f274631917b2df8617c24feb09f69c Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 3 Jan 2017 10:42:09 -0800 Subject: Apply new pattern to repetitive functions --- ui/app/actions.js | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) (limited to 'ui/app') diff --git a/ui/app/actions.js b/ui/app/actions.js index 018baff73..bc9b4a092 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -231,7 +231,6 @@ function createNewVaultAndKeychain (password) { if (err) { return dispatch(actions.showWarning(err.message)) } - dispatch(actions.updateMetamaskState(newState)) }) } } @@ -467,16 +466,7 @@ function updateMetamaskState (newState) { } function lockMetamask () { - return (dispatch) => { - dispatch(actions.showLoadingIndication()) - background.setLocked((err, newState) => { - dispatch(actions.hideLoadingIndication()) - if (err) { - return dispatch(actions.displayWarning(err.message)) - } - dispatch(actions.updateMetamaskState(newState)) - }) - } + return callBackgroundThenUpdate(background.setLocked) } function showAccountDetail (address) { @@ -586,14 +576,7 @@ function clearNotices () { } function markAccountsFound() { - return (dispatch) => { - dispatch(this.showLoadingIndication()) - background.markAccountsFound((err, newState) => { - dispatch(this.hideLoadingIndication()) - if (err) return dispatch(this.showWarning(err.message)) - dispatch(actions.updateMetamaskState(newState)) - }) - } + return callBackgroundThenUpdate(background.markAccountsFound) } // -- cgit From 013e6a608f55c7a81e17a171d681cb21e041c9d9 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 3 Jan 2017 11:03:25 -0800 Subject: Corrected instances of showWarning to displayWarning --- ui/app/actions.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ui/app') diff --git a/ui/app/actions.js b/ui/app/actions.js index bc9b4a092..96d76a50a 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -229,7 +229,7 @@ function createNewVaultAndKeychain (password) { return (dispatch) => { background.createNewVaultAndKeychain(password, (err, newState) => { if (err) { - return dispatch(actions.showWarning(err.message)) + return dispatch(actions.displayWarning(err.message)) } }) } @@ -261,7 +261,7 @@ function addNewKeyring (type, opts) { background.addNewKeyring(type, opts, (err) => { dispatch(this.hideLoadingIndication()) if (err) { - return dispatch(actions.showWarning(err)) + return dispatch(actions.displayWarning(err)) } }) } @@ -548,7 +548,7 @@ function markNoticeRead (notice) { background.markNoticeRead(notice, (err, notice) => { dispatch(this.hideLoadingIndication()) if (err) { - return dispatch(actions.showWarning(err)) + return dispatch(actions.displayWarning(err)) } if (notice) { return dispatch(actions.showNotice(notice)) -- cgit From 10c818abac0901724cf7d98bf63728bdeadcdbed Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 3 Jan 2017 11:30:27 -0800 Subject: Restore missing line --- ui/app/actions.js | 1 + 1 file changed, 1 insertion(+) (limited to 'ui/app') diff --git a/ui/app/actions.js b/ui/app/actions.js index 96d76a50a..2ffa352a4 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -231,6 +231,7 @@ function createNewVaultAndKeychain (password) { if (err) { return dispatch(actions.displayWarning(err.message)) } + dispatch(actions.updateMetamaskState(newState)) }) } } -- cgit From 2c2cdc4475b0ac8a6a52186a470a49c6a085ca08 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 3 Jan 2017 11:33:15 -0800 Subject: Convert more actions to new simple pattern --- ui/app/actions.js | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) (limited to 'ui/app') diff --git a/ui/app/actions.js b/ui/app/actions.js index 2ffa352a4..d63d36f19 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -226,14 +226,7 @@ function createNewVaultAndRestore (password, seed) { } function createNewVaultAndKeychain (password) { - return (dispatch) => { - background.createNewVaultAndKeychain(password, (err, newState) => { - if (err) { - return dispatch(actions.displayWarning(err.message)) - } - dispatch(actions.updateMetamaskState(newState)) - }) - } + return callBackgroundThenUpdate(background.createNewVaultAndKeychain, password) } function revealSeedConfirmation () { @@ -255,17 +248,8 @@ function requestRevealSeed (password) { } } - function addNewKeyring (type, opts) { - return (dispatch) => { - dispatch(actions.showLoadingIndication()) - background.addNewKeyring(type, opts, (err) => { - dispatch(this.hideLoadingIndication()) - if (err) { - return dispatch(actions.displayWarning(err)) - } - }) - } + return callBackgroundThenUpdate(background.addNewKeyring, type, opts) } function addNewAccount (ringNumber = 0) { -- cgit