-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Enable 'Remove Wallet Account'
- Loading branch information
1 parent
27f7c64
commit 36e62cc
Showing
7 changed files
with
185 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
packages/frontend/src/components/profile/remove_account/RemoveAccountModal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import React, { useState } from 'react'; | ||
import { Translate } from 'react-localize-redux'; | ||
import styled from 'styled-components'; | ||
|
||
import Checkbox from '../../common/Checkbox'; | ||
import FormButton from '../../common/FormButton'; | ||
import Modal from '../../common/modal/Modal'; | ||
import SafeTranslate from '../../SafeTranslate'; | ||
|
||
const Container = styled.div` | ||
&&&&& { | ||
padding: 15px 0 10px 0; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
text-align: center; | ||
h3 { | ||
margin: 15px 0; | ||
font-size: 18px; | ||
font-weight: 700; | ||
} | ||
p { | ||
line-height: 1.5; | ||
} | ||
label { | ||
text-align: left; | ||
display: flex; | ||
background-color: #F5FAFF; | ||
margin: 25px -25px 0 -25px; | ||
padding: 15px 25px; | ||
line-height: 1.5; | ||
> div { | ||
> div { | ||
border-color: #0081F1; | ||
} | ||
} | ||
> span { | ||
margin-left: 10px; | ||
word-break: break-word; | ||
color: #006ADC; | ||
} | ||
b { | ||
color: #272729; | ||
} | ||
} | ||
> button { | ||
margin-top: 25px; | ||
width: 100%; | ||
} | ||
} | ||
`; | ||
|
||
export default ({ | ||
accountId, | ||
isOpen, | ||
onRemoveAccount, | ||
onClose | ||
}) => { | ||
const [removeAccountDisclaimerApproved, setRemoveAccountDisclaimerApproved] = useState(false); | ||
return ( | ||
<Modal | ||
id='remove-account-modal' | ||
isOpen={isOpen} | ||
onClose={onClose} | ||
modalSize='sm' | ||
> | ||
<Container> | ||
<h3><Translate id='removeAccount.title' /></h3> | ||
<p><Translate id='removeAccount.desc' /></p> | ||
<label> | ||
<Checkbox | ||
checked={removeAccountDisclaimerApproved} | ||
onChange={(e) => setRemoveAccountDisclaimerApproved(e.target.checked)} | ||
/> | ||
<span> | ||
<SafeTranslate | ||
id='removeAccount.disclaimer' | ||
data={{ accountId: accountId }} | ||
/> | ||
</span> | ||
</label> | ||
<FormButton | ||
disabled={!removeAccountDisclaimerApproved} | ||
onClick={onRemoveAccount} | ||
> | ||
<Translate id='button.removeAccount' /> | ||
</FormButton> | ||
<FormButton | ||
className='link' | ||
onClick={onClose}> | ||
<Translate id='button.cancel' /> | ||
</FormButton> | ||
</Container> | ||
</Modal> | ||
); | ||
}; |
49 changes: 49 additions & 0 deletions
49
packages/frontend/src/components/profile/remove_account/RemoveAccountWrapper.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React, { useState } from 'react'; | ||
import { Translate } from 'react-localize-redux'; | ||
import { useSelector, useDispatch } from 'react-redux'; | ||
import styled from 'styled-components'; | ||
|
||
import { switchAccount } from '../../../redux/actions/account'; | ||
import { selectAccountId } from '../../../redux/slices/account'; | ||
import { wallet } from '../../../utils/wallet'; | ||
import FormButton from '../../common/FormButton'; | ||
import Container from '../../common/styled/Container.css'; | ||
import RemoveAccountModal from './RemoveAccountModal'; | ||
|
||
const StyledContainer = styled(Container)` | ||
> button { | ||
width: 100%; | ||
} | ||
`; | ||
|
||
export default () => { | ||
const dispatch = useDispatch(); | ||
const [showRemoveAccountModal, setShowRemoveAccountModal] = useState(false); | ||
const accountId = useSelector(selectAccountId); | ||
return ( | ||
<StyledContainer> | ||
<FormButton | ||
color='red' | ||
onClick={() => setShowRemoveAccountModal(true)} | ||
> | ||
<Translate id='removeAccount.button' /> | ||
</FormButton> | ||
{showRemoveAccountModal && | ||
<RemoveAccountModal | ||
onClose={() => setShowRemoveAccountModal(false)} | ||
onRemoveAccount={() => { | ||
const walletAccounts = wallet.removeWalletAccount(accountId); | ||
if (Object.keys(walletAccounts).length === 0) { | ||
location.reload(); | ||
} else { | ||
dispatch(switchAccount({ accountId: Object.keys(walletAccounts)[0] })); | ||
} | ||
setShowRemoveAccountModal(false); | ||
}} | ||
isOpen={showRemoveAccountModal} | ||
accountId={accountId} | ||
/> | ||
} | ||
</StyledContainer> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters