reset wallet by deleting wallet cache file (#751)

This commit is contained in:
m2049r 2021-04-20 13:06:14 +02:00 committed by GitHub
parent b39857fd2e
commit c7bd7469a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 129 additions and 15 deletions

View File

@ -557,6 +557,31 @@ public class LoginActivity extends BaseActivity
.show();
}
@Override
public void onWalletDeleteCache(final String walletName) {
Timber.d("delete cache for wallet ." + walletName + ".");
if (checkServiceRunning()) return;
DialogInterface.OnClickListener dialogClickListener = (dialog, which) -> {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
if (!deleteWalletCache(Helper.getWalletFile(LoginActivity.this, walletName))) {
Toast.makeText(LoginActivity.this, getString(R.string.delete_failed), Toast.LENGTH_LONG).show();
}
break;
case DialogInterface.BUTTON_NEGATIVE:
// do nothing
break;
}
};
AlertDialog.Builder builder = new MaterialAlertDialogBuilder(this);
builder.setMessage(getString(R.string.deletecache_alert_message, walletName))
.setTitle(walletName)
.setPositiveButton(getString(R.string.delete_alert_yes), dialogClickListener)
.setNegativeButton(getString(R.string.delete_alert_no), dialogClickListener)
.show();
}
void reloadWalletList() {
Timber.d("reloadWalletList()");
try {
@ -1024,6 +1049,18 @@ public class LoginActivity extends BaseActivity
return success;
}
boolean deleteWalletCache(File walletFile) {
Timber.d("deleteWalletCache %s", walletFile.getAbsolutePath());
File dir = walletFile.getParentFile();
String name = walletFile.getName();
boolean success = true;
File cacheFile = new File(dir, name);
if (cacheFile.exists()) {
success = cacheFile.delete();
}
return success;
}
void copyFile(File src, File dst) throws IOException {
try (FileChannel inChannel = new FileInputStream(src).getChannel();
FileChannel outChannel = new FileOutputStream(dst).getChannel()) {

View File

@ -88,6 +88,8 @@ public class LoginFragment extends Fragment implements WalletInfoAdapter.OnInter
void onWalletDelete(String walletName);
void onWalletDeleteCache(String walletName);
void onAddWallet(String type);
void onNodePrefs();
@ -220,6 +222,8 @@ public class LoginFragment extends Fragment implements WalletInfoAdapter.OnInter
activityCallback.onWalletBackup(listItem.getName());
} else if (id == R.id.action_archive) {
activityCallback.onWalletDelete(listItem.getName());
} else if (id == R.id.action_deletecache) {
activityCallback.onWalletDeleteCache(listItem.getName());
} else {
return super.onContextItemSelected(item);
}

View File

@ -167,7 +167,7 @@ public class ExchangeApiImpl implements ExchangeApi {
private Calendar fetchDate = null;
synchronized private ExchangeRate getRate(String currency) throws ExchangeException {
Timber.e("Getting %s", currency);
Timber.d("Getting %s", currency);
final Double rate = fxEntries.get(currency);
if (rate == null) throw new ExchangeException(404, "Currency not supported: " + currency);
return new ExchangeRateImpl(currency, rate, fxDate.getTime());

View File

@ -26,4 +26,8 @@
android:orderInCategory="500"
android:title="@string/menu_info" />
<item
android:id="@+id/action_deletecache"
android:orderInCategory="500"
android:title="@string/menu_deletecache" />
</menu>

View File

@ -417,10 +417,13 @@
<string name="subaddress_select_label">Select a subaddress</string>
<string name="subaddress_details_hint">Long-press for details</string>
<string name="delete_alert_message">The wallet will be deleted!</string>
<string name="delete_alert_message">This wallet will be deleted!</string>
<string name="menu_delete">Delete</string><!-- like: "Delete wallet!" -->
<string name="delete_failed">Delete failed!</string>
<string name="menu_restore">Import wallet</string>
<string name="restore_failed">Import failed!</string>
<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>
</resources>

View File

@ -424,4 +424,7 @@
<string name="menu_restore">Import wallet</string>
<string name="restore_failed">Import failed!</string>
<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>
</resources>

View File

@ -419,10 +419,13 @@
<string name="subaddress_select_label">Select a subaddress</string>
<string name="subaddress_details_hint">Long-press for details</string>
<string name="delete_alert_message">The wallet will be deleted!</string>
<string name="delete_alert_message">This wallet will be deleted!</string>
<string name="menu_delete">Delete</string><!-- like: "Delete wallet!" -->
<string name="delete_failed">Delete failed!</string>
<string name="menu_restore">Import wallet</string>
<string name="restore_failed">Import failed!</string>
<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>
</resources>

View File

@ -419,10 +419,13 @@
<string name="subaddress_select_label">Select a subaddress</string>
<string name="subaddress_details_hint">Long-press for details</string>
<string name="delete_alert_message">The wallet will be deleted!</string>
<string name="delete_alert_message">This wallet will be deleted!</string>
<string name="menu_delete">Delete</string><!-- like: "Delete wallet!" -->
<string name="delete_failed">Delete failed!</string>
<string name="menu_restore">Import wallet</string>
<string name="restore_failed">Import failed!</string>
<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>
</resources>

View File

@ -416,4 +416,7 @@
<string name="menu_restore">Import wallet</string>
<string name="restore_failed">Import failed!</string>
<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>
</resources>

View File

@ -417,10 +417,13 @@
<string name="subaddress_select_label">Select a subaddress</string>
<string name="subaddress_details_hint">Long-press for details</string>
<string name="delete_alert_message">The wallet will be deleted!</string>
<string name="delete_alert_message">This wallet will be deleted!</string>
<string name="menu_delete">Delete</string><!-- like: "Delete wallet!" -->
<string name="delete_failed">Delete failed!</string>
<string name="menu_restore">Import wallet</string>
<string name="restore_failed">Import failed!</string>
<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>
</resources>

View File

@ -429,4 +429,7 @@
<string name="menu_restore">Import wallet</string>
<string name="restore_failed">Import failed!</string>
<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>
</resources>

View File

@ -421,10 +421,13 @@
<string name="subaddress_select_label">Select a subaddress</string>
<string name="subaddress_details_hint">Long-press for details</string>
<string name="delete_alert_message">The wallet will be deleted!</string>
<string name="delete_alert_message">This wallet will be deleted!</string>
<string name="menu_delete">Delete</string><!-- like: "Delete wallet!" -->
<string name="delete_failed">Delete failed!</string>
<string name="menu_restore">Import wallet</string>
<string name="restore_failed">Import failed!</string>
<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>
</resources>

View File

@ -428,4 +428,7 @@
<string name="menu_restore">Import wallet</string>
<string name="restore_failed">Import failed!</string>
<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>
</resources>

View File

@ -422,10 +422,13 @@
<string name="subaddress_select_label">Select a subaddress</string>
<string name="subaddress_details_hint">Long-press for details</string>
<string name="delete_alert_message">The wallet will be deleted!</string>
<string name="delete_alert_message">This wallet will be deleted!</string>
<string name="menu_delete">Delete</string><!-- like: "Delete wallet!" -->
<string name="delete_failed">Delete failed!</string>
<string name="menu_restore">Import wallet</string>
<string name="restore_failed">Import failed!</string>
<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>
</resources>

View File

@ -419,10 +419,13 @@
<string name="subaddress_select_label">Select a subaddress</string>
<string name="subaddress_details_hint">Long-press for details</string>
<string name="delete_alert_message">The wallet will be deleted!</string>
<string name="delete_alert_message">This wallet will be deleted!</string>
<string name="menu_delete">Delete</string><!-- like: "Delete wallet!" -->
<string name="delete_failed">Delete failed!</string>
<string name="menu_restore">Import wallet</string>
<string name="restore_failed">Import failed!</string>
<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>
</resources>

View File

@ -425,4 +425,7 @@
<string name="menu_restore">Import wallet</string>
<string name="restore_failed">Import failed!</string>
<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>
</resources>

View File

@ -411,10 +411,13 @@
<string name="subaddress_select_label">Selecione um subendereço</string>
<string name="subaddress_details_hint">Toque e segure para mais detalhes</string>
<string name="delete_alert_message">The wallet will be deleted!</string>
<string name="delete_alert_message">This wallet will be deleted!</string>
<string name="menu_delete">Delete</string><!-- like: "Delete wallet!" -->
<string name="delete_failed">Delete failed!</string>
<string name="menu_restore">Import wallet</string>
<string name="restore_failed">Import failed!</string>
<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>
</resources>

View File

@ -423,10 +423,13 @@
<string name="subaddress_select_label">Select a subaddress</string>
<string name="subaddress_details_hint">Long-press for details</string>
<string name="delete_alert_message">The wallet will be deleted!</string>
<string name="delete_alert_message">This wallet will be deleted!</string>
<string name="menu_delete">Delete</string><!-- like: "Delete wallet!" -->
<string name="delete_failed">Delete failed!</string>
<string name="menu_restore">Import wallet</string>
<string name="restore_failed">Import failed!</string>
<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>
</resources>

View File

@ -419,10 +419,13 @@
<string name="subaddress_select_label">Selectează o subadresă</string>
<string name="subaddress_details_hint">Atinge lung pentru detalii</string>
<string name="delete_alert_message">The wallet will be deleted!</string>
<string name="delete_alert_message">This wallet will be deleted!</string>
<string name="menu_delete">Delete</string><!-- like: "Delete wallet!" -->
<string name="delete_failed">Delete failed!</string>
<string name="menu_restore">Import wallet</string>
<string name="restore_failed">Import failed!</string>
<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>
</resources>

View File

@ -429,4 +429,7 @@
<string name="menu_restore">Импортировать кошелек</string>
<string name="restore_failed">Ошибка импорта!</string>
<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>
</resources>

View File

@ -426,4 +426,7 @@
<string name="menu_restore">Import wallet</string>
<string name="restore_failed">Import failed!</string>
<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>
</resources>

View File

@ -424,4 +424,7 @@
<string name="menu_restore">Import wallet</string>
<string name="restore_failed">Import failed!</string>
<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>
</resources>

View File

@ -411,10 +411,13 @@
<string name="subaddress_select_label">Select a subaddress</string>
<string name="subaddress_details_hint">Long-press for details</string>
<string name="delete_alert_message">The wallet will be deleted!</string>
<string name="delete_alert_message">This wallet will be deleted!</string>
<string name="menu_delete">Delete</string><!-- like: "Delete wallet!" -->
<string name="delete_failed">Delete failed!</string>
<string name="menu_restore">Import wallet</string>
<string name="restore_failed">Import failed!</string>
<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>
</resources>

View File

@ -429,4 +429,7 @@
<string name="menu_restore">Import wallet</string>
<string name="restore_failed">Import failed!</string>
<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>
</resources>

View File

@ -343,10 +343,13 @@
<string name="subaddress_select_label">Select a subaddress</string>
<string name="subaddress_details_hint">Long-press for details</string>
<string name="delete_alert_message">The wallet will be deleted!</string>
<string name="delete_alert_message">This wallet will be deleted!</string>
<string name="menu_delete">Delete</string><!-- like: "Delete wallet!" -->
<string name="delete_failed">Delete failed!</string>
<string name="menu_restore">Import wallet</string>
<string name="restore_failed">Import failed!</string>
<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>
</resources>

View File

@ -418,10 +418,13 @@
<string name="subaddress_select_label">Select a subaddress</string>
<string name="subaddress_details_hint">Long-press for details</string>
<string name="delete_alert_message">The wallet will be deleted!</string>
<string name="delete_alert_message">This wallet will be deleted!</string>
<string name="menu_delete">Delete</string><!-- like: "Delete wallet!" -->
<string name="delete_failed">Delete failed!</string>
<string name="menu_restore">Import wallet</string>
<string name="restore_failed">Import failed!</string>
<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>
</resources>

View File

@ -278,7 +278,7 @@
<string name="details_alert_no">Take me back!</string>
<string name="details_title">Details</string>
<string name="delete_alert_message">The wallet will be deleted!</string>
<string name="delete_alert_message">This wallet will be deleted!</string>
<string name="delete_alert_yes">Yes, do that!</string>
<string name="delete_alert_no">No thanks!</string>
@ -497,4 +497,7 @@
<string name="menu_restore">Import wallet</string>
<string name="restore_failed">Import failed!</string>
<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>
</resources>