Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: new send flow amount balance #1294

Merged
merged 5 commits into from
Jan 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,27 @@ exports[`Amount should render correctly 1`] = `
/>
</View>
</View>
<View
style={
Object {
"marginVertical": 16,
}
}
>
<Text
style={
Object {
"alignSelf": "center",
"fontFamily": "Roboto",
"fontSize": 12,
"fontWeight": "400",
"lineHeight": 16,
}
}
>
Balance: undefined
</Text>
</View>
</View>
</View>
<KeyboardAvoidingView
Expand Down
34 changes: 31 additions & 3 deletions app/components/Views/SendFlow/Amount/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,15 @@ const styles = StyleSheet.create({
nextActionWrapper: {
flex: 1,
marginBottom: 16
},
balanceWrapper: {
marginVertical: 16
},
balanceText: {
...fontStyles.normal,
alignSelf: 'center',
fontSize: 12,
lineHeight: 16
}
});

Expand Down Expand Up @@ -357,11 +366,13 @@ class Amount extends PureComponent {
collectibles = [];

componentDidMount = async () => {
const { tokens, ticker } = this.props;
const { tokens, ticker, selectedAsset } = this.props;
this.tokens = [getEther(ticker), ...tokens];
this.collectibles = this.processCollectibles();
this.amountInput && this.amountInput.current && this.amountInput.current.focus();
this.onInputChange();
// if collectible don't do this
if (!selectedAsset.tokenId) this.handleSelectedAssetBalance(selectedAsset);
const estimatedTotalGas = await this.estimateTransactionTotalGas();
this.setState({ estimatedTotalGas });
};
Expand Down Expand Up @@ -570,11 +581,24 @@ class Amount extends PureComponent {
this.setState({ assetsModalVisible: !assetsModalVisible });
};

handleSelectedAssetBalance = selectedAsset => {
const { accounts, selectedAddress, contractBalances } = this.props;
let currentBalance;
const { address, decimals, symbol, isETH } = selectedAsset;
if (isETH) {
currentBalance = `${renderFromWei(accounts[selectedAddress].balance)} ${symbol}`;
} else {
currentBalance = `${renderFromTokenMinimalUnit(contractBalances[address], decimals)} ${symbol}`;
}
this.setState({ currentBalance });
};

pickSelectedAsset = selectedAsset => {
this.toggleAssetsModal();
this.props.setSelectedAsset(selectedAsset);
if (!selectedAsset.tokenId) {
this.onInputChange(undefined, selectedAsset);
this.handleSelectedAssetBalance(selectedAsset);
// Wait for input to mount first
setTimeout(() => this.amountInput && this.amountInput.current && this.amountInput.current.focus(), 500);
}
Expand Down Expand Up @@ -719,7 +743,8 @@ class Amount extends PureComponent {
renderableInputValueConversion,
amountError,
hasExchangeRate,
internalPrimaryCurrencyIsCrypto
internalPrimaryCurrencyIsCrypto,
currentBalance
} = this.state;
const { currentCurrency } = this.props;
return (
Expand All @@ -741,7 +766,7 @@ class Amount extends PureComponent {
</View>
{hasExchangeRate && (
<View style={styles.actionsWrapper}>
<View style={[styles.action]}>
<View style={styles.action}>
<TouchableOpacity style={styles.actionSwitch} onPress={this.switchCurrency}>
<Text style={styles.textSwitch} numberOfLines={1}>
{renderableInputValueConversion}
Expand All @@ -758,6 +783,9 @@ class Amount extends PureComponent {
</View>
</View>
)}
<View style={styles.balanceWrapper}>
<Text style={styles.balanceText}>{`${strings('transaction.balance')}: ${currentBalance}`}</Text>
</View>
{amountError && (
<View style={styles.errorMessageWrapper}>
<ErrorMessage errorMessage={amountError} />
Expand Down
4 changes: 2 additions & 2 deletions app/components/Views/SendFlow/Confirm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ class Confirm extends PureComponent {
} else if (selectedAsset.tokenId) {
fromAccountBalance = `${renderFromWei(accounts[from].balance)} ${parsedTicker}`;
const collectibleTransferInformation =
selectedAsset.address in collectiblesTransferInformation &&
collectiblesTransferInformation[selectedAsset.address];
selectedAsset.address.toLowerCase() in collectiblesTransferInformation &&
collectiblesTransferInformation[selectedAsset.address.toLowerCase()];
if (
!collectibleTransferInformation ||
(collectibleTransferInformation.tradable && collectibleTransferInformation.method === 'transferFrom')
Expand Down
3 changes: 2 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,8 @@
"total_amount": "Total amount",
"adjust_transaction_fee": "Adjust transaction fee",
"could_not_resolve_ens": "Couldn't resolve ENS",
"asset": "Asset"
"asset": "Asset",
"balance": "Balance"
},
"custom_gas": {
"advanced_options": "Show advanced options",
Expand Down
3 changes: 2 additions & 1 deletion locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,8 @@
"total_amount": "Cantidad total",
"adjust_transaction_fee": "Ajustar tarifa de transacción",
"could_not_resolve_ens": "No se pudo resolver nombre ENS",
"asset": "Activo"
"asset": "Activo",
"balance": "Balance"
},
"custom_gas": {
"advanced_options": "Mostrar opciones avanzadas",
Expand Down