forked from MetaMask/metamask-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[REFACTOR] Reveal Private Key section (MetaMask#6134)
- Loading branch information
Showing
4 changed files
with
107 additions
and
41 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
...components/Views/Settings/SecuritySettings/Sections/RevealPrivateKey/RevealPrivateKey.tsx
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,74 @@ | ||
import React from 'react'; | ||
import { View } from 'react-native'; | ||
import { useNavigation } from '@react-navigation/native'; | ||
import { useSelector } from 'react-redux'; | ||
import Button, { | ||
ButtonVariants, | ||
} from '../../../../../../component-library/components/Buttons/Button'; | ||
import Text from '../../../../../../component-library/components/Texts/Text'; | ||
import { MetaMetricsEvents } from '../../../../../../core/Analytics'; | ||
import AnalyticsV2 from '../../../../../../util/analyticsV2'; | ||
import { useTheme } from '../../../../../../util/theme'; | ||
import { strings } from '../../../../../../../locales/i18n'; | ||
import { createStyles } from './styles'; | ||
import Routes from '../../../../../../constants/navigation/Routes'; | ||
|
||
const testIds = { | ||
section: 'reveal-private-key-section', | ||
}; | ||
|
||
const RevealPrivateKey = () => { | ||
const { colors } = useTheme(); | ||
const styles = createStyles(colors); | ||
const navigation = useNavigation(); | ||
|
||
const accounts = useSelector( | ||
(state: any) => | ||
state.engine.backgroundState.AccountTrackerController.accounts, | ||
); | ||
const identities = useSelector( | ||
(state: any) => | ||
state.engine.backgroundState.PreferencesController.identities, | ||
); | ||
const selectedAddress = useSelector( | ||
(state: any) => | ||
state.engine.backgroundState.PreferencesController.selectedAddress, | ||
); | ||
|
||
const account = { | ||
address: selectedAddress, | ||
...identities[selectedAddress], | ||
...accounts[selectedAddress], | ||
}; | ||
|
||
const goToExportPrivateKey = () => { | ||
AnalyticsV2.trackEvent(MetaMetricsEvents.REVEAL_PRIVATE_KEY_INITIATED, {}); | ||
navigation.navigate(Routes.SETTINGS.REVEAL_PRIVATE_CREDENTIAL, { | ||
credentialName: 'private_key', | ||
shouldUpdateNav: true, | ||
}); | ||
}; | ||
|
||
return ( | ||
<View style={styles.setting} testID={testIds.section}> | ||
<Text style={styles.title}> | ||
{strings('reveal_credential.private_key_title_for_account', { | ||
accountName: account.name, | ||
})} | ||
</Text> | ||
<Text style={styles.desc}> | ||
{strings('reveal_credential.private_key_warning', { | ||
accountName: account.name, | ||
})} | ||
</Text> | ||
<Button | ||
label={strings('reveal_credential.show_private_key')} | ||
variant={ButtonVariants.Primary} | ||
onPress={goToExportPrivateKey} | ||
style={styles.confirm} | ||
/> | ||
</View> | ||
); | ||
}; | ||
|
||
export default RevealPrivateKey; |
29 changes: 29 additions & 0 deletions
29
app/components/Views/Settings/SecuritySettings/Sections/RevealPrivateKey/styles.ts
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,29 @@ | ||
/* eslint-disable import/prefer-default-export */ | ||
import { fontStyles } from '../../../../../../styles/common'; | ||
import { StyleSheet } from 'react-native'; | ||
|
||
export const createStyles = (colors: any) => | ||
StyleSheet.create({ | ||
setting: { | ||
marginTop: 50, | ||
}, | ||
title: { | ||
...fontStyles.normal, | ||
color: colors.text.default, | ||
fontSize: 20, | ||
lineHeight: 20, | ||
paddingTop: 4, | ||
marginTop: -4, | ||
}, | ||
desc: { | ||
...fontStyles.normal, | ||
color: colors.text.alternative, | ||
fontSize: 14, | ||
lineHeight: 20, | ||
marginTop: 12, | ||
}, | ||
confirm: { | ||
marginTop: 18, | ||
width: '100%', | ||
}, | ||
}); |
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