Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DDW-221] Prevent wallet data polling during wallet deletion #996

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Changelog
- Fixed Linux Kanji characters support ([PR 971](https://github.com/input-output-hk/daedalus/pull/971))
- Removed the Ada Redemption link from the 'app bar' menu and added it to system menu ([PR 972](https://github.com/input-output-hk/daedalus/pull/972))
- Fixed the button outline color on special buttons. ([PR 990](https://github.com/input-output-hk/daedalus/pull/990))
- Prevented wallet data polling during wallet deletion ([PR 996]https://github.com/input-output-hk/daedalus/pull/996)

### Chores

Expand Down
34 changes: 30 additions & 4 deletions source/renderer/app/stores/ada/AdaWalletsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default class AdaWalletsStore extends WalletStore {
const { router, walletBackup, ada } = this.actions;
const { wallets } = ada;
wallets.createWallet.listen(this._create);
wallets.deleteWallet.listen(this._delete);
wallets.deleteWallet.listen(this._deleteWallet);
wallets.sendMoney.listen(this._sendMoney);
wallets.restoreWallet.listen(this._restoreWallet);
wallets.importWalletFromFile.listen(this._importWalletFromFile);
Expand Down Expand Up @@ -143,6 +143,32 @@ export default class AdaWalletsStore extends WalletStore {
}
};

_deleteWallet = async (params: { walletId: string }) => {
// Pause polling in order to avoid fetching data for wallet we are about to delete
this._pausePolling();

const walletToDelete = this.getWalletById(params.walletId);
if (!walletToDelete) return;
const indexOfWalletToDelete = this.all.indexOf(walletToDelete);
await this.deleteWalletRequest.execute({ walletId: params.walletId });
await this.walletsRequest.patch(result => {
result.splice(indexOfWalletToDelete, 1);
});
runInAction('AdaWalletsStore::_deleteWallet', () => {
if (this.hasAnyWallets) {
const nextIndexInList = Math.max(indexOfWalletToDelete - 1, 0);
const nextWalletInList = this.all[nextIndexInList];
this.actions.dialogs.closeActiveDialog.trigger();
this.goToWalletRoute(nextWalletInList.id);
} else {
this.active = null;
}
});
this._resumePolling();
this.deleteWalletRequest.reset();
this.refreshWalletsData();
};

@action _setIsRestoreActive = (active: boolean) => {
this.isRestoreActive = active;
};
Expand Down Expand Up @@ -232,15 +258,15 @@ export default class AdaWalletsStore extends WalletStore {
}
};

_pausePolling = () => {
@action _pausePolling = () => {
this._pollingBlocked = true;
};

_resumePolling = () => {
@action _resumePolling = () => {
this._pollingBlocked = false;
};

_generateCertificate = async (params: {
@action _generateCertificate = async (params: {
filePath: string,
}) => {
try {
Expand Down