ResetTransactionsSubmitAction extends MultiBitSubmitAction { @Override public void actionPerformed(ActionEvent event) { if (abort()) { return; } setEnabled(false); WalletData activePerWalletModelData = super.bitcoinController.getModel().getActivePerWalletModelData(); Date earliestTransactionDate = new Date(DateUtils.nowUtc().getMillis()); Set<Transaction> allTransactions = activePerWalletModelData.getWallet().getTransactions(true); if (allTransactions != null) { for (Transaction transaction : allTransactions) { if (transaction != null) { Date updateTime = transaction.getUpdateTime(); if (updateTime != null && earliestTransactionDate.after(updateTime)) { earliestTransactionDate = updateTime; } } } } Date actualResetDate = earliestTransactionDate; long earliestKeyCreationTime = activePerWalletModelData.getWallet().getEarliestKeyCreationTime() * NUMBER_OF_MILLISECOND_IN_A_SECOND; if (earliestKeyCreationTime != 0 && earliestKeyCreationTime < earliestTransactionDate.getTime()) { earliestTransactionDate = new Date(earliestKeyCreationTime); actualResetDate = earliestTransactionDate; } actualResetDate = new Date (actualResetDate.getTime() - 3600 * 24 * NUMBER_OF_MILLISECOND_IN_A_SECOND); activePerWalletModelData.getWallet().clearTransactions(actualResetDate); try { super.bitcoinController.getFileHandler().savePerWalletModelData(activePerWalletModelData, true); super.bitcoinController.getModel().createWalletTableData(super.bitcoinController, super.bitcoinController.getModel().getActiveWalletFilename()); controller.fireRecreateAllViews(false); } catch (WalletSaveException wse) { log.error(wse.getClass().getCanonicalName() + " " + wse.getMessage()); MessageManager.INSTANCE.addMessage(new Message(wse.getClass().getCanonicalName() + " " + wse.getMessage())); } WalletData perWalletModelData = this.bitcoinController.getModel().getActivePerWalletModelData(); if (!perWalletModelData.isBusy()) { perWalletModelData.setBusy(true); perWalletModelData.setBusyTaskKey("resetTransactionsSubmitAction.text"); perWalletModelData.setBusyTaskVerbKey("resetTransactionsSubmitAction.verb"); super.bitcoinController.fireWalletBusyChange(true); resetTransactionsInBackground(actualResetDate, activePerWalletModelData.getWalletFilename()); } } ResetTransactionsSubmitAction(BitcoinController bitcoinController, MultiBitFrame mainFrame, Icon icon); @Override void actionPerformed(ActionEvent event);  }
@Test public void testNoWalletSelected() throws Exception { final CreateControllers.Controllers controllers = CreateControllers.createControllers(); BitcoinController controller = controllers.bitcoinController; assertTrue("There was an active wallet when there should not be", controller.getModel().thereIsNoActiveWallet()); FontSizer.INSTANCE.initialise(controller); ResetTransactionsPanel resetTransactionsPanel = new ResetTransactionsPanel(controller, null); ResetTransactionsSubmitAction resetTransactionsSubmitAction = resetTransactionsPanel.getResetTransactionsSubmitAction(); assertNotNull("resetTransactionsSubmitAction was not created successfully", resetTransactionsSubmitAction); resetTransactionsSubmitAction.actionPerformed(null); Object[] messages = MessageManager.INSTANCE.getMessages().toArray(); assertTrue("There were no messages but there should have been", messages != null && messages.length > 0); assertEquals("Wrong message after reset transactions with no active wallet", EXPECTED_NO_WALLET_IS_SELECTED, ((Message)messages[messages.length - 1]).getText()); }