-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minimetoken branch to Embark 3.1 (#11)
* merge bootstrap-embark31 * tests for embark31 * use js config * merge bootstrap
- Loading branch information
Showing
37 changed files
with
735 additions
and
534 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"plugins": ["transform-object-rest-spread"], | ||
"presets": ["stage-2"] | ||
} |
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,9 @@ | ||
{ | ||
"extends": "airbnb", | ||
"plugins": [ | ||
"react" | ||
], | ||
"rules": { | ||
"react/prop-types": 0 | ||
} | ||
} |
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,19 @@ | ||
import ERC20Token from 'Embark/contracts/ERC20Token'; | ||
import { actions as accountActions } from '../reducers/accounts' | ||
|
||
const { receiveAccounts } = accountActions | ||
export const fetchAndDispatchAccountsWithBalances = (web3, dispatch) => { | ||
web3.eth.getAccounts((err, addresses) => { | ||
if (addresses) { | ||
const defaultAccount = web3.eth.defaultAccount || addresses[0] | ||
const accounts = addresses.map(async address => { | ||
const balance = await web3.eth.getBalance(address, 'latest') | ||
const ERC20TokenBalance = await ERC20Token.methods.balanceOf(address).call() | ||
return { address, balance, ERC20TokenBalance } | ||
}) | ||
Promise.all(accounts).then(accounts => { | ||
dispatch(receiveAccounts(defaultAccount, accounts)) | ||
}) | ||
} | ||
}) | ||
} |
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,66 @@ | ||
import web3 from 'Embark/web3' | ||
import React from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { Nav, MenuItem, NavDropdown } from 'react-bootstrap'; | ||
import Blockies from 'react-blockies'; | ||
import { string, bool, func, arrayOf, shape } from 'prop-types'; | ||
import { getAccounts, getDefaultAccount, accountsIsLoading, actions as accountActions } from '../reducers/accounts'; | ||
import './accountlist.css'; | ||
|
||
const AccList = ({ | ||
accounts, defaultAccount, changeAccount, isLoading, classNameNavDropdown, | ||
}) => ( | ||
<React.Fragment> | ||
{!isLoading ? | ||
<div className="accounts"> | ||
<div className="selectedIdenticon"> | ||
<Blockies seed={defaultAccount} /> | ||
</div> | ||
<div className="accountList"> | ||
<Nav> | ||
<NavDropdown key={1} title={defaultAccount} id="basic-nav-dropdown" className={classNameNavDropdown}> | ||
{accounts.map(account => ( | ||
<MenuItem key={account.address} onClick={() => changeAccount(account.address)}> | ||
<div className="account"> | ||
<div className="accountIdenticon"> | ||
<Blockies seed={account.address} /> | ||
</div> | ||
<div className="accountHexString"> | ||
{account.address} | ||
</div> | ||
<div className="accountBalance"> | ||
Ξ {account.balance / (10 ** 18)} | ||
</div> | ||
</div> | ||
</MenuItem> | ||
))} | ||
</NavDropdown> | ||
</Nav> | ||
</div> | ||
</div> | ||
: <div>Loading...</div>} | ||
</React.Fragment> | ||
); | ||
|
||
AccList.propTypes = { | ||
accounts: arrayOf(shape({ address: string, balance: string })).isRequired, | ||
defaultAccount: string, | ||
changeAccount: func.isRequired, | ||
isLoading: bool.isRequired, | ||
classNameNavDropdown: string | ||
} | ||
|
||
const mapStateToProps = state => ({ | ||
accounts: getAccounts(state), | ||
defaultAccount: getDefaultAccount(state), | ||
isLoading: accountsIsLoading(state), | ||
}); | ||
|
||
const mapDispatchToProps = dispatch => ({ | ||
changeAccount(address) { | ||
web3.eth.defaultAccount = address; | ||
dispatch(accountActions.updateDefaultAccount(address)); | ||
}, | ||
}); | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(AccList); |
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 |
---|---|---|
@@ -1,112 +1,66 @@ | ||
import web3 from "Embark/web3" | ||
import EmbarkJS from 'Embark/EmbarkJS'; | ||
import web3 from 'Embark/web3' | ||
import React from 'react'; | ||
import { Nav, MenuItem , NavDropdown} from 'react-bootstrap'; | ||
import { connect } from 'react-redux'; | ||
import { Nav, MenuItem, NavDropdown } from 'react-bootstrap'; | ||
import Blockies from 'react-blockies'; | ||
|
||
import { string, bool, func, arrayOf, shape } from 'prop-types'; | ||
import { getAccounts, getDefaultAccount, accountsIsLoading, actions as accountActions } from '../reducers/accounts'; | ||
import './accountlist.css'; | ||
|
||
class AccList extends React.Component { | ||
|
||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
classNameNavDropdown: props.classNameNavDropdown, | ||
defaultAccount: "0x0000000000000000000000000000000000000000", | ||
addresses: [], | ||
balances: [] | ||
} | ||
__embarkContext.execWhenReady(() => { | ||
this.load() | ||
}); | ||
} | ||
|
||
|
||
load() { | ||
web3.eth.getAccounts((err, addresses) => { | ||
if (addresses) { | ||
var defaultAccount = web3.eth.defaultAccount; | ||
if(!defaultAccount){ | ||
web3.eth.defaultAccount = addresses[0]; | ||
} | ||
|
||
var balances = []; | ||
balances.length == addresses.length; | ||
addresses.forEach((address, index) => { | ||
web3.eth.getBalance(address, 'latest', (err, balance) => { | ||
balances[index] = balance; | ||
if(index+1 == balances.length){ | ||
this.setState({ | ||
balances: balances | ||
}); | ||
} | ||
}) | ||
}) | ||
this.setState({ | ||
defaultAccount: defaultAccount, | ||
addresses: addresses | ||
}); | ||
|
||
} else { | ||
console.log("No addresses available."); | ||
} | ||
|
||
}) | ||
} | ||
setDefaultAccount(index) { | ||
var defaultAcc = this.state.addresses[index]; | ||
if(defaultAcc){ | ||
web3.eth.defaultAccount = defaultAcc; | ||
this.setState({defaultAccount: defaultAcc }); | ||
} else { | ||
console.log("invalid account") | ||
} | ||
} | ||
|
||
render() { | ||
|
||
var accsTitle; | ||
var accsList = []; | ||
if (this.state.addresses) { | ||
accsTitle = this.state.defaultAccount; | ||
this.state.addresses.forEach( | ||
(name, index) => { | ||
accsList.push( | ||
<MenuItem key={index} onClick={(e) => this.setDefaultAccount(index) }> | ||
<div className="account"> | ||
<div className="accountIdenticon"> | ||
<Blockies seed={name} /> | ||
</div> | ||
<div className="accountHexString"> | ||
{name} | ||
</div> | ||
<div className="accountBalance"> | ||
Ξ {this.state.balances[index] / (10**18)} | ||
</div> | ||
</div> | ||
</MenuItem>); | ||
} | ||
) | ||
} | ||
|
||
return ( | ||
<React.Fragment> | ||
<div className="accounts"> | ||
<div className="selectedIdenticon"> | ||
<Blockies seed={ this.state.defaultAccount } /> | ||
const AccList = ({ | ||
accounts, defaultAccount, changeAccount, isLoading, classNameNavDropdown, | ||
}) => ( | ||
<React.Fragment> | ||
{!isLoading ? | ||
<div className="accounts"> | ||
<div className="selectedIdenticon"> | ||
<Blockies seed={defaultAccount} /> | ||
</div> | ||
<div className="accountList"> | ||
<Nav> | ||
<NavDropdown key={1} title={defaultAccount} id="basic-nav-dropdown" className={classNameNavDropdown}> | ||
{accounts.map(account => ( | ||
<MenuItem key={account.address} onClick={() => changeAccount(account.address)}> | ||
<div className="account"> | ||
<div className="accountIdenticon"> | ||
<Blockies seed={account.address} /> | ||
</div> | ||
<div className="accountList"> | ||
<Nav> | ||
<NavDropdown key={1} title={accsTitle} id="basic-nav-dropdown" className={ this.state.classNameNavDropdown }> | ||
{accsList} | ||
</NavDropdown> | ||
</Nav> | ||
<div className="accountHexString"> | ||
{account.address} | ||
</div> | ||
</div> | ||
</React.Fragment> | ||
) | ||
} | ||
<div className="accountBalance"> | ||
Ξ {account.balance / (10 ** 18)} | ||
</div> | ||
</div> | ||
</MenuItem> | ||
))} | ||
</NavDropdown> | ||
</Nav> | ||
</div> | ||
</div> | ||
: <div>Loading...</div>} | ||
</React.Fragment> | ||
); | ||
|
||
AccList.propTypes = { | ||
accounts: arrayOf(shape({ address: string, balance: string })).isRequired, | ||
defaultAccount: string, | ||
changeAccount: func.isRequired, | ||
isLoading: bool.isRequired, | ||
classNameNavDropdown: string | ||
} | ||
|
||
const mapStateToProps = state => ({ | ||
accounts: getAccounts(state), | ||
defaultAccount: getDefaultAccount(state), | ||
isLoading: accountsIsLoading(state), | ||
}); | ||
|
||
} | ||
const mapDispatchToProps = dispatch => ({ | ||
changeAccount(address) { | ||
web3.eth.defaultAccount = address; | ||
dispatch(accountActions.updateDefaultAccount(address)); | ||
}, | ||
}); | ||
|
||
export default AccList; | ||
export default connect(mapStateToProps, mapDispatchToProps)(AccList); |
Oops, something went wrong.