diff --git a/web/settings/password-change-modal.js b/web/settings/password-change-modal.js --- a/web/settings/password-change-modal.js +++ b/web/settings/password-change-modal.js @@ -6,6 +6,8 @@ import { changeKeyserverUserPasswordActionTypes, changeKeyserverUserPassword, + useChangeIdentityUserPassword, + changeIdentityUserPasswordActionTypes, } from 'lib/actions/user-actions.js'; import { useModalContext } from 'lib/components/modal-provider.react.js'; import { useStringForUser } from 'lib/hooks/ens-cache.js'; @@ -16,6 +18,7 @@ useDispatchActionPromise, type DispatchActionPromise, } from 'lib/utils/redux-promise-utils.js'; +import { usingCommServicesAccessToken } from 'lib/utils/services-utils.js'; import css from './password-change-modal.css'; import Button from '../components/button.react.js'; @@ -29,6 +32,10 @@ +changeKeyserverUserPassword: ( passwordUpdate: PasswordUpdate, ) => Promise, + +changeIdentityUserPassword: ( + oldPassword: string, + newPassword: string, + ) => Promise, +popModal: () => void, +stringForUser: ?string, }; @@ -186,20 +193,34 @@ return; } - void this.props.dispatchActionPromise( - changeKeyserverUserPasswordActionTypes, - this.changeUserSettingsAction(), - ); + if (usingCommServicesAccessToken) { + void this.props.dispatchActionPromise( + changeIdentityUserPasswordActionTypes, + this.changeUserSettingsAction(), + ); + } else { + void this.props.dispatchActionPromise( + changeKeyserverUserPasswordActionTypes, + this.changeUserSettingsAction(), + ); + } }; async changeUserSettingsAction(): Promise { try { - await this.props.changeKeyserverUserPassword({ - updatedFields: { - password: this.state.newPassword, - }, - currentPassword: this.state.currentPassword, - }); + if (usingCommServicesAccessToken) { + await this.props.changeIdentityUserPassword( + this.state.currentPassword, + this.state.newPassword, + ); + } else { + await this.props.changeKeyserverUserPassword({ + updatedFields: { + password: this.state.newPassword, + }, + currentPassword: this.state.currentPassword, + }); + } this.props.popModal(); } catch (e) { if (e.message === 'invalid_credentials') { @@ -235,17 +256,18 @@ } } -const changeKeyserverUserPasswordLoadingStatusSelector = - createLoadingStatusSelector(changeKeyserverUserPasswordActionTypes); +const changeUserPasswordLoadingStatusSelector = usingCommServicesAccessToken + ? createLoadingStatusSelector(changeIdentityUserPasswordActionTypes) + : createLoadingStatusSelector(changeKeyserverUserPasswordActionTypes); const ConnectedPasswordChangeModal: React.ComponentType<{}> = React.memo<{}>( function ConnectedPasswordChangeModal(): React.Node { const inputDisabled = useSelector( - state => - changeKeyserverUserPasswordLoadingStatusSelector(state) === 'loading', + state => changeUserPasswordLoadingStatusSelector(state) === 'loading', ); const callChangeKeyserverUserPassword = useLegacyAshoatKeyserverCall( changeKeyserverUserPassword, ); + const callChangeIdentityUserPassword = useChangeIdentityUserPassword(); const dispatchActionPromise = useDispatchActionPromise(); const modalContext = useModalContext(); @@ -257,6 +279,7 @@