From ba3dd0c87ad34433bcb5e9bfe59eca0bcb8bd865 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Wed, 23 May 2018 13:35:42 +0100 Subject: [PATCH] Refactor onOk to async function --- .../views/dialogs/DeactivateAccountDialog.js | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/components/views/dialogs/DeactivateAccountDialog.js b/src/components/views/dialogs/DeactivateAccountDialog.js index 87228b4733..f41f37e075 100644 --- a/src/components/views/dialogs/DeactivateAccountDialog.js +++ b/src/components/views/dialogs/DeactivateAccountDialog.js @@ -47,19 +47,17 @@ export default class DeactivateAccountDialog extends React.Component { }); } - _onOk() { + async _onOk() { // This assumes that the HS requires password UI auth // for this endpoint. In reality it could be any UI auth. this.setState({busy: true}); - MatrixClientPeg.get().deactivateAccount({ - type: 'm.login.password', - user: MatrixClientPeg.get().credentials.userId, - password: this._passwordField.value, - }).done(() => { - Analytics.trackEvent('Account', 'Deactivate Account'); - Lifecycle.onLoggedOut(); - this.props.onFinished(false); - }, (err) => { + try { + await MatrixClientPeg.get().deactivateAccount({ + type: 'm.login.password', + user: MatrixClientPeg.get().credentials.userId, + password: this._passwordField.value, + }); + } catch (err) { let errStr = _t('Unknown error'); // https://matrix.org/jira/browse/SYN-744 if (err.httpStatus == 401 || err.httpStatus == 403) { @@ -70,7 +68,11 @@ export default class DeactivateAccountDialog extends React.Component { busy: false, errStr: errStr, }); - }); + return; + } + Analytics.trackEvent('Account', 'Deactivate Account'); + Lifecycle.onLoggedOut(); + this.props.onFinished(false); } _onCancel() {