Search in sources :

Example 1 with DialogBuilder

use of de.schildbach.wallet.ui.DialogBuilder in project bitcoin-wallet by bitcoin-wallet.

the class RestoreWalletDialogFragment method restorePrivateKeysFromBase58.

private void restorePrivateKeysFromBase58(final File file) {
    try (final FileInputStream is = new FileInputStream(file)) {
        restoreWallet(WalletUtils.restorePrivateKeysFromBase58(is, Constants.NETWORK_PARAMETERS));
        log.info("successfully restored unencrypted private keys: {}", file);
    } catch (final IOException x) {
        final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.import_export_keys_dialog_failure_title);
        dialog.setMessage(getString(R.string.import_keys_dialog_failure, x.getMessage()));
        dialog.setPositiveButton(R.string.button_dismiss, null);
        dialog.setNegativeButton(R.string.button_retry, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(final DialogInterface dialog, final int id) {
                show(activity.getSupportFragmentManager());
            }
        });
        dialog.show();
        log.info("problem restoring private keys: " + file, x);
    }
}
Also used : DialogInterface(android.content.DialogInterface) OnClickListener(android.content.DialogInterface.OnClickListener) IOException(java.io.IOException) DialogBuilder(de.schildbach.wallet.ui.DialogBuilder) FileInputStream(java.io.FileInputStream)

Example 2 with DialogBuilder

use of de.schildbach.wallet.ui.DialogBuilder in project bitcoin-wallet by bitcoin-wallet.

the class RestoreWalletDialogFragment method restoreWalletFromProtobuf.

private void restoreWalletFromProtobuf(final File file) {
    try (final FileInputStream is = new FileInputStream(file)) {
        restoreWallet(WalletUtils.restoreWalletFromProtobuf(is, Constants.NETWORK_PARAMETERS));
        log.info("successfully restored unencrypted wallet: {}", file);
    } catch (final IOException x) {
        final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.import_export_keys_dialog_failure_title);
        dialog.setMessage(getString(R.string.import_keys_dialog_failure, x.getMessage()));
        dialog.setPositiveButton(R.string.button_dismiss, null);
        dialog.setNegativeButton(R.string.button_retry, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(final DialogInterface dialog, final int id) {
                show(activity.getSupportFragmentManager());
            }
        });
        dialog.show();
        log.info("problem restoring unencrypted wallet: " + file, x);
    }
}
Also used : DialogInterface(android.content.DialogInterface) OnClickListener(android.content.DialogInterface.OnClickListener) IOException(java.io.IOException) DialogBuilder(de.schildbach.wallet.ui.DialogBuilder) FileInputStream(java.io.FileInputStream)

Example 3 with DialogBuilder

use of de.schildbach.wallet.ui.DialogBuilder in project bitcoin-wallet by bitcoin-wallet.

the class RestoreWalletDialogFragment method restoreWalletFromEncrypted.

private void restoreWalletFromEncrypted(final File file, final String password) {
    try {
        final BufferedReader cipherIn = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
        final StringBuilder cipherText = new StringBuilder();
        Io.copy(cipherIn, cipherText, Constants.BACKUP_MAX_CHARS);
        cipherIn.close();
        final byte[] plainText = Crypto.decryptBytes(cipherText.toString(), password.toCharArray());
        final InputStream is = new ByteArrayInputStream(plainText);
        restoreWallet(WalletUtils.restoreWalletFromProtobufOrBase58(is, Constants.NETWORK_PARAMETERS));
        log.info("successfully restored encrypted wallet: {}", file);
    } catch (final IOException x) {
        final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.import_export_keys_dialog_failure_title);
        dialog.setMessage(getString(R.string.import_keys_dialog_failure, x.getMessage()));
        dialog.setPositiveButton(R.string.button_dismiss, null);
        dialog.setNegativeButton(R.string.button_retry, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(final DialogInterface dialog, final int id) {
                show(activity.getSupportFragmentManager());
            }
        });
        dialog.show();
        log.info("problem restoring wallet: " + file, x);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) DialogInterface(android.content.DialogInterface) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) OnClickListener(android.content.DialogInterface.OnClickListener) IOException(java.io.IOException) DialogBuilder(de.schildbach.wallet.ui.DialogBuilder) FileInputStream(java.io.FileInputStream)

Example 4 with DialogBuilder

use of de.schildbach.wallet.ui.DialogBuilder in project bitcoin-wallet by bitcoin-wallet.

the class RestoreWalletDialogFragment method restoreWallet.

private void restoreWallet(final Wallet wallet) throws IOException {
    application.replaceWallet(wallet);
    config.disarmBackupReminder();
    final DialogBuilder dialog = new DialogBuilder(activity);
    final StringBuilder message = new StringBuilder();
    message.append(getString(R.string.restore_wallet_dialog_success));
    message.append("\n\n");
    message.append(getString(R.string.restore_wallet_dialog_success_replay));
    if (wallet.isEncrypted()) {
        message.append("\n\n");
        message.append(getString(R.string.restore_wallet_dialog_success_encrypted));
    }
    dialog.setMessage(message);
    dialog.setNeutralButton(R.string.button_ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(final DialogInterface dialog, final int id) {
            BlockchainService.resetBlockchain(activity);
            activity.finish();
        }
    });
    dialog.show();
}
Also used : OnClickListener(android.content.DialogInterface.OnClickListener) DialogInterface(android.content.DialogInterface) DialogBuilder(de.schildbach.wallet.ui.DialogBuilder)

Example 5 with DialogBuilder

use of de.schildbach.wallet.ui.DialogBuilder in project bitcoin-wallet by bitcoin-wallet.

the class RestoreWalletFromExternalDialogFragment method handleRestore.

private void handleRestore(final String password) {
    try {
        final InputStream is = contentResolver.openInputStream(backupUri);
        restoreWalletFromEncrypted(is, password);
        config.disarmBackupReminder();
        log.info("successfully restored encrypted wallet from external source");
        final DialogBuilder dialog = new DialogBuilder(activity);
        final StringBuilder message = new StringBuilder();
        message.append(getString(R.string.restore_wallet_dialog_success));
        message.append("\n\n");
        message.append(getString(R.string.restore_wallet_dialog_success_replay));
        if (application.getWallet().isEncrypted()) {
            message.append("\n\n");
            message.append(getString(R.string.restore_wallet_dialog_success_encrypted));
        }
        dialog.setMessage(message);
        dialog.setNeutralButton(R.string.button_ok, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(final DialogInterface dialog, final int id) {
                BlockchainService.resetBlockchain(activity);
                activity.finish();
            }
        });
        dialog.show();
    } catch (final IOException x) {
        log.info("problem restoring wallet", x);
        final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.import_export_keys_dialog_failure_title);
        dialog.setMessage(getString(R.string.import_keys_dialog_failure, x.getMessage()));
        dialog.setPositiveButton(R.string.button_dismiss, finishListener).setOnCancelListener(finishListener);
        dialog.setNegativeButton(R.string.button_retry, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(final DialogInterface dialog, final int id) {
                show(activity.getSupportFragmentManager(), backupUri);
            }
        });
        dialog.show();
    }
}
Also used : OnClickListener(android.content.DialogInterface.OnClickListener) DialogInterface(android.content.DialogInterface) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OnClickListener(android.content.DialogInterface.OnClickListener) IOException(java.io.IOException) DialogBuilder(de.schildbach.wallet.ui.DialogBuilder)

Aggregations

DialogBuilder (de.schildbach.wallet.ui.DialogBuilder)20 DialogInterface (android.content.DialogInterface)8 View (android.view.View)8 OnClickListener (android.content.DialogInterface.OnClickListener)7 PaymentIntent (de.schildbach.wallet.data.PaymentIntent)7 TextView (android.widget.TextView)6 AlertDialog (android.app.AlertDialog)5 Transaction (org.bitcoinj.core.Transaction)5 StringInputParser (de.schildbach.wallet.ui.InputParser.StringInputParser)4 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 Coin (org.bitcoinj.core.Coin)4 VerificationException (org.bitcoinj.core.VerificationException)4 MonetaryFormat (org.bitcoinj.utils.MonetaryFormat)4 Wallet (org.bitcoinj.wallet.Wallet)4 FileInputStream (java.io.FileInputStream)3 Activity (android.app.Activity)2 Context (android.content.Context)2 Intent (android.content.Intent)2 PackageManager (android.content.pm.PackageManager)2