Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add events for export pk #2766

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import CopyButton from '@/components/common/CopyButton'
import ModalDialog from '@/components/common/ModalDialog'
import { trackEvent } from '@/services/analytics'
import { MPC_WALLET_EVENTS } from '@/services/analytics/events/mpcWallet'
import { Box, Button, DialogContent, DialogTitle, IconButton, TextField, Typography } from '@mui/material'
import { useState } from 'react'
import { useForm } from 'react-hook-form'
Expand Down Expand Up @@ -43,9 +45,11 @@ const ExportMPCAccountModal = ({ onClose, open }: { onClose: () => void; open: b
try {
setError(undefined)
const pk = await socialWalletService.exportSignerKey(data[ExportFieldNames.password])
trackEvent(MPC_WALLET_EVENTS.EXPORT_PK_SUCCESS)
setValue(ExportFieldNames.pk, pk)
} catch (err) {
logError(ErrorCodes._305, err)
trackEvent(MPC_WALLET_EVENTS.EXPORT_PK_ERROR)
setError(asError(err).message)
}
}
Expand All @@ -55,13 +59,19 @@ const ExportMPCAccountModal = ({ onClose, open }: { onClose: () => void; open: b
reset()
onClose()
}

const toggleShowPK = () => {
trackEvent(MPC_WALLET_EVENTS.SEE_PK)
setShowPassword((prev) => !prev)
}

const onCopy = () => {
trackEvent(MPC_WALLET_EVENTS.COPY_PK)
}

return (
<ModalDialog open={open} onClose={handleClose}>
<DialogTitle>
<Typography variant="h6" fontWeight={700}>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was causing some MUI errors in the console

Export your account
</Typography>
</DialogTitle>
<DialogTitle fontWeight="bold">Export your account</DialogTitle>
<IconButton className={css.close} aria-label="close" onClick={handleClose} size="small">
<Close fontSize="large" />
</IconButton>
Expand All @@ -83,10 +93,10 @@ const ExportMPCAccountModal = ({ onClose, open }: { onClose: () => void; open: b
readOnly: true,
endAdornment: (
<>
<IconButton size="small" onClick={() => setShowPassword((prev) => !prev)}>
<IconButton size="small" onClick={toggleShowPK}>
{showPassword ? <VisibilityOff fontSize="small" /> : <Visibility fontSize="small" />}
</IconButton>
<CopyButton text={exportedKey} />
<CopyButton text={exportedKey} onCopy={onCopy} />
</>
),
}}
Expand Down
29 changes: 18 additions & 11 deletions src/components/settings/SecurityLogin/SocialSignerExport/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Track from '@/components/common/Track'
import { MPC_WALLET_EVENTS } from '@/services/analytics/events/mpcWallet'
import { Alert, Box, Button, Tooltip, Typography } from '@mui/material'
import { useState } from 'react'
import ExportMPCAccountModal from '@/components/settings/SecurityLogin/SocialSignerExport/ExportMPCAccountModal'
Expand All @@ -20,17 +22,22 @@ const SocialSignerExport = () => {
Never disclose your keys or seed phrase to anyone. If someone gains access to them, they have full access over
your social login signer.
</Alert>
<Tooltip title={isPasswordSet ? '' : 'Private key export is only available if you set a recovery password'}>
<Button
color="primary"
variant="contained"
sx={{ pointerEvents: 'all !important' }}
disabled={isModalOpen || !isPasswordSet}
onClick={() => setIsModalOpen(true)}
>
Reveal private key
</Button>
</Tooltip>

<Track {...MPC_WALLET_EVENTS.REVEAL_PRIVATE_KEY}>
<Tooltip title={isPasswordSet ? '' : 'Private key export is only available if you set a recovery password'}>
<span>
<Button
color="primary"
variant="contained"
sx={{ pointerEvents: 'all !important' }}
disabled={isModalOpen || !isPasswordSet}
onClick={() => setIsModalOpen(true)}
>
Reveal private key
</Button>
</span>
</Tooltip>
</Track>
</Box>
<ExportMPCAccountModal onClose={() => setIsModalOpen(false)} open={isModalOpen} />
</>
Expand Down
25 changes: 25 additions & 0 deletions src/services/analytics/events/mpcWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,29 @@ export const MPC_WALLET_EVENTS = {
action: 'Enable MFA for account',
category: MPC_WALLET_CATEGORY,
},
REVEAL_PRIVATE_KEY: {
event: EventType.CLICK,
action: 'Reveal private key',
category: MPC_WALLET_CATEGORY,
},
EXPORT_PK_SUCCESS: {
event: EventType.META,
action: 'Export private key successful',
category: MPC_WALLET_CATEGORY,
},
EXPORT_PK_ERROR: {
event: EventType.META,
action: 'Export private key error',
category: MPC_WALLET_CATEGORY,
},
SEE_PK: {
event: EventType.CLICK,
action: 'Toggle see private key',
category: MPC_WALLET_CATEGORY,
},
COPY_PK: {
event: EventType.CLICK,
action: 'Copy private key',
category: MPC_WALLET_CATEGORY,
},
}
Loading