forked from Splyse/NeoLink
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #120 from FredrikOseberg/feature/switch-accounts
Feature/switch accounts list
- Loading branch information
Showing
9 changed files
with
3,856 additions
and
3,696 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
11 changes: 11 additions & 0 deletions
11
src/app/components/SwitchAccountCard/SwitchAccountCard.css
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,11 @@ | ||
.switchAccountCard { | ||
background-color: #fff; | ||
margin: 20px 0; | ||
padding: 20px 0; | ||
box-shadow: 2px 2px 2px rgba(201, 201, 201, 1) | ||
} | ||
|
||
.switchAccountAmounts { | ||
margin-top:20px; | ||
} | ||
|
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,26 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
import AccountInfoHeader from '../../components/AccountInfo/AccountInfoHeader' | ||
import AccountInfoAmounts from '../../components/AccountInfo/AccountInfoAmounts' | ||
|
||
import style from './SwitchAccountCard.css' | ||
|
||
const SwitchAccountCard = ({ address, neo, gas, label, classNames }) => { | ||
return ( | ||
<section className={ style.switchAccountCard + ' ' + classNames }> | ||
<AccountInfoHeader address={ address } label={ label } showOptions={ false } /> | ||
<AccountInfoAmounts neo={ neo } gas={ gas } showRefresh={ false } classNames={ style.switchAccountAmounts } /> | ||
</section> | ||
) | ||
} | ||
|
||
SwitchAccountCard.propTypes = { | ||
address: PropTypes.string, | ||
neo: PropTypes.number, | ||
gas: PropTypes.number, | ||
label: PropTypes.string, | ||
classNames: PropTypes.string, | ||
} | ||
|
||
export default SwitchAccountCard |
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,12 @@ | ||
.switchAccountContainer { | ||
padding: 20px 0; | ||
} | ||
|
||
.switchAccountHeading { | ||
text-align: center; | ||
margin-top: 0; | ||
} | ||
|
||
.accountSelected { | ||
border-top: 2px solid green; | ||
} |
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,93 @@ | ||
import React, { Component } from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
import { getBalance } from '../../utils/helpers' | ||
|
||
import SwitchAccountCard from '../../components/SwitchAccountCard' | ||
|
||
import style from './SwitchAccount.css' | ||
|
||
class SwitchAccount extends Component { | ||
state = { | ||
accounts: [], | ||
} | ||
|
||
componentDidMount() { | ||
this.setAccountState() | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
const { selectedNetworkId } = this.props | ||
if (selectedNetworkId !== nextProps.selectedNetworkId) { | ||
this.setAccountState() | ||
} | ||
} | ||
|
||
setAccountState = () => { | ||
const { accounts, networks, selectedNetworkId } = this.props | ||
const formattedAccounts = [] | ||
|
||
const accountsArray = Object.keys(accounts) | ||
accountsArray.map((account, index) => { | ||
getBalance(networks, selectedNetworkId, accounts[account].address).then(response => { | ||
formattedAccounts.push({ | ||
address: accounts[account].address, | ||
encryptedKey: accounts[account].key, | ||
label: accounts[account].label, | ||
neo: response.neo, | ||
gas: response.gas, | ||
}) | ||
if (index === accountsArray.length - 1) { | ||
this.setState({ accounts: formattedAccounts }) | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
generateAccountCards = () => { | ||
const { account } = this.props | ||
const { accounts } = this.state | ||
let selectedAccountIndex | ||
|
||
const accountCards = accounts.map(({ label, neo, gas, address }, index) => { | ||
let selectedStyles = null | ||
if (account.address === address) { | ||
selectedStyles = style.accountSelected | ||
selectedAccountIndex = index | ||
} | ||
return ( | ||
<SwitchAccountCard | ||
label={ label } | ||
neo={ neo } | ||
gas={ gas } | ||
address={ address } | ||
classNames={ selectedStyles } | ||
key={ address } | ||
/> | ||
) | ||
}) | ||
|
||
const selectedAccount = accountCards.splice(selectedAccountIndex, 1) | ||
accountCards.unshift(selectedAccount) | ||
|
||
return accountCards | ||
} | ||
|
||
render() { | ||
return ( | ||
<section className={ style.switchAccountContainer }> | ||
<h1 className={ style.switchAccountHeading }>Switch Account</h1> | ||
{this.generateAccountCards()} | ||
</section> | ||
) | ||
} | ||
} | ||
|
||
SwitchAccount.propTypes = { | ||
accounts: PropTypes.object, | ||
account: PropTypes.object, | ||
networks: PropTypes.object, | ||
selectedNetworkId: PropTypes.object, | ||
} | ||
|
||
export default SwitchAccount |
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,11 @@ | ||
import { connect } from 'react-redux' | ||
import SwitchAccount from './SwitchAccount' | ||
|
||
const mapStateToProps = state => ({ | ||
accounts: state.wallet.accounts, | ||
account: state.account, | ||
networks: state.config.networks, | ||
selectedNetworkId: state.config.selectedNetworkId, | ||
}) | ||
|
||
export default connect(mapStateToProps)(SwitchAccount) |
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