Skip to content

Commit

Permalink
refactor: move logic to effect for reset private key component
Browse files Browse the repository at this point in the history
  • Loading branch information
dawidgil committed Apr 7, 2022
1 parent 96c6d67 commit 4677262
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { useContext } from 'react';
import { UserDataContext } from '@dsb-client-gateway/ui/login';
import Swal from 'sweetalert2';
import { theme } from '@dsb-client-gateway/ui/utils';
import { AccountStatusEnum } from '../check-account-status/check-account-status';

export const useResetPrivateKey = () => {
const {userData, setUserData} = useContext(UserDataContext);

const resetPrivateKeyHandler = () => {
Swal.fire( {
icon: 'warning',
iconColor: theme.palette.warning.main,
title: 'Reset private key',
text: 'Please confirm to reset private key',
showCancelButton: true,
showConfirmButton: true,
confirmButtonText: 'Confirm'
}).then((result) => {
if (result.isConfirmed) {
setUserData({...userData, accountStatus: AccountStatusEnum.NotSetPrivateKey});
}
})
};

return {resetPrivateKeyHandler}
}
Original file line number Diff line number Diff line change
@@ -1,35 +1,15 @@
import { Button } from '@mui/material';
import Swal from 'sweetalert2';
import { theme } from '@dsb-client-gateway/ui/utils';
import { AccountStatusEnum } from '../check-account-status/check-account-status';
import { useContext } from 'react';
import { UserDataContext } from '../UserDataContext';
import { useResetPrivateKey } from './ResetPrivateKey.effects';

export function ResetPrivateKey() {
const {userData, setUserData} = useContext(UserDataContext);

const onResetPrivateKey = () => {
Swal.fire( {
icon: 'warning',
iconColor: theme.palette.warning.main,
title: 'Reset private key',
text: 'Please confirm to reset private key',
showCancelButton: true,
showConfirmButton: true,
confirmButtonText: 'Confirm'
}).then((result) => {
if (result.isConfirmed) {
setUserData({...userData, accountStatus: AccountStatusEnum.NotSetPrivateKey});
}
})
};
const {resetPrivateKeyHandler} = useResetPrivateKey()

return (
<Button
variant="contained"
color="primary"
sx={{marginTop: '17px'}}
onClick={() => onResetPrivateKey()}
onClick={() => resetPrivateKeyHandler()}
fullWidth>
Reset private key
</Button>
Expand Down

0 comments on commit 4677262

Please sign in to comment.