thunderbiscuit / padawan-wallet

The bitcoin wallet trainer on Android.
https://padawanwallet.com/
Apache License 2.0
114 stars 50 forks source link

Wallet sync doesn't check for network connection #194

Closed thunderbiscuit closed 1 year ago

thunderbiscuit commented 2 years ago

I believe this is a regression introduced in #165.

The sync button uses this code to sync:

        binding.syncButton.setOnClickListener {
            when (isNetworkAvailable(requireContext())) {
                true -> {
                    viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO) {
                        syncWallet()
                    }
                }
                false -> fireSnackbar(requireView(), SnackbarLevel.WARNING, "Network connection currently not available")
            }
        }

But the onCreateView calls the sync coroutine directly, without checking for network availability first:

        viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO) {
            syncWallet()
        }
thunderbiscuit commented 2 years ago

I can't quite reproduce it because of the bug described in #192 which is taking precedence, but I noticed it while investigating that issue. Opening this just to keep track of it.

masterchief164 commented 2 years ago

Try launching the app with both wifi and cellular data turned off

thunderbiscuit commented 2 years ago

Yeah I'm able to make it crash, but I think it's because of the issue in 192, not because of this one here I don't think (attempting the sync without network access). For example you can try adding the check for network to the initial sync when onCreateView gets called, but the app will crash with the same error.

thunderbiscuit commented 1 year ago

Fixed!