@@ -24,19 +24,19 @@ export default class MyWalletDetailsScreen extends React.Component {
2424
2525 constructor ( props ) {
2626 super ( props )
27- this . walletUtils = new WalletUtils ( this . props . navigation . getParam ( 'wallet' , null ) , this . props . navigation . getParam ( 'password' , null ) , global . ecl ) ;
28- this . walletUtils . subscribeToAddresses ( ) ;
29- this . walletUtils . checkHistory ( ) ;
30- this . isCancelled = false ;
3127 this . state = {
3228
29+ updatingBalance : false ,
3330 loading : false ,
3431 isConnected : false ,
35- wallet : this . props . navigation . getParam ( 'wallet' , null ) ,
36- password : this . props . navigation . getParam ( 'password' , null ) ,
32+ walletUtils : new WalletUtils ( this . props . navigation . getParam ( 'wallet' , null ) , this . props . navigation . getParam ( 'password' , null ) , global . ecl ) ,
3733 appState : AppState . currentState
3834
3935 }
36+
37+ this . state . walletUtils . subscribeToAddresses ( ) ;
38+ this . state . walletUtils . checkHistory ( ) ;
39+ this . state . isCancelled = false ;
4040
4141 const willFocusSubscription = this . props . navigation . addListener (
4242 'willFocus' ,
@@ -83,7 +83,14 @@ export default class MyWalletDetailsScreen extends React.Component {
8383 }
8484
8585 updateWallet ( ) {
86- if ( ! this . isCancelled ) this . setState ( { wallet : this . walletUtils . wallet } ) ;
86+ if ( ! this . isCancelled ) this . setState ( { walletUtils : this . state . walletUtils } ) ;
87+ }
88+
89+ async updateBalance ( ) {
90+ if ( ! this . isCancelled ) this . setState ( { updatingBalance : true } ) ;
91+ await this . state . walletUtils . updateBalance ( ) ;
92+ if ( ! this . isCancelled ) this . setState ( { walletUtils : this . state . walletUtils } ) ;
93+ if ( ! this . isCancelled ) this . setState ( { updatingBalance : false } ) ;
8794 }
8895
8996 static navigationOptions = ( { navigation } ) => {
@@ -98,7 +105,7 @@ export default class MyWalletDetailsScreen extends React.Component {
98105 }
99106
100107 navigateToSettings = ( ) => {
101- this . props . navigation . navigate ( "WalletSettings" , { wallet : this . state . wallet , password : this . state . password } )
108+ this . props . navigation . navigate ( "WalletSettings" , { walletUtils : this . state . walletUtils } )
102109 }
103110
104111
@@ -117,9 +124,9 @@ export default class MyWalletDetailsScreen extends React.Component {
117124
118125 handleAppStateChange = ( nextAppState ) => {
119126 if ( this . state . appState . match ( / i n a c t i v e | b a c k g r o u n d / ) && nextAppState === 'active' ) {
120- this . walletUtils = new WalletUtils ( this . state . wallet , this . props . navigation . getParam ( ' password' , null ) , global . ecl ) ;
121- this . walletUtils . subscribeToAddresses ( ) ;
122- this . walletUtils . checkHistory ( ) ;
127+ this . setState ( { walletUtils : new WalletUtils ( this . state . walletUtils . wallet , this . state . walletUtils . password , global . ecl ) } ) ;
128+ this . state . walletUtils . subscribeToAddresses ( ) ;
129+ this . state . walletUtils . checkHistory ( ) ;
123130 }
124131 if ( ! this . isCancelled ) this . setState ( { appState : nextAppState } ) ;
125132 }
@@ -134,26 +141,26 @@ export default class MyWalletDetailsScreen extends React.Component {
134141
135142 render ( ) {
136143
137- const { wallet , password , isConnected, loading, updatingBalance } = this . state
144+ const { walletUtils , isConnected, loading, updatingBalance } = this . state
138145
139146 return (
140147 < View style = { styles . container } >
141148 { loading &&
142149 < Loader loading = { true } />
143150 }
144151 < View style = { styles . balanceContainer } >
145- < Text style = { styles . balanceText } > { `${ wallet . balance / 10000 } MBC` } </ Text >
152+ { updatingBalance ? < ActivityIndicator size = "small" color = "#fff" style = { styles . balanceLoading } /> : < TouchableOpacity onPress = { ( ) => this . updateBalance ( ) } > < Text style = { styles . balanceText } > { `${ walletUtils . wallet . balance / 10000 } MBC` } </ Text > </ TouchableOpacity > }
146153 < Text >
147154 < Icon name = "controller-record" size = { 14 } color = { isConnected ? '#00d47d' : '#ff4133' } />
148- < Text style = { styles . balanceSubText } > { wallet . title } </ Text >
155+ < Text style = { styles . balanceSubText } > { walletUtils . wallet . title } </ Text >
149156 </ Text >
150157 </ View >
151158 < ScrollView >
152- { wallet . transactions == null ? < View style = { styles . noHistoryContainer } > < ActivityIndicator size = "large" color = "#000672" /> </ View > : null }
153- { wallet . transactions != null && Object . keys ( wallet . transactions ) . length == 0 && wallet . mempool . length == 0 ? < View style = { styles . noHistoryContainer } > < Text style = { styles . labelText } > Wallet history is empty</ Text > </ View > : null }
154- { wallet . mempool . length > 0 ? < Text style = { styles . addressHeader } > Unconfirmed transactions</ Text > : null }
159+ { walletUtils . wallet . transactions == null ? < View style = { styles . noHistoryContainer } > < ActivityIndicator size = "large" color = "#000672" /> </ View > : null }
160+ { walletUtils . wallet . transactions != null && Object . keys ( walletUtils . wallet . transactions ) . length == 0 && walletUtils . wallet . mempool . length == 0 ? < View style = { styles . noHistoryContainer } > < Text style = { styles . labelText } > Wallet history is empty</ Text > </ View > : null }
161+ { walletUtils . wallet . mempool . length > 0 ? < Text style = { styles . addressHeader } > Unconfirmed transactions</ Text > : null }
155162 {
156- wallet . mempool . map ( ( tx ) => (
163+ walletUtils . wallet . mempool . map ( ( tx ) => (
157164 < TouchableOpacity
158165 key = { tx [ 'hash' ] }
159166 onPress = { ( ) => this . openLink ( tx [ 'hash' ] ) } >
@@ -162,20 +169,20 @@ export default class MyWalletDetailsScreen extends React.Component {
162169 ) )
163170 }
164171
165- { Object . keys ( wallet . transactions ) . length > 0 ? < Text style = { styles . addressHeader } > Confirmed transactions</ Text > : null }
172+ { Object . keys ( walletUtils . wallet . transactions ) . length > 0 ? < Text style = { styles . addressHeader } > Confirmed transactions</ Text > : null }
166173 {
167- wallet . transactions != null ? Object . keys ( wallet . transactions ) . reverse ( ) . slice ( 0 , wallet . settings . historyCount ) . map ( ( tx ) => (
174+ walletUtils . wallet . transactions != null ? Object . keys ( walletUtils . wallet . transactions ) . reverse ( ) . slice ( 0 , walletUtils . wallet . settings . historyCount ) . map ( ( tx ) => (
168175 < TouchableOpacity
169- key = { wallet . transactions [ tx ] [ 'hash' ] }
170- onPress = { ( ) => this . openLink ( wallet . transactions [ tx ] [ 'hash' ] ) } >
171- < MyWalletTransaction tx = { wallet . transactions [ tx ] } />
176+ key = { walletUtils . wallet . transactions [ tx ] [ 'hash' ] }
177+ onPress = { ( ) => this . openLink ( walletUtils . wallet . transactions [ tx ] [ 'hash' ] ) } >
178+ < MyWalletTransaction tx = { walletUtils . wallet . transactions [ tx ] } />
172179 </ TouchableOpacity >
173180 ) ) : null
174181 }
175182 </ ScrollView >
176183 < View style = { styles . navbar } >
177184 < TouchableOpacity
178- onPress = { ( ) => this . props . navigation . navigate ( 'WalletReceive' , { 'wallet' : wallet , 'password' : password , ' walletUtils' : this . walletUtils } ) }
185+ onPress = { ( ) => this . props . navigation . navigate ( 'WalletReceive' , { 'walletUtils' : walletUtils } ) }
179186 style = { styles . navbarIconButton } >
180187 < NavbarButton label = 'Receive' icon = 'login' />
181188 </ TouchableOpacity >
@@ -184,7 +191,7 @@ export default class MyWalletDetailsScreen extends React.Component {
184191 < NavbarButton label = 'Wallets' icon = 'wallet' />
185192 </ TouchableOpacity >
186193 < TouchableOpacity
187- onPress = { ( ) => this . props . navigation . navigate ( 'WalletSend' , { 'wallet' : wallet , 'password' : password , ' walletUtils' : this . walletUtils } ) }
194+ onPress = { ( ) => this . props . navigation . navigate ( 'WalletSend' , { 'walletUtils' : walletUtils } ) }
188195 style = { styles . navbarIconButton } >
189196 < NavbarButton label = 'Send' icon = 'log-out' />
190197 </ TouchableOpacity >
0 commit comments