@@ -265,6 +265,15 @@ const styles = StyleSheet.create({
265
265
nextActionWrapper : {
266
266
flex : 1 ,
267
267
marginBottom : 16
268
+ } ,
269
+ balanceWrapper : {
270
+ marginVertical : 16
271
+ } ,
272
+ balanceText : {
273
+ ...fontStyles . normal ,
274
+ alignSelf : 'center' ,
275
+ fontSize : 12 ,
276
+ lineHeight : 16
268
277
}
269
278
} ) ;
270
279
@@ -357,11 +366,13 @@ class Amount extends PureComponent {
357
366
collectibles = [ ] ;
358
367
359
368
componentDidMount = async ( ) => {
360
- const { tokens, ticker } = this . props ;
369
+ const { tokens, ticker, selectedAsset } = this . props ;
361
370
this . tokens = [ getEther ( ticker ) , ...tokens ] ;
362
371
this . collectibles = this . processCollectibles ( ) ;
363
372
this . amountInput && this . amountInput . current && this . amountInput . current . focus ( ) ;
364
373
this . onInputChange ( ) ;
374
+ // if collectible don't do this
375
+ if ( ! selectedAsset . tokenId ) this . handleSelectedAssetBalance ( selectedAsset ) ;
365
376
const estimatedTotalGas = await this . estimateTransactionTotalGas ( ) ;
366
377
this . setState ( { estimatedTotalGas } ) ;
367
378
} ;
@@ -570,11 +581,24 @@ class Amount extends PureComponent {
570
581
this . setState ( { assetsModalVisible : ! assetsModalVisible } ) ;
571
582
} ;
572
583
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
+
573
596
pickSelectedAsset = selectedAsset => {
574
597
this . toggleAssetsModal ( ) ;
575
598
this . props . setSelectedAsset ( selectedAsset ) ;
576
599
if ( ! selectedAsset . tokenId ) {
577
600
this . onInputChange ( undefined , selectedAsset ) ;
601
+ this . handleSelectedAssetBalance ( selectedAsset ) ;
578
602
// Wait for input to mount first
579
603
setTimeout ( ( ) => this . amountInput && this . amountInput . current && this . amountInput . current . focus ( ) , 500 ) ;
580
604
}
@@ -719,7 +743,8 @@ class Amount extends PureComponent {
719
743
renderableInputValueConversion,
720
744
amountError,
721
745
hasExchangeRate,
722
- internalPrimaryCurrencyIsCrypto
746
+ internalPrimaryCurrencyIsCrypto,
747
+ currentBalance
723
748
} = this . state ;
724
749
const { currentCurrency } = this . props ;
725
750
return (
@@ -741,7 +766,7 @@ class Amount extends PureComponent {
741
766
</ View >
742
767
{ hasExchangeRate && (
743
768
< View style = { styles . actionsWrapper } >
744
- < View style = { [ styles . action ] } >
769
+ < View style = { styles . action } >
745
770
< TouchableOpacity style = { styles . actionSwitch } onPress = { this . switchCurrency } >
746
771
< Text style = { styles . textSwitch } numberOfLines = { 1 } >
747
772
{ renderableInputValueConversion }
@@ -758,6 +783,9 @@ class Amount extends PureComponent {
758
783
</ View >
759
784
</ View >
760
785
) }
786
+ < View style = { styles . balanceWrapper } >
787
+ < Text style = { styles . balanceText } > { `${ strings ( 'transaction.balance' ) } : ${ currentBalance } ` } </ Text >
788
+ </ View >
761
789
{ amountError && (
762
790
< View style = { styles . errorMessageWrapper } >
763
791
< ErrorMessage errorMessage = { amountError } />
0 commit comments