Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding periodic reminder modal for backing up recovery phrase (#11021)
* Adding recurring recovery phrase reminder modal * Refactoring per PR feedback
- Loading branch information
Showing
17 changed files
with
350 additions
and
10 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { cloneDeep } from 'lodash'; | ||
|
||
const version = 61; | ||
|
||
/** | ||
* Initialize attributes related to recovery seed phrase reminder | ||
*/ | ||
export default { | ||
version, | ||
async migrate(originalVersionedData) { | ||
const versionedData = cloneDeep(originalVersionedData); | ||
versionedData.meta.version = version; | ||
const state = versionedData.data; | ||
const newState = transformState(state); | ||
versionedData.data = newState; | ||
return versionedData; | ||
}, | ||
}; | ||
|
||
function transformState(state) { | ||
const currentTime = new Date().getTime(); | ||
if (state.AppStateController) { | ||
state.AppStateController.recoveryPhraseReminderHasBeenShown = false; | ||
state.AppStateController.recoveryPhraseReminderLastShown = currentTime; | ||
} else { | ||
state.AppStateController = { | ||
recoveryPhraseReminderHasBeenShown: false, | ||
recoveryPhraseReminderLastShown: currentTime, | ||
}; | ||
} | ||
return state; | ||
} |
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,67 @@ | ||
import { strict as assert } from 'assert'; | ||
import sinon from 'sinon'; | ||
import migration61 from './061'; | ||
|
||
describe('migration #61', function () { | ||
let dateStub; | ||
|
||
beforeEach(function () { | ||
dateStub = sinon.stub(Date.prototype, 'getTime').returns(1621580400000); | ||
}); | ||
|
||
afterEach(function () { | ||
dateStub.restore(); | ||
}); | ||
|
||
it('should update the version metadata', async function () { | ||
const oldStorage = { | ||
meta: { | ||
version: 60, | ||
}, | ||
data: {}, | ||
}; | ||
|
||
const newStorage = await migration61.migrate(oldStorage); | ||
assert.deepEqual(newStorage.meta, { | ||
version: 61, | ||
}); | ||
}); | ||
|
||
it('should set recoveryPhraseReminderHasBeenShown to false and recoveryPhraseReminderLastShown to the current time', async function () { | ||
const oldStorage = { | ||
meta: {}, | ||
data: { | ||
AppStateController: { | ||
existingProperty: 'foo', | ||
}, | ||
}, | ||
}; | ||
|
||
const newStorage = await migration61.migrate(oldStorage); | ||
assert.deepEqual(newStorage.data, { | ||
AppStateController: { | ||
recoveryPhraseReminderHasBeenShown: false, | ||
recoveryPhraseReminderLastShown: 1621580400000, | ||
existingProperty: 'foo', | ||
}, | ||
}); | ||
}); | ||
|
||
it('should initialize AppStateController if it does not exist', async function () { | ||
const oldStorage = { | ||
meta: {}, | ||
data: { | ||
existingProperty: 'foo', | ||
}, | ||
}; | ||
|
||
const newStorage = await migration61.migrate(oldStorage); | ||
assert.deepEqual(newStorage.data, { | ||
existingProperty: 'foo', | ||
AppStateController: { | ||
recoveryPhraseReminderHasBeenShown: false, | ||
recoveryPhraseReminderLastShown: 1621580400000, | ||
}, | ||
}); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const MILLISECOND = 1; | ||
export const SECOND = MILLISECOND * 1000; | ||
export const MINUTE = SECOND * 60; | ||
export const HOUR = MINUTE * 60; | ||
export const DAY = HOUR * 24; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './recovery-phrase-reminder'; |
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,10 @@ | ||
.recovery-phrase-reminder { | ||
&__list { | ||
list-style: disc; | ||
padding-left: 20px; | ||
|
||
li { | ||
margin-bottom: 5px; | ||
} | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
ui/components/app/recovery-phrase-reminder/recovery-phrase-reminder.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,91 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { useHistory } from 'react-router-dom'; | ||
import { useI18nContext } from '../../../hooks/useI18nContext'; | ||
// Components | ||
import Box from '../../ui/box'; | ||
import Button from '../../ui/button'; | ||
import Popover from '../../ui/popover'; | ||
import Typography from '../../ui/typography'; | ||
// Helpers | ||
import { | ||
COLORS, | ||
DISPLAY, | ||
TEXT_ALIGN, | ||
TYPOGRAPHY, | ||
BLOCK_SIZES, | ||
FONT_WEIGHT, | ||
JUSTIFY_CONTENT, | ||
} from '../../../helpers/constants/design-system'; | ||
import { INITIALIZE_BACKUP_SEED_PHRASE_ROUTE } from '../../../helpers/constants/routes'; | ||
|
||
export default function RecoveryPhraseReminder({ onConfirm, hasBackedUp }) { | ||
const t = useI18nContext(); | ||
const history = useHistory(); | ||
|
||
const handleBackUp = () => { | ||
history.push(INITIALIZE_BACKUP_SEED_PHRASE_ROUTE); | ||
}; | ||
|
||
return ( | ||
<Popover centerTitle title={t('recoveryPhraseReminderTitle')}> | ||
<Box padding={[0, 4, 6, 4]} className="recovery-phrase-reminder"> | ||
<Typography | ||
color={COLORS.BLACK} | ||
align={TEXT_ALIGN.CENTER} | ||
variant={TYPOGRAPHY.Paragraph} | ||
boxProps={{ marginTop: 0, marginBottom: 4 }} | ||
> | ||
{t('recoveryPhraseReminderSubText')} | ||
</Typography> | ||
<Box margin={[4, 0, 8, 0]}> | ||
<ul className="recovery-phrase-reminder__list"> | ||
<li> | ||
<Typography | ||
tag="span" | ||
color={COLORS.BLACK} | ||
fontWeight={FONT_WEIGHT.BOLD} | ||
> | ||
{t('recoveryPhraseReminderItemOne')} | ||
</Typography> | ||
</li> | ||
<li>{t('recoveryPhraseReminderItemTwo')}</li> | ||
<li> | ||
{hasBackedUp ? ( | ||
t('recoveryPhraseReminderHasBackedUp') | ||
) : ( | ||
<> | ||
{t('recoveryPhraseReminderHasNotBackedUp')} | ||
<Box display={DISPLAY.INLINE_BLOCK} marginLeft={1}> | ||
<Button | ||
type="link" | ||
onClick={handleBackUp} | ||
style={{ | ||
fontSize: 'inherit', | ||
padding: 0, | ||
}} | ||
> | ||
{t('recoveryPhraseReminderBackupStart')} | ||
</Button> | ||
</Box> | ||
</> | ||
)} | ||
</li> | ||
</ul> | ||
</Box> | ||
<Box justifyContent={JUSTIFY_CONTENT.CENTER}> | ||
<Box width={BLOCK_SIZES.TWO_FIFTHS}> | ||
<Button rounded type="primary" onClick={onConfirm}> | ||
{t('recoveryPhraseReminderConfirm')} | ||
</Button> | ||
</Box> | ||
</Box> | ||
</Box> | ||
</Popover> | ||
); | ||
} | ||
|
||
RecoveryPhraseReminder.propTypes = { | ||
hasBackedUp: PropTypes.bool.isRequired, | ||
onConfirm: PropTypes.func.isRequired, | ||
}; |
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 |
---|---|---|
|
@@ -47,6 +47,10 @@ | |
margin-right: 24px; | ||
} | ||
} | ||
|
||
&.center { | ||
justify-content: center; | ||
} | ||
} | ||
|
||
&__subtitle { | ||
|
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
Oops, something went wrong.