Add sender balance in transfer modal
This commit is contained in:
parent
054b4810d5
commit
d9da8a48ff
@ -134,6 +134,7 @@ export default class Details extends Component {
|
|||||||
images: PropTypes.object.isRequired,
|
images: PropTypes.object.isRequired,
|
||||||
sender: PropTypes.string,
|
sender: PropTypes.string,
|
||||||
senderError: PropTypes.string,
|
senderError: PropTypes.string,
|
||||||
|
sendersBalances: PropTypes.object,
|
||||||
recipient: PropTypes.string,
|
recipient: PropTypes.string,
|
||||||
recipientError: PropTypes.string,
|
recipientError: PropTypes.string,
|
||||||
tag: PropTypes.string,
|
tag: PropTypes.string,
|
||||||
@ -203,7 +204,7 @@ export default class Details extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderFromAddress () {
|
renderFromAddress () {
|
||||||
const { sender, senderError, senders } = this.props;
|
const { sender, senderError, senders, sendersBalances } = this.props;
|
||||||
|
|
||||||
if (!senders) {
|
if (!senders) {
|
||||||
return null;
|
return null;
|
||||||
@ -218,6 +219,7 @@ export default class Details extends Component {
|
|||||||
hint='the sender address'
|
hint='the sender address'
|
||||||
value={ sender }
|
value={ sender }
|
||||||
onChange={ this.onEditSender }
|
onChange={ this.onEditSender }
|
||||||
|
balances={ sendersBalances }
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -54,6 +54,7 @@ export default class TransferStore {
|
|||||||
|
|
||||||
@observable sender = '';
|
@observable sender = '';
|
||||||
@observable senderError = null;
|
@observable senderError = null;
|
||||||
|
@observable sendersBalances = {};
|
||||||
|
|
||||||
@observable total = '0.0';
|
@observable total = '0.0';
|
||||||
@observable totalError = null;
|
@observable totalError = null;
|
||||||
@ -66,8 +67,6 @@ export default class TransferStore {
|
|||||||
onClose = null;
|
onClose = null;
|
||||||
|
|
||||||
senders = null;
|
senders = null;
|
||||||
sendersBalances = null;
|
|
||||||
|
|
||||||
isWallet = false;
|
isWallet = false;
|
||||||
wallet = null;
|
wallet = null;
|
||||||
|
|
||||||
|
@ -155,8 +155,8 @@ class Transfer extends Component {
|
|||||||
|
|
||||||
renderDetailsPage () {
|
renderDetailsPage () {
|
||||||
const { account, balance, images, senders } = this.props;
|
const { account, balance, images, senders } = this.props;
|
||||||
const { valueAll, extras, recipient, recipientError, sender, senderError } = this.store;
|
const { recipient, recipientError, sender, senderError, sendersBalances } = this.store;
|
||||||
const { tag, total, totalError, value, valueError } = this.store;
|
const { valueAll, extras, tag, total, totalError, value, valueError } = this.store;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Details
|
<Details
|
||||||
@ -170,6 +170,7 @@ class Transfer extends Component {
|
|||||||
recipientError={ recipientError }
|
recipientError={ recipientError }
|
||||||
sender={ sender }
|
sender={ sender }
|
||||||
senderError={ senderError }
|
senderError={ senderError }
|
||||||
|
sendersBalances={ sendersBalances }
|
||||||
tag={ tag }
|
tag={ tag }
|
||||||
total={ total }
|
total={ total }
|
||||||
totalError={ totalError }
|
totalError={ totalError }
|
||||||
|
@ -44,7 +44,7 @@ export default handleActions({
|
|||||||
const { token, value } = t;
|
const { token, value } = t;
|
||||||
const { tag } = token;
|
const { tag } = token;
|
||||||
|
|
||||||
const tokenIndex = nextTokens.findIndex((tok) => tok.token.tag === tag);
|
const tokenIndex = nextTokens.findIndex((tok) => tok.token && tok.token.tag === tag);
|
||||||
|
|
||||||
if (tokenIndex === -1) {
|
if (tokenIndex === -1) {
|
||||||
nextTokens.push({
|
nextTokens.push({
|
||||||
|
@ -15,7 +15,9 @@
|
|||||||
/* along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
/* along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
.account {
|
.account {
|
||||||
padding: 4px 0 0 0;
|
padding: 0.25em 0;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.name {
|
.name {
|
||||||
@ -27,6 +29,11 @@
|
|||||||
padding: 0 0 0 1em;
|
padding: 0 0 0 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.balance {
|
||||||
|
color: #aaa;
|
||||||
|
padding-left: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
.image {
|
.image {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
height: 32px;
|
height: 32px;
|
||||||
|
@ -21,6 +21,8 @@ import AutoComplete from '../AutoComplete';
|
|||||||
import IdentityIcon from '../../IdentityIcon';
|
import IdentityIcon from '../../IdentityIcon';
|
||||||
import IdentityName from '../../IdentityName';
|
import IdentityName from '../../IdentityName';
|
||||||
|
|
||||||
|
import { fromWei } from '~/api/util/wei';
|
||||||
|
|
||||||
import styles from './addressSelect.css';
|
import styles from './addressSelect.css';
|
||||||
|
|
||||||
export default class AddressSelect extends Component {
|
export default class AddressSelect extends Component {
|
||||||
@ -40,7 +42,8 @@ export default class AddressSelect extends Component {
|
|||||||
value: PropTypes.string,
|
value: PropTypes.string,
|
||||||
tokens: PropTypes.object,
|
tokens: PropTypes.object,
|
||||||
onChange: PropTypes.func.isRequired,
|
onChange: PropTypes.func.isRequired,
|
||||||
allowInput: PropTypes.bool
|
allowInput: PropTypes.bool,
|
||||||
|
balances: PropTypes.object
|
||||||
}
|
}
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
@ -129,7 +132,34 @@ export default class AddressSelect extends Component {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
renderBalance (address) {
|
||||||
|
const { balances = {} } = this.props;
|
||||||
|
const balance = balances[address];
|
||||||
|
|
||||||
|
if (!balance) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ethToken = balance.tokens.find((t) => t.token.tag.toLowerCase() === 'eth');
|
||||||
|
|
||||||
|
if (!ethToken) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const value = fromWei(ethToken.value);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={ styles.balance }>
|
||||||
|
{ value.toFormat(3) }<small> { 'ETH' }</small>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
renderMenuItem (address) {
|
renderMenuItem (address) {
|
||||||
|
const balance = this.props.balances
|
||||||
|
? this.renderBalance(address)
|
||||||
|
: null;
|
||||||
|
|
||||||
const item = (
|
const item = (
|
||||||
<div className={ styles.account }>
|
<div className={ styles.account }>
|
||||||
<IdentityIcon
|
<IdentityIcon
|
||||||
@ -139,6 +169,8 @@ export default class AddressSelect extends Component {
|
|||||||
<IdentityName
|
<IdentityName
|
||||||
className={ styles.name }
|
className={ styles.name }
|
||||||
address={ address } />
|
address={ address } />
|
||||||
|
|
||||||
|
{ balance }
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -155,11 +187,10 @@ export default class AddressSelect extends Component {
|
|||||||
|
|
||||||
getSearchText () {
|
getSearchText () {
|
||||||
const entry = this.getEntry();
|
const entry = this.getEntry();
|
||||||
const { value } = this.state;
|
|
||||||
|
|
||||||
return entry && entry.name
|
return entry && entry.name
|
||||||
? entry.name.toUpperCase()
|
? entry.name.toUpperCase()
|
||||||
: value;
|
: this.state.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
getEntry () {
|
getEntry () {
|
||||||
|
Loading…
Reference in New Issue
Block a user