Skip to content

Commit 510aa9b

Browse files
authored
Bugfix: new send flow amount balance (#1294)
* add balance * snaps * ui issue * fix collectible
1 parent 5d45314 commit 510aa9b

File tree

5 files changed

+58
-7
lines changed

5 files changed

+58
-7
lines changed

app/components/Views/SendFlow/Amount/__snapshots__/index.test.js.snap

+21
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,27 @@ exports[`Amount should render correctly 1`] = `
153153
/>
154154
</View>
155155
</View>
156+
<View
157+
style={
158+
Object {
159+
"marginVertical": 16,
160+
}
161+
}
162+
>
163+
<Text
164+
style={
165+
Object {
166+
"alignSelf": "center",
167+
"fontFamily": "Roboto",
168+
"fontSize": 12,
169+
"fontWeight": "400",
170+
"lineHeight": 16,
171+
}
172+
}
173+
>
174+
Balance: undefined
175+
</Text>
176+
</View>
156177
</View>
157178
</View>
158179
<KeyboardAvoidingView

app/components/Views/SendFlow/Amount/index.js

+31-3
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,15 @@ const styles = StyleSheet.create({
265265
nextActionWrapper: {
266266
flex: 1,
267267
marginBottom: 16
268+
},
269+
balanceWrapper: {
270+
marginVertical: 16
271+
},
272+
balanceText: {
273+
...fontStyles.normal,
274+
alignSelf: 'center',
275+
fontSize: 12,
276+
lineHeight: 16
268277
}
269278
});
270279

@@ -357,11 +366,13 @@ class Amount extends PureComponent {
357366
collectibles = [];
358367

359368
componentDidMount = async () => {
360-
const { tokens, ticker } = this.props;
369+
const { tokens, ticker, selectedAsset } = this.props;
361370
this.tokens = [getEther(ticker), ...tokens];
362371
this.collectibles = this.processCollectibles();
363372
this.amountInput && this.amountInput.current && this.amountInput.current.focus();
364373
this.onInputChange();
374+
// if collectible don't do this
375+
if (!selectedAsset.tokenId) this.handleSelectedAssetBalance(selectedAsset);
365376
const estimatedTotalGas = await this.estimateTransactionTotalGas();
366377
this.setState({ estimatedTotalGas });
367378
};
@@ -570,11 +581,24 @@ class Amount extends PureComponent {
570581
this.setState({ assetsModalVisible: !assetsModalVisible });
571582
};
572583

584+
handleSelectedAssetBalance = selectedAsset => {
585+
const { accounts, selectedAddress, contractBalances } = this.props;
586+
let currentBalance;
587+
const { address, decimals, symbol, isETH } = selectedAsset;
588+
if (isETH) {
589+
currentBalance = `${renderFromWei(accounts[selectedAddress].balance)} ${symbol}`;
590+
} else {
591+
currentBalance = `${renderFromTokenMinimalUnit(contractBalances[address], decimals)} ${symbol}`;
592+
}
593+
this.setState({ currentBalance });
594+
};
595+
573596
pickSelectedAsset = selectedAsset => {
574597
this.toggleAssetsModal();
575598
this.props.setSelectedAsset(selectedAsset);
576599
if (!selectedAsset.tokenId) {
577600
this.onInputChange(undefined, selectedAsset);
601+
this.handleSelectedAssetBalance(selectedAsset);
578602
// Wait for input to mount first
579603
setTimeout(() => this.amountInput && this.amountInput.current && this.amountInput.current.focus(), 500);
580604
}
@@ -719,7 +743,8 @@ class Amount extends PureComponent {
719743
renderableInputValueConversion,
720744
amountError,
721745
hasExchangeRate,
722-
internalPrimaryCurrencyIsCrypto
746+
internalPrimaryCurrencyIsCrypto,
747+
currentBalance
723748
} = this.state;
724749
const { currentCurrency } = this.props;
725750
return (
@@ -741,7 +766,7 @@ class Amount extends PureComponent {
741766
</View>
742767
{hasExchangeRate && (
743768
<View style={styles.actionsWrapper}>
744-
<View style={[styles.action]}>
769+
<View style={styles.action}>
745770
<TouchableOpacity style={styles.actionSwitch} onPress={this.switchCurrency}>
746771
<Text style={styles.textSwitch} numberOfLines={1}>
747772
{renderableInputValueConversion}
@@ -758,6 +783,9 @@ class Amount extends PureComponent {
758783
</View>
759784
</View>
760785
)}
786+
<View style={styles.balanceWrapper}>
787+
<Text style={styles.balanceText}>{`${strings('transaction.balance')}: ${currentBalance}`}</Text>
788+
</View>
761789
{amountError && (
762790
<View style={styles.errorMessageWrapper}>
763791
<ErrorMessage errorMessage={amountError} />

app/components/Views/SendFlow/Confirm/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,8 @@ class Confirm extends PureComponent {
328328
} else if (selectedAsset.tokenId) {
329329
fromAccountBalance = `${renderFromWei(accounts[from].balance)} ${parsedTicker}`;
330330
const collectibleTransferInformation =
331-
selectedAsset.address in collectiblesTransferInformation &&
332-
collectiblesTransferInformation[selectedAsset.address];
331+
selectedAsset.address.toLowerCase() in collectiblesTransferInformation &&
332+
collectiblesTransferInformation[selectedAsset.address.toLowerCase()];
333333
if (
334334
!collectibleTransferInformation ||
335335
(collectibleTransferInformation.tradable && collectibleTransferInformation.method === 'transferFrom')

locales/en.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,8 @@
506506
"total_amount": "Total amount",
507507
"adjust_transaction_fee": "Adjust transaction fee",
508508
"could_not_resolve_ens": "Couldn't resolve ENS",
509-
"asset": "Asset"
509+
"asset": "Asset",
510+
"balance": "Balance"
510511
},
511512
"custom_gas": {
512513
"advanced_options": "Show advanced options",

locales/es.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,8 @@
496496
"total_amount": "Cantidad total",
497497
"adjust_transaction_fee": "Ajustar tarifa de transacción",
498498
"could_not_resolve_ens": "No se pudo resolver nombre ENS",
499-
"asset": "Activo"
499+
"asset": "Activo",
500+
"balance": "Balance"
500501
},
501502
"custom_gas": {
502503
"advanced_options": "Mostrar opciones avanzadas",

0 commit comments

Comments
 (0)