Skip to content

Commit

Permalink
Use ownProps to get updatedBalanceFromStore
Browse files Browse the repository at this point in the history
  • Loading branch information
rickycodes committed Aug 20, 2020
1 parent cfc50cb commit 4cb235f
Showing 1 changed file with 18 additions and 26 deletions.
44 changes: 18 additions & 26 deletions app/components/UI/AccountList/AccountElement/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,9 @@ class AccountElement extends PureComponent {
disabled: PropTypes.bool,
item: PropTypes.object,
/**
* Selected address as string
* Updated balance using stored in state
*/
selectedAddress: PropTypes.string,
/**
* The currently selected account
*/
selectedAccount: PropTypes.object,
/**
* Does the currently selected account have a balance?
*/
selectedAccountHasBalance: PropTypes.bool
updatedBalanceFromStore: PropTypes.string
};

onPress = () => {
Expand All @@ -126,8 +118,8 @@ class AccountElement extends PureComponent {
};

render() {
const { disabled, selectedAddress, selectedAccount, selectedAccountHasBalance } = this.props;
const { address, balance, ticker, name, isSelected, isImported, balanceError } = this.props.item;
const { disabled, updatedBalanceFromStore } = this.props;
const { address, ticker, name, isSelected, isImported, balanceError } = this.props.item;
const selected = isSelected ? <Icon name="check-circle" size={30} color={colors.blue} /> : null;
const imported = isImported ? (
<View style={styles.importedWrapper}>
Expand All @@ -137,11 +129,6 @@ class AccountElement extends PureComponent {
</View>
) : null;

const updatedBalanceFromState =
balance === EMPTY && selectedAddress === address && selectedAccount && selectedAccountHasBalance
? selectedAccount[BALANCE_KEY]
: balance;

return (
<TouchableOpacity
style={[styles.account, disabled ? styles.disabledAccount : null]}
Expand All @@ -158,7 +145,7 @@ class AccountElement extends PureComponent {
</Text>
<View style={styles.accountBalanceWrapper}>
<Text style={styles.accountBalance}>
{renderFromWei(updatedBalanceFromState)} {getTicker(ticker)}
{renderFromWei(updatedBalanceFromStore)} {getTicker(ticker)}
</Text>
{!!balanceError && (
<Text style={[styles.accountBalance, styles.accountBalanceError]}>{balanceError}</Text>
Expand All @@ -173,20 +160,25 @@ class AccountElement extends PureComponent {
}
}

const mapStateToProps = ({
engine: {
backgroundState: { PreferencesController, AccountTrackerController }
}
}) => {
const mapStateToProps = (
{
engine: {
backgroundState: { PreferencesController, AccountTrackerController }
}
},
{ item: { balance, address } }
) => {
const { selectedAddress } = PreferencesController;
const { accounts } = AccountTrackerController;
const selectedAccount = accounts[selectedAddress];
const selectedAccountHasBalance =
selectedAccount && Object.prototype.hasOwnProperty.call(selectedAccount, BALANCE_KEY);
const updatedBalanceFromStore =
balance === EMPTY && selectedAddress === address && selectedAccount && selectedAccountHasBalance
? selectedAccount[BALANCE_KEY]
: balance;
return {
selectedAddress,
selectedAccount,
selectedAccountHasBalance
updatedBalanceFromStore
};
};

Expand Down

0 comments on commit 4cb235f

Please sign in to comment.