@@ -44,15 +44,15 @@ class IPFS extends React.Component {
4444 < Content >
4545 < Row >
4646 < Col sm = { 12 } >
47- < Box className = ' text-center ipfs-checkbox-container' >
47+ < Box className = " text-center ipfs-checkbox-container" >
4848 < Checkbox
49- id = ' ipfs-checkbox'
50- className = ' ipfs-checkbox'
49+ id = " ipfs-checkbox"
50+ className = " ipfs-checkbox"
5151 value = { ipfsConnection } // mark as checked
52- text = ' Connect to wallet services over IPFS'
53- labelPosition = ' none'
52+ text = " Connect to wallet services over IPFS"
53+ labelPosition = " none"
5454 labelXs = { 0 }
55- name = ' ipfsConnection'
55+ name = " ipfsConnection"
5656 onChange = { this . handleIpfs }
5757 />
5858 </ Box >
@@ -338,17 +338,68 @@ class IPFS extends React.Component {
338338
339339 _this . bchWalletLib = new _this . BchWallet ( mnemonic , advancedConfig )
340340
341- await _this . bchWalletLib . walletInfoPromise // Wait for wallet to be created.
342-
343- // If UTXOs fail to update, try one more time.
344- if ( ! _this . bchWalletLib . utxos . utxoStore ) {
345- await _this . bchWalletLib . getUtxos ( )
346-
347- // Throw an error if UTXOs are still not updated.
348- if ( ! _this . bchWalletLib . utxos . utxoStore ) {
349- throw new Error ( 'UTXOs failed to update. Try again.' )
341+ let utxosInitialized = false
342+ let cnt = 0
343+ do {
344+ cnt ++
345+
346+ try {
347+ // Wait for wallet to be created.
348+ await _this . bchWalletLib . walletInfoPromise
349+
350+ // await _this.bchWalletLib.bchjs.Util.sleep(5000)
351+ await _this . sleep ( 5000 )
352+
353+ const utxos = await _this . bchWalletLib . getUtxos ( )
354+ if ( _this . bchWalletLib . utxos . utxoStore ) {
355+ _this . onStatusLog (
356+ `utxo initialization succeeded: ${ JSON . stringify ( utxos , null , 2 ) } `
357+ )
358+ utxosInitialized = true
359+ } else {
360+ _this . onStatusLog (
361+ `Attempt ${ cnt } to re-initialize timed out. Will try again.`
362+ )
363+ }
364+ } catch ( err ) {
365+ _this . onStatusLog (
366+ `Attempt ${ cnt } to re-initialize wallet failed. Will try again.`
367+ )
368+ console . log ( err )
350369 }
351- }
370+ // } while (!utxosInitialized)
371+ } while ( ! utxosInitialized && cnt < 10 )
372+
373+ // console.log('_this.bchWalletLib: ', _this.bchWalletLib)
374+ //
375+ // setInterval(async function () {
376+ // const now = new Date()
377+ // console.log(`Getting UTXOs at ${now.toLocaleString()}`)
378+ // await _this.bchWalletLib.getUtxos()
379+ // console.log(
380+ // `_this.bchWalletLib.utxos.utxoStore: ${JSON.stringify(
381+ // _this.bchWalletLib.utxos.utxoStore,
382+ // null,
383+ // 2
384+ // )}`
385+ // )
386+ // }, 20000)
387+
388+ // let now = new Date()
389+ // console.log(`Starting at ${now.toLocaleString()}`)
390+ // await _this.bchWalletLib.bchjs.Util.sleep(5000)
391+ // now = new Date()
392+ // console.log(`Finished at ${now.toLocaleString()}`)
393+
394+ // // If UTXOs fail to update, try one more time.
395+ // if (!_this.bchWalletLib.utxos.utxoStore) {
396+ // await _this.bchWalletLib.getUtxos()
397+ //
398+ // // Throw an error if UTXOs are still not updated.
399+ // if (!_this.bchWalletLib.utxos.utxoStore) {
400+ // throw new Error('UTXOs failed to update. Try again.')
401+ // }
402+ // }
352403
353404 // Update redux state
354405 _this . props . setBchWallet ( _this . bchWalletLib )
0 commit comments