fix onboarding bugs. tor no longer works, so i'm investigating.

This commit is contained in:
pokkst 2022-09-08 02:24:34 -05:00
parent 789d992deb
commit 602a57cbbe
No known key found for this signature in database
GPG key ID: 90C2ED85E67A50FF
6 changed files with 61 additions and 24 deletions

View file

@ -71,7 +71,6 @@ public class MainActivity extends AppCompatActivity implements MoneroHandlerThre
public void init(File walletFile, String password) {
Wallet wallet = WalletManager.getInstance().openWallet(walletFile.getAbsolutePath(), password);
WalletManager.getInstance().setProxy("127.0.0.1:9050");
thread = new MoneroHandlerThread("WalletService", wallet, this);
this.txService = new TxService(this, thread);
this.balanceService = new BalanceService(this, thread);

View file

@ -45,6 +45,7 @@ import java.util.Collections;
public class HomeFragment extends Fragment implements TransactionInfoAdapter.TxInfoAdapterListener {
private HomeViewModel mViewModel;
long startHeight = 0;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@ -114,15 +115,20 @@ public class HomeFragment extends Fragment implements TransactionInfoAdapter.TxI
if(blockchainService != null) {
blockchainService.height.observe(getViewLifecycleOwner(), height -> {
Wallet wallet = WalletManager.getInstance().getWallet();
long daemonHeight = wallet.getDaemonBlockChainHeight();
int syncPct = (int)blockchainService.getSyncPercentage();
progressBar.setIndeterminate(height <= 1 || daemonHeight <= 0);
if(height > 1 && daemonHeight > 1) {
progressBar.setProgress(syncPct);
if(wallet.isSynchronized()) {
progressBar.setVisibility(View.INVISIBLE);
if (!wallet.isSynchronized()) {
if (startHeight == 0 && height != 1) {
startHeight = height;
}
long daemonHeight = blockchainService.getDaemonHeight();
long n = daemonHeight - height;
int x = 100 - Math.round(100f * n / (1f * daemonHeight - startHeight));
progressBar.setIndeterminate(height <= 1 || daemonHeight <= 0);
if (height > 1 && daemonHeight > 1) {
if (x == 0) x = 101; // indeterminate
progressBar.setProgress(x);
}
} else {
progressBar.setVisibility(View.INVISIBLE);
}
});
}

View file

@ -13,7 +13,10 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.fragment.NavHostFragment;
import com.m2049r.xmrwallet.MainActivity;
import com.m2049r.xmrwallet.R;
@ -40,6 +43,7 @@ public class OnboardingFragment extends Fragment {
mViewModel = new ViewModelProvider(this).get(OnboardingViewModel.class);
EditText walletPasswordEditText = view.findViewById(R.id.wallet_password_edittext);
EditText walletSeedEditText = view.findViewById(R.id.wallet_seed_edittext);
EditText walletRestoreHeightEditText = view.findViewById(R.id.wallet_restore_height_edittext);
Button createWalletButton = view.findViewById(R.id.create_wallet_button);
createWalletButton.setOnClickListener(view1 -> {
String walletPassword = walletPasswordEditText.getText().toString();
@ -47,20 +51,29 @@ public class OnboardingFragment extends Fragment {
PrefService.getInstance().edit().putBoolean(Constants.PREF_USES_PASSWORD, true).apply();
}
String walletSeed = walletSeedEditText.getText().toString().trim();
String restoreHeightText = walletRestoreHeightEditText.getText().toString().trim();
long restoreHeight = -1;
File walletFile = new File(getActivity().getApplicationInfo().dataDir, Constants.WALLET_NAME);
Wallet wallet = null;
if(walletSeed.isEmpty()) {
wallet = WalletManager.getInstance().createWallet(walletFile, walletPassword, Constants.MNEMONIC_LANGUAGE, 1);
wallet = WalletManager.getInstance().createWallet(walletFile, walletPassword, Constants.MNEMONIC_LANGUAGE, restoreHeight);
} else {
if(!checkMnemonic(walletSeed)) {
Toast.makeText(getContext(), getString(R.string.invalid_mnemonic_code), Toast.LENGTH_SHORT).show();
return;
}
wallet = WalletManager.getInstance().recoveryWallet(walletFile, walletPassword, walletSeed, "", 0);
if(!restoreHeightText.isEmpty()) {
restoreHeight = Long.parseLong(restoreHeightText);
}
wallet = WalletManager.getInstance().recoveryWallet(walletFile, walletPassword, walletSeed, "", restoreHeight);
}
boolean ok = wallet.getStatus().isOk();
walletFile.delete(); // cache is broken for some reason when recovering wallets. delete the file here. this happens in monerujo too.
if(ok) {
((MainActivity)getActivity()).init(walletFile, walletPassword);
getActivity().onBackPressed();
}
wallet.close();
((MainActivity)getActivity()).init(walletFile, walletPassword);
getActivity().onBackPressed();
});
walletSeedEditText.addTextChangedListener(new TextWatcher() {
@Override
@ -83,4 +96,16 @@ public class OnboardingFragment extends Fragment {
private boolean checkMnemonic(String seed) {
return (seed.split("\\s").length == 25);
}
private void navigate(int destination) {
FragmentActivity activity = getActivity();
if (activity != null) {
FragmentManager fm = activity.getSupportFragmentManager();
NavHostFragment navHostFragment =
(NavHostFragment) fm.findFragmentById(R.id.nav_host_fragment);
if (navHostFragment != null) {
navHostFragment.getNavController().navigate(destination);
}
}
}
}

View file

@ -32,9 +32,4 @@ public class BlockchainService extends ServiceBase {
public long getDaemonHeight() {
return WalletManager.getInstance().getWallet().getDaemonBlockChainHeight();
}
public double getSyncPercentage() {
double percentRaw = (double)getCurrentHeight()/(double)getDaemonHeight();
return percentRaw * 100d;
}
}

View file

@ -53,7 +53,9 @@ public class MoneroHandlerThread extends Thread implements WalletListener {
@Override
public void run() {
WalletManager.getInstance().setProxy("127.0.0.1:9050");
WalletManager.getInstance().setDaemon(Node.fromString(DefaultNodes.XMRTW.getUri()));
wallet.setProxy("127.0.0.1:9050");
wallet.init(0);
wallet.setListener(this);
wallet.startRefresh();
@ -73,9 +75,7 @@ public class MoneroHandlerThread extends Thread implements WalletListener {
@Override
public void newBlock(long height) {
if (height % 1000 == 0) {
refresh();
}
refresh();
}
@Override

View file

@ -26,8 +26,20 @@
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginEnd="12dp"
android:layout_marginBottom="32dp"
android:hint="Recovery phrase (optional)"
android:inputType="textPassword"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@id/wallet_restore_height_edittext"
tools:visibility="visible"/>
<EditText
android:id="@+id/wallet_restore_height_edittext"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginEnd="12dp"
android:hint="Restore height (optional)"
android:inputType="number"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@id/create_wallet_button"
@ -40,6 +52,6 @@
android:layout_marginEnd="24dp"
android:layout_marginTop="32dp"
android:text="@string/create_wallet"
app:layout_constraintTop_toBottomOf="@id/wallet_seed_edittext"
app:layout_constraintTop_toBottomOf="@id/wallet_restore_height_edittext"
app:layout_constraintStart_toStartOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>