mirror of
https://codeberg.org/r4v3r23/mysu.git
synced 2024-11-09 20:53:47 +01:00
fix onboarding bugs. tor no longer works, so i'm investigating.
This commit is contained in:
parent
789d992deb
commit
602a57cbbe
@ -71,7 +71,6 @@ public class MainActivity extends AppCompatActivity implements MoneroHandlerThre
|
|||||||
|
|
||||||
public void init(File walletFile, String password) {
|
public void init(File walletFile, String password) {
|
||||||
Wallet wallet = WalletManager.getInstance().openWallet(walletFile.getAbsolutePath(), password);
|
Wallet wallet = WalletManager.getInstance().openWallet(walletFile.getAbsolutePath(), password);
|
||||||
WalletManager.getInstance().setProxy("127.0.0.1:9050");
|
|
||||||
thread = new MoneroHandlerThread("WalletService", wallet, this);
|
thread = new MoneroHandlerThread("WalletService", wallet, this);
|
||||||
this.txService = new TxService(this, thread);
|
this.txService = new TxService(this, thread);
|
||||||
this.balanceService = new BalanceService(this, thread);
|
this.balanceService = new BalanceService(this, thread);
|
||||||
|
@ -45,6 +45,7 @@ import java.util.Collections;
|
|||||||
public class HomeFragment extends Fragment implements TransactionInfoAdapter.TxInfoAdapterListener {
|
public class HomeFragment extends Fragment implements TransactionInfoAdapter.TxInfoAdapterListener {
|
||||||
|
|
||||||
private HomeViewModel mViewModel;
|
private HomeViewModel mViewModel;
|
||||||
|
long startHeight = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||||
@ -114,15 +115,20 @@ public class HomeFragment extends Fragment implements TransactionInfoAdapter.TxI
|
|||||||
if(blockchainService != null) {
|
if(blockchainService != null) {
|
||||||
blockchainService.height.observe(getViewLifecycleOwner(), height -> {
|
blockchainService.height.observe(getViewLifecycleOwner(), height -> {
|
||||||
Wallet wallet = WalletManager.getInstance().getWallet();
|
Wallet wallet = WalletManager.getInstance().getWallet();
|
||||||
long daemonHeight = wallet.getDaemonBlockChainHeight();
|
if (!wallet.isSynchronized()) {
|
||||||
int syncPct = (int)blockchainService.getSyncPercentage();
|
if (startHeight == 0 && height != 1) {
|
||||||
progressBar.setIndeterminate(height <= 1 || daemonHeight <= 0);
|
startHeight = height;
|
||||||
if(height > 1 && daemonHeight > 1) {
|
|
||||||
progressBar.setProgress(syncPct);
|
|
||||||
|
|
||||||
if(wallet.isSynchronized()) {
|
|
||||||
progressBar.setVisibility(View.INVISIBLE);
|
|
||||||
}
|
}
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,10 @@ import android.widget.Toast;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
import androidx.navigation.fragment.NavHostFragment;
|
||||||
|
|
||||||
import com.m2049r.xmrwallet.MainActivity;
|
import com.m2049r.xmrwallet.MainActivity;
|
||||||
import com.m2049r.xmrwallet.R;
|
import com.m2049r.xmrwallet.R;
|
||||||
@ -40,6 +43,7 @@ public class OnboardingFragment extends Fragment {
|
|||||||
mViewModel = new ViewModelProvider(this).get(OnboardingViewModel.class);
|
mViewModel = new ViewModelProvider(this).get(OnboardingViewModel.class);
|
||||||
EditText walletPasswordEditText = view.findViewById(R.id.wallet_password_edittext);
|
EditText walletPasswordEditText = view.findViewById(R.id.wallet_password_edittext);
|
||||||
EditText walletSeedEditText = view.findViewById(R.id.wallet_seed_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);
|
Button createWalletButton = view.findViewById(R.id.create_wallet_button);
|
||||||
createWalletButton.setOnClickListener(view1 -> {
|
createWalletButton.setOnClickListener(view1 -> {
|
||||||
String walletPassword = walletPasswordEditText.getText().toString();
|
String walletPassword = walletPasswordEditText.getText().toString();
|
||||||
@ -47,20 +51,29 @@ public class OnboardingFragment extends Fragment {
|
|||||||
PrefService.getInstance().edit().putBoolean(Constants.PREF_USES_PASSWORD, true).apply();
|
PrefService.getInstance().edit().putBoolean(Constants.PREF_USES_PASSWORD, true).apply();
|
||||||
}
|
}
|
||||||
String walletSeed = walletSeedEditText.getText().toString().trim();
|
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);
|
File walletFile = new File(getActivity().getApplicationInfo().dataDir, Constants.WALLET_NAME);
|
||||||
Wallet wallet = null;
|
Wallet wallet = null;
|
||||||
if(walletSeed.isEmpty()) {
|
if(walletSeed.isEmpty()) {
|
||||||
wallet = WalletManager.getInstance().createWallet(walletFile, walletPassword, Constants.MNEMONIC_LANGUAGE, 1);
|
wallet = WalletManager.getInstance().createWallet(walletFile, walletPassword, Constants.MNEMONIC_LANGUAGE, restoreHeight);
|
||||||
} else {
|
} else {
|
||||||
if(!checkMnemonic(walletSeed)) {
|
if(!checkMnemonic(walletSeed)) {
|
||||||
Toast.makeText(getContext(), getString(R.string.invalid_mnemonic_code), Toast.LENGTH_SHORT).show();
|
Toast.makeText(getContext(), getString(R.string.invalid_mnemonic_code), Toast.LENGTH_SHORT).show();
|
||||||
return;
|
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() {
|
walletSeedEditText.addTextChangedListener(new TextWatcher() {
|
||||||
@Override
|
@Override
|
||||||
@ -83,4 +96,16 @@ public class OnboardingFragment extends Fragment {
|
|||||||
private boolean checkMnemonic(String seed) {
|
private boolean checkMnemonic(String seed) {
|
||||||
return (seed.split("\\s").length == 25);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -32,9 +32,4 @@ public class BlockchainService extends ServiceBase {
|
|||||||
public long getDaemonHeight() {
|
public long getDaemonHeight() {
|
||||||
return WalletManager.getInstance().getWallet().getDaemonBlockChainHeight();
|
return WalletManager.getInstance().getWallet().getDaemonBlockChainHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getSyncPercentage() {
|
|
||||||
double percentRaw = (double)getCurrentHeight()/(double)getDaemonHeight();
|
|
||||||
return percentRaw * 100d;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,9 @@ public class MoneroHandlerThread extends Thread implements WalletListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
WalletManager.getInstance().setProxy("127.0.0.1:9050");
|
||||||
WalletManager.getInstance().setDaemon(Node.fromString(DefaultNodes.XMRTW.getUri()));
|
WalletManager.getInstance().setDaemon(Node.fromString(DefaultNodes.XMRTW.getUri()));
|
||||||
|
wallet.setProxy("127.0.0.1:9050");
|
||||||
wallet.init(0);
|
wallet.init(0);
|
||||||
wallet.setListener(this);
|
wallet.setListener(this);
|
||||||
wallet.startRefresh();
|
wallet.startRefresh();
|
||||||
@ -73,9 +75,7 @@ public class MoneroHandlerThread extends Thread implements WalletListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void newBlock(long height) {
|
public void newBlock(long height) {
|
||||||
if (height % 1000 == 0) {
|
refresh();
|
||||||
refresh();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -26,8 +26,20 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="24dp"
|
android:layout_marginStart="24dp"
|
||||||
android:layout_marginEnd="12dp"
|
android:layout_marginEnd="12dp"
|
||||||
|
android:layout_marginBottom="32dp"
|
||||||
android:hint="Recovery phrase (optional)"
|
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_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintBottom_toTopOf="@id/create_wallet_button"
|
app:layout_constraintBottom_toTopOf="@id/create_wallet_button"
|
||||||
@ -40,6 +52,6 @@
|
|||||||
android:layout_marginEnd="24dp"
|
android:layout_marginEnd="24dp"
|
||||||
android:layout_marginTop="32dp"
|
android:layout_marginTop="32dp"
|
||||||
android:text="@string/create_wallet"
|
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"/>
|
app:layout_constraintStart_toStartOf="parent"/>
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Reference in New Issue
Block a user