@xyo-network/react-wallet 7.5.7 → 7.5.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/dist/browser/components/WalletAccountDetails/WalletAccountDetails.d.ts.map +1 -1
  2. package/dist/browser/contexts/SeedPhrase/Provider.d.ts.map +1 -1
  3. package/dist/browser/index.mjs +656 -566
  4. package/dist/browser/index.mjs.map +1 -1
  5. package/package.json +112 -46
  6. package/src/components/MaxAccounts/MaxAccountsTableRow.tsx +0 -75
  7. package/src/components/MaxAccounts/OutOfBoundsSnackBar.tsx +0 -41
  8. package/src/components/MaxAccounts/index.ts +0 -1
  9. package/src/components/SeedPhrase/DefaultSeedPhrase.stories.tsx +0 -27
  10. package/src/components/SeedPhrase/DefaultSeedPhrase.tsx +0 -52
  11. package/src/components/SeedPhrase/_shared/SeedPhraseIconButton.tsx +0 -53
  12. package/src/components/SeedPhrase/_shared/index.ts +0 -1
  13. package/src/components/SeedPhrase/dialog/SeedPhraseDialog.stories.tsx +0 -33
  14. package/src/components/SeedPhrase/dialog/SeedPhraseDialog.tsx +0 -84
  15. package/src/components/SeedPhrase/dialog/components/DialogActionButtons.tsx +0 -33
  16. package/src/components/SeedPhrase/dialog/components/OverwriteWarning.tsx +0 -28
  17. package/src/components/SeedPhrase/dialog/components/fields/NewPhraseTextField.tsx +0 -45
  18. package/src/components/SeedPhrase/dialog/components/fields/PhraseDialogActions.stories.tsx +0 -29
  19. package/src/components/SeedPhrase/dialog/components/fields/PhraseDialogActions.tsx +0 -38
  20. package/src/components/SeedPhrase/dialog/components/fields/SavedPhraseTextField.tsx +0 -113
  21. package/src/components/SeedPhrase/dialog/components/fields/index.ts +0 -4
  22. package/src/components/SeedPhrase/dialog/components/fields/validation-messages/InvalidPhrase.tsx +0 -14
  23. package/src/components/SeedPhrase/dialog/components/fields/validation-messages/PhraseHeaderBox.tsx +0 -50
  24. package/src/components/SeedPhrase/dialog/components/fields/validation-messages/colorParser.ts +0 -14
  25. package/src/components/SeedPhrase/dialog/components/fields/validation-messages/index.ts +0 -3
  26. package/src/components/SeedPhrase/dialog/components/index.ts +0 -3
  27. package/src/components/SeedPhrase/dialog/index.ts +0 -2
  28. package/src/components/SeedPhrase/index.ts +0 -4
  29. package/src/components/SeedPhrase/settings/SeedPhraseTableRow.stories.tsx +0 -31
  30. package/src/components/SeedPhrase/settings/SeedPhraseTableRow.tsx +0 -48
  31. package/src/components/SeedPhrase/settings/index.ts +0 -1
  32. package/src/components/WalletAccountDetails/WalletAccountDetails.stories.tsx +0 -27
  33. package/src/components/WalletAccountDetails/WalletAccountDetails.tsx +0 -37
  34. package/src/components/WalletAccountDetails/WalletAccountDetailsWithProvider.stories.tsx +0 -33
  35. package/src/components/WalletAccountDetails/index.ts +0 -1
  36. package/src/components/WalletAccountSelect/RenderedMenuItem.tsx +0 -52
  37. package/src/components/WalletAccountSelect/Select.tsx +0 -84
  38. package/src/components/WalletAccountSelect/SelectBar.tsx +0 -44
  39. package/src/components/WalletAccountSelect/WalletAccountSelect.stories.tsx +0 -45
  40. package/src/components/WalletAccountSelect/WalletAccountSelectBar.stories.tsx +0 -61
  41. package/src/components/WalletAccountSelect/WalletAccountSelectWithProvider.stories.tsx +0 -43
  42. package/src/components/WalletAccountSelect/WalletInfo.tsx +0 -121
  43. package/src/components/WalletAccountSelect/index.ts +0 -2
  44. package/src/components/WalletAccountSelect/stories/WalletProviderDecorator.tsx +0 -31
  45. package/src/components/WalletAccountSelect/stories/index.ts +0 -1
  46. package/src/components/index.ts +0 -4
  47. package/src/contexts/SeedPhrase/Context.ts +0 -6
  48. package/src/contexts/SeedPhrase/Provider.tsx +0 -103
  49. package/src/contexts/SeedPhrase/State.ts +0 -19
  50. package/src/contexts/SeedPhrase/index.ts +0 -4
  51. package/src/contexts/SeedPhrase/use.ts +0 -6
  52. package/src/contexts/Wallet/Context.ts +0 -6
  53. package/src/contexts/Wallet/Provider.tsx +0 -46
  54. package/src/contexts/Wallet/State.ts +0 -15
  55. package/src/contexts/Wallet/index.ts +0 -4
  56. package/src/contexts/Wallet/use.ts +0 -37
  57. package/src/contexts/index.ts +0 -2
  58. package/src/hooks/index.ts +0 -4
  59. package/src/hooks/useAccount.ts +0 -68
  60. package/src/hooks/useWallet.ts +0 -46
  61. package/src/hooks/useWallets.ts +0 -22
  62. package/src/hooks/useWrapperAccount.ts +0 -36
  63. package/src/index.ts +0 -3
@@ -1,75 +0,0 @@
1
- import type { TableRowProps } from '@mui/material'
2
- import {
3
- ButtonGroup, TableCell, TableRow, Typography,
4
- } from '@mui/material'
5
- import { ButtonEx } from '@xylabs/react-button'
6
- import React, { useState } from 'react'
7
-
8
- import { OutOfBoundsSnackBar } from './OutOfBoundsSnackBar.tsx'
9
-
10
- /** @public */
11
- export interface MaxAccountsTableRow extends TableRowProps {
12
- activeAccountIndex?: number
13
- changeMaxAccounts?: (maxAccounts: number) => void
14
- maxAccounts?: number
15
- }
16
-
17
- /** @public */
18
- export const MaxAccountsTableRow: React.FC<MaxAccountsTableRow> = ({
19
- activeAccountIndex, changeMaxAccounts, maxAccounts,
20
- }) => {
21
- const [desiredMaximumAccounts, setDesiredMaximumAccounts] = useState<number | undefined>()
22
- const [showSnackBar, setShowSnackBar] = useState(false)
23
-
24
- const handleChangeMaxAccounts = (change: 'increase' | 'decrease') => {
25
- if (maxAccounts !== undefined && activeAccountIndex !== undefined) {
26
- switch (change) {
27
- case 'decrease': {
28
- const desiredMaximumAccounts = maxAccounts - 1
29
- const validMaximumAccounts = desiredMaximumAccounts > 0
30
- const maxAccountsWithinRange = activeAccountIndex + 1 <= desiredMaximumAccounts
31
- if (validMaximumAccounts && maxAccountsWithinRange) {
32
- changeMaxAccounts?.(desiredMaximumAccounts)
33
- }
34
- if (!maxAccountsWithinRange) setShowSnackBar(true)
35
- setDesiredMaximumAccounts(desiredMaximumAccounts)
36
- return
37
- }
38
- case 'increase': {
39
- changeMaxAccounts?.(maxAccounts + 1)
40
- return
41
- }
42
- default: {
43
- console.error(change, 'is not a recognized value')
44
- }
45
- }
46
- } else {
47
- throw new Error('Max Accounts is unset and needs a default')
48
- }
49
- }
50
-
51
- return (
52
- <TableRow>
53
- <TableCell>Maximum Accounts</TableCell>
54
- <TableCell align="center">
55
- <Typography variant="caption">{maxAccounts}</Typography>
56
- </TableCell>
57
- <TableCell align="center">
58
- <ButtonGroup>
59
- <ButtonEx onClick={() => handleChangeMaxAccounts('decrease')} variant="contained" size="small">
60
- -
61
- </ButtonEx>
62
- <ButtonEx onClick={() => handleChangeMaxAccounts('increase')} variant="contained" size="small">
63
- +
64
- </ButtonEx>
65
- </ButtonGroup>
66
- <OutOfBoundsSnackBar
67
- desiredMaximumAccounts={desiredMaximumAccounts}
68
- activeAccountIndex={activeAccountIndex}
69
- setShowSnackBar={setShowSnackBar}
70
- showSnackBar={showSnackBar}
71
- />
72
- </TableCell>
73
- </TableRow>
74
- )
75
- }
@@ -1,41 +0,0 @@
1
- import type { SnackbarProps } from '@mui/material'
2
- import {
3
- Alert, AlertTitle, Snackbar,
4
- } from '@mui/material'
5
- import type { Dispatch, SetStateAction } from 'react'
6
- import React from 'react'
7
-
8
- /** @public */
9
- export interface OutOfBoundsSnackBarProps extends SnackbarProps {
10
- activeAccountIndex?: number
11
- desiredMaximumAccounts?: number
12
- setShowSnackBar?: Dispatch<SetStateAction<boolean>>
13
- showSnackBar?: boolean
14
- }
15
-
16
- /** @public */
17
- export const OutOfBoundsSnackBar: React.FC<OutOfBoundsSnackBarProps> = ({
18
- activeAccountIndex,
19
- desiredMaximumAccounts,
20
- setShowSnackBar,
21
- showSnackBar,
22
- }) => {
23
- return (
24
- <Snackbar
25
- anchorOrigin={{ horizontal: 'center', vertical: 'top' }}
26
- autoHideDuration={5000}
27
- onClose={() => setShowSnackBar?.(false)}
28
- open={showSnackBar}
29
- >
30
- <Alert severity="error" onClose={() => setShowSnackBar?.(false)}>
31
- <AlertTitle>Maximum Accounts Error</AlertTitle>
32
- Your currently selected account number (
33
- {activeAccountIndex === undefined ? '' : activeAccountIndex + 1}
34
- ) cannot be greater than the desired
35
- Maximum Accounts (
36
- {desiredMaximumAccounts}
37
- ).
38
- </Alert>
39
- </Snackbar>
40
- )
41
- }
@@ -1 +0,0 @@
1
- export * from './MaxAccountsTableRow.tsx'
@@ -1,27 +0,0 @@
1
- import type { Meta, StoryFn } from '@storybook/react-vite'
2
- import React from 'react'
3
-
4
- import { DefaultSeedPhrase } from './DefaultSeedPhrase.tsx'
5
-
6
- export default {
7
- component: DefaultSeedPhrase,
8
- title: 'Wallet/DefaultSeedPhrase',
9
- } as Meta
10
-
11
- const Template: StoryFn<typeof DefaultSeedPhrase> = props => <DefaultSeedPhrase {...props} />
12
-
13
- const Default = Template.bind({})
14
- Default.args = { seedPhrase: 'test me' }
15
-
16
- const WithoutDefaultSeedPhrase = Template.bind({})
17
- WithoutDefaultSeedPhrase.args = { changeSeedPhrase: (mnemonic?: string) => alert(`Generated Default Seed Phrase: ${mnemonic}`) }
18
-
19
- const WithHiddenDefaultSeedPhrase = Template.bind({})
20
- WithHiddenDefaultSeedPhrase.args = {
21
- hideDefaultSeedPhraseMessage: true,
22
- ...WithoutDefaultSeedPhrase.args,
23
- }
24
-
25
- export {
26
- Default, WithHiddenDefaultSeedPhrase, WithoutDefaultSeedPhrase,
27
- }
@@ -1,52 +0,0 @@
1
- import {
2
- Alert, AlertTitle, Snackbar,
3
- } from '@mui/material'
4
- import { generateMnemonic } from '@scure/bip39'
5
- import { wordlist } from '@scure/bip39/wordlists/english.js'
6
- import { isUndefinedOrNull } from '@xylabs/sdk-js'
7
- import type { PropsWithChildren } from 'react'
8
- import React, { useState } from 'react'
9
-
10
- /** @public */
11
- export interface DefaultSeedPhraseProps extends PropsWithChildren {
12
- changeSeedPhrase?: (seedPhrase: string) => void
13
- hideDefaultSeedPhraseMessage?: boolean
14
- seedPhrase?: string
15
- }
16
-
17
- /** @public */
18
- export const DefaultSeedPhrase: React.FC<DefaultSeedPhraseProps> = ({
19
- changeSeedPhrase, children, hideDefaultSeedPhraseMessage, seedPhrase,
20
- }) => {
21
- const [showSnackBar, setShowSnackBar] = useState(false)
22
- const [previousSeedPhrase, setPreviousSeedPhrase] = useState<string | undefined>()
23
- if (seedPhrase !== previousSeedPhrase) {
24
- setPreviousSeedPhrase(seedPhrase)
25
- if (isUndefinedOrNull(previousSeedPhrase) && !isUndefinedOrNull(seedPhrase)) {
26
- const mnemonic = generateMnemonic(wordlist, 256)
27
- changeSeedPhrase?.(mnemonic)
28
- setShowSnackBar(true)
29
- }
30
- }
31
-
32
- return (
33
- <>
34
- {hideDefaultSeedPhraseMessage
35
- ? null
36
- : (
37
- <Snackbar
38
- open={showSnackBar}
39
- autoHideDuration={5000}
40
- onClose={() => setShowSnackBar(false)}
41
- anchorOrigin={{ horizontal: 'center', vertical: 'top' }}
42
- >
43
- <Alert severity="success">
44
- <AlertTitle>Default Seed Phrase Generated</AlertTitle>
45
- Go to application settings to save it.
46
- </Alert>
47
- </Snackbar>
48
- )}
49
- {children}
50
- </>
51
- )
52
- }
@@ -1,53 +0,0 @@
1
- import { HelpOutline as HelpOutlineIcon } from '@mui/icons-material'
2
- import type { IconButtonProps } from '@mui/material'
3
- import {
4
- Button,
5
- Dialog,
6
- DialogActions,
7
- DialogContent,
8
- DialogTitle,
9
- IconButton,
10
- Link,
11
- List,
12
- ListItem,
13
- Typography,
14
- } from '@mui/material'
15
- import React, { useState } from 'react'
16
-
17
- /** @internal */
18
- export const SeedPhraseIconButton: React.FC<IconButtonProps> = (props) => {
19
- const [open, setOpen] = useState(false)
20
- const onClose = () => setOpen(false)
21
- return (
22
- <>
23
- <IconButton onClick={() => setOpen(true)} {...props}>
24
- <HelpOutlineIcon fontSize="small" />
25
- </IconButton>
26
- <Dialog open={open}>
27
- <DialogTitle>Understanding your Seed Phrase</DialogTitle>
28
- <DialogContent>
29
- <Typography>
30
- Your Seed Phrase should adhere to the
31
- {' '}
32
- <Link target="_blank" href="https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki">
33
- bip39 specification
34
- </Link>
35
- {' '}
36
- and is used to generate accounts which identify your data on the XYO Network.
37
- </Typography>
38
- <List>
39
- <ListItem>Do not share this phrase with anyone.</ListItem>
40
- <ListItem>Do not save it to a public computer.</ListItem>
41
- <ListItem>Do not use a existing phrase from another wallet (i.e. Metamask).</ListItem>
42
- <ListItem>Do not use before copying it down somewhere safe.</ListItem>
43
- </List>
44
- </DialogContent>
45
- <DialogActions>
46
- <Button onClick={onClose} variant="outlined">
47
- OK
48
- </Button>
49
- </DialogActions>
50
- </Dialog>
51
- </>
52
- )
53
- }
@@ -1 +0,0 @@
1
- export * from './SeedPhraseIconButton.tsx'
@@ -1,33 +0,0 @@
1
- import { Button, Typography } from '@mui/material'
2
- import { generateMnemonic } from '@scure/bip39'
3
- import { wordlist } from '@scure/bip39/wordlists/english.js'
4
- import type { Meta, StoryFn } from '@storybook/react-vite'
5
- import { FlexCol } from '@xylabs/react-flexbox'
6
- import React, { useState } from 'react'
7
-
8
- import { SeedPhraseDialog } from './SeedPhraseDialog.tsx'
9
-
10
- export default {
11
- component: SeedPhraseDialog,
12
- title: 'Wallet/SeedPhraseDialog',
13
- } as Meta
14
-
15
- const Template: StoryFn<typeof SeedPhraseDialog> = (props) => {
16
- const mnemonic = generateMnemonic(wordlist, 256)
17
- const [seedPhrase, setSeedPhrase] = useState(mnemonic)
18
- const [open, setOpen] = useState(false)
19
- return (
20
- <FlexCol rowGap={3}>
21
- <Button variant="contained" onClick={() => setOpen(true)}>
22
- Open Dialog
23
- </Button>
24
- <Typography>Seed Phrase</Typography>
25
- <code>{seedPhrase}</code>
26
- <SeedPhraseDialog showCopyButton seedPhrase={seedPhrase} changeSeedPhrase={setSeedPhrase} {...props} open={open} onClose={() => setOpen(false)} />
27
- </FlexCol>
28
- )
29
- }
30
-
31
- const Default = Template.bind({})
32
-
33
- export { Default }
@@ -1,84 +0,0 @@
1
- import type { DialogProps } from '@mui/material'
2
- import {
3
- Dialog, DialogContent, DialogTitle, FormLabel,
4
- } from '@mui/material'
5
- import type { ReactNode } from 'react'
6
- import React from 'react'
7
-
8
- import { SeedPhraseProvider, useSeedPhrase } from '../../../contexts/index.ts'
9
- import { SeedPhraseIconButton } from '../_shared/index.ts'
10
- import {
11
- DialogActionButtons,
12
- NewPhraseTextField,
13
- OverwriteWarning,
14
- PhraseDialogActions,
15
- PhraseHeaderBox,
16
- SavedPhraseTextField,
17
- } from './components/index.ts'
18
-
19
- /** @public */
20
- export interface SeedPhraseDialogProps extends DialogProps {
21
- changeSeedPhrase?: (value: string) => void
22
- dialogTitle?: ReactNode
23
- seedPhrase?: string
24
- seedPhraseTextFieldTitle?: ReactNode
25
- showCopyButton?: boolean
26
- }
27
-
28
- /** @public */
29
- export const SeedPhraseDialog: React.FC<SeedPhraseDialogProps> = ({
30
- changeSeedPhrase, dialogTitle = 'Update Your Seed Phrase', seedPhrase, seedPhraseTextFieldTitle = 'New Seed Phrase', ...props
31
- }) => {
32
- return (
33
- <SeedPhraseProvider
34
- seedPhrase={seedPhrase}
35
- handleChangeSeedPhrase={changeSeedPhrase}
36
- open={props.open}
37
- saveCallback={() => props.onClose?.({}, 'escapeKeyDown')}
38
- >
39
- <SeedPhraseDialogInner dialogTitle={dialogTitle} seedPhraseTextFieldTitle={seedPhraseTextFieldTitle} {...props} />
40
- </SeedPhraseProvider>
41
- )
42
- }
43
-
44
- /** @public */
45
- export const SeedPhraseDialogInner: React.FC<SeedPhraseDialogProps> = ({
46
- dialogTitle, seedPhraseTextFieldTitle, showCopyButton, ...props
47
- }) => {
48
- const {
49
- overwriteWarning, seedPhrase, validPhrase,
50
- } = useSeedPhrase()
51
-
52
- return (
53
- <Dialog aria-labelledby="alert-dialog-title" aria-describedby="alert-dialog-description" fullWidth maxWidth="sm" {...props}>
54
- <DialogTitle
55
- id="alert-dialog-title"
56
- sx={{
57
- alignItems: 'center', display: 'inline-flex', flexDirection: 'row',
58
- }}
59
- >
60
- {dialogTitle}
61
- <SeedPhraseIconButton />
62
- </DialogTitle>
63
- <DialogContent sx={{
64
- display: 'flex', flexDirection: 'column', rowGap: 2,
65
- }}
66
- >
67
-
68
- <NewPhraseTextField>
69
- <FormLabel>
70
- <PhraseHeaderBox conditional={validPhrase}>{seedPhraseTextFieldTitle}</PhraseHeaderBox>
71
- </FormLabel>
72
- </NewPhraseTextField>
73
- <PhraseDialogActions />
74
- {seedPhrase
75
- ? <SavedPhraseTextField showCopyButton={showCopyButton} />
76
- : null}
77
- {overwriteWarning
78
- ? <OverwriteWarning />
79
- : null}
80
- </DialogContent>
81
- <DialogActionButtons onClose={props.onClose} />
82
- </Dialog>
83
- )
84
- }
@@ -1,33 +0,0 @@
1
- import type { DialogActionsProps, DialogProps } from '@mui/material'
2
- import { Button, DialogActions } from '@mui/material'
3
- import type { MouseEvent } from 'react'
4
- import React from 'react'
5
-
6
- import { useSeedPhrase } from '../../../../contexts/index.ts'
7
-
8
- /** @public */
9
- export interface DialogActionButtonsProps extends DialogActionsProps {
10
- onClose?: DialogProps['onClose']
11
- }
12
-
13
- /** @public */
14
- export const DialogActionButtons: React.FC<DialogActionButtonsProps> = ({ onClose, ...props }) => {
15
- const { handleSave, setPhrase } = useSeedPhrase()
16
-
17
- const wrappedOnClose = (e: MouseEvent<HTMLElement>) => {
18
- // clear local copy of phrase when modal closes
19
- setPhrase?.('')
20
- onClose?.(e, 'escapeKeyDown')
21
- }
22
-
23
- return (
24
- <DialogActions {...props}>
25
- <Button variant="outlined" onClick={wrappedOnClose}>
26
- Cancel
27
- </Button>
28
- <Button type="submit" variant="contained" onClick={handleSave}>
29
- Save
30
- </Button>
31
- </DialogActions>
32
- )
33
- }
@@ -1,28 +0,0 @@
1
- import { Alert, Button } from '@mui/material'
2
- import { FlexRow } from '@xylabs/react-flexbox'
3
- import React from 'react'
4
-
5
- import { useSeedPhrase } from '../../../../contexts/index.ts'
6
-
7
- /** @public */
8
- export const OverwriteWarning = () => {
9
- const { handleCancelOverwrite, handleSave } = useSeedPhrase()
10
- return (
11
- <Alert
12
- variant="outlined"
13
- severity="warning"
14
- action={(
15
- <FlexRow sx={{ columnGap: 1 }}>
16
- <Button variant="outlined" color="inherit" size="small" onClick={handleSave}>
17
- Overwrite
18
- </Button>
19
- <Button variant="outlined" color="inherit" size="small" onClick={handleCancelOverwrite}>
20
- Cancel
21
- </Button>
22
- </FlexRow>
23
- )}
24
- >
25
- Are you sure you want to overwrite existing seed phrase? This action cannot be undone.
26
- </Alert>
27
- )
28
- }
@@ -1,45 +0,0 @@
1
- import type { StandardTextFieldProps } from '@mui/material'
2
- import { FormControl, TextField } from '@mui/material'
3
- import type { ReactNode } from 'react'
4
- import React from 'react'
5
-
6
- import { useSeedPhrase } from '../../../../../contexts/index.ts'
7
- import { colorParser, InvalidPhraseTypography } from './validation-messages/index.ts'
8
-
9
- /** @public */
10
- export interface NewPhraseTextFieldProps extends StandardTextFieldProps {
11
- children?: ReactNode
12
- disableColor?: boolean
13
- }
14
-
15
- /** @public */
16
- export const NewPhraseTextField: React.FC<NewPhraseTextFieldProps> = ({
17
- children, disableColor, ...props
18
- }) => {
19
- const {
20
- phrase, setPhrase, validPhrase,
21
- } = useSeedPhrase()
22
- return (
23
- <FormControl
24
- fullWidth
25
- size="small"
26
- sx={{
27
- display: 'flex', flexDirection: 'column', rowGap: 1,
28
- }}
29
- >
30
- {children}
31
- <TextField
32
- focused
33
- color={disableColor ? undefined : colorParser(validPhrase)}
34
- error={validPhrase === false}
35
- helperText={validPhrase === false ? <InvalidPhraseTypography /> : null}
36
- fullWidth
37
- maxRows={Number.POSITIVE_INFINITY}
38
- multiline
39
- onChange={e => setPhrase?.(e.target.value)}
40
- value={phrase}
41
- {...props}
42
- />
43
- </FormControl>
44
- )
45
- }
@@ -1,29 +0,0 @@
1
- import type { Meta, StoryFn } from '@storybook/react-vite'
2
- import React from 'react'
3
-
4
- import { SeedPhraseProvider } from '../../../../../contexts/index.ts'
5
- import { PhraseDialogActions } from './PhraseDialogActions.tsx'
6
-
7
- export default {
8
- title: 'Wallet/PhraseDialogActions',
9
- component: PhraseDialogActions,
10
- } as Meta
11
-
12
- const Template: StoryFn<typeof PhraseDialogActions> = args => (
13
- <SeedPhraseProvider>
14
- <PhraseDialogActions {...args} />
15
- </SeedPhraseProvider>
16
- )
17
-
18
- const Default = Template.bind({})
19
- Default.args = {}
20
-
21
- const WithHideGenerate = Template.bind({})
22
- WithHideGenerate.args = { hideGenerate: true }
23
-
24
- const WithHideClear = Template.bind({})
25
- WithHideClear.args = { hideClear: true }
26
-
27
- export {
28
- Default, WithHideClear, WithHideGenerate,
29
- }
@@ -1,38 +0,0 @@
1
- import type { DialogActionsProps } from '@mui/material'
2
- import { Button, DialogActions } from '@mui/material'
3
- import React from 'react'
4
-
5
- import { useSeedPhrase } from '../../../../../contexts/index.ts'
6
-
7
- export interface PhraseDialogActionsProps extends DialogActionsProps {
8
- hideClear?: boolean
9
- hideGenerate?: boolean
10
- }
11
-
12
- /** @public */
13
- export const PhraseDialogActions: React.FC<PhraseDialogActionsProps> = ({
14
- hideClear, hideGenerate, ...props
15
- }) => {
16
- const {
17
- handleClear, handleGenerate, overwriteWarning,
18
- } = useSeedPhrase()
19
- return (
20
- <DialogActions sx={{ justifyContent: 'center' }} {...props}>
21
- {hideGenerate
22
- ? null
23
- : (
24
- <Button disabled={overwriteWarning} variant="contained" onClick={handleGenerate}>
25
- Generate
26
- </Button>
27
- )}
28
- {hideClear
29
- ? null
30
- : (
31
- <Button variant="outlined" onClick={handleClear}>
32
- Clear
33
- </Button>
34
-
35
- )}
36
- </DialogActions>
37
- )
38
- }
@@ -1,113 +0,0 @@
1
- import { ContentCopy } from '@mui/icons-material'
2
- import type { StandardTextFieldProps } from '@mui/material'
3
- import {
4
- Chip, FormControl, FormLabel, IconButton, TextField,
5
- Tooltip,
6
- useTheme,
7
- } from '@mui/material'
8
- import { FlexRow } from '@xylabs/react-flexbox'
9
- import React, { useState } from 'react'
10
-
11
- import { useSeedPhrase } from '../../../../../contexts/index.ts'
12
- import { InvalidPhraseTypography, PhraseHeaderBox } from './validation-messages/index.ts'
13
-
14
- /** @public */
15
- export interface SavedPhraseTextFieldProps extends StandardTextFieldProps {
16
- fullWidth?: boolean
17
- showCopyButton?: boolean
18
- showPhraseHeader?: boolean
19
- visible?: boolean
20
- }
21
-
22
- /** @public */
23
- export const SavedPhraseTextField: React.FC<SavedPhraseTextFieldProps> = ({
24
-
25
- fullWidth, showCopyButton, showPhraseHeader, visible: visibleProp, ...props
26
- }) => {
27
- const { validSeedPhrase, seedPhrase } = useSeedPhrase()
28
- const theme = useTheme()
29
-
30
- const [visible, setVisible] = useState(visibleProp)
31
-
32
- const [previousVisibleProp, setPreviousVisibleProp] = useState(visibleProp)
33
- if (visibleProp !== previousVisibleProp) {
34
- setPreviousVisibleProp(visibleProp)
35
- setVisible(visibleProp)
36
- }
37
-
38
- const [copied, setCopied] = useState(false)
39
- const onCopyPhrase = async () => {
40
- if (seedPhrase) {
41
- try {
42
- await navigator.clipboard.writeText(seedPhrase)
43
- setCopied(true)
44
- setTimeout(() => setCopied(false), 2000)
45
- } catch (e) {
46
- console.error('Error copying resolvedSelectedAddress to clipboard', e)
47
- }
48
- }
49
- }
50
-
51
- return (
52
- <FormControl
53
- fullWidth={fullWidth}
54
- size="small"
55
- sx={{
56
- display: 'flex', flexDirection: 'column', rowGap: 1,
57
- }}
58
- >
59
- <FlexRow gap={0.5}>
60
- <Chip
61
- label="Show Seed Phrase"
62
- onClick={() => setVisible(!visible)}
63
- // Margin is set to 2px to match the Copy Button size and remove jumping during animation
64
- sx={{ alignSelf: 'center', my: '2px' }}
65
- />
66
- <Tooltip title={copied ? 'Copied!' : 'Copy'}>
67
- <IconButton
68
- onClick={() => void onCopyPhrase()}
69
- sx={{
70
- height: visible ? 'auto' : 0,
71
- opacity: visible ? 1 : 0,
72
- overflow: 'hidden',
73
- padding: visible ? theme.spacing(1) : 0,
74
- transition: 'all .25s ease-in-out',
75
- width: visible ? 'max-content' : 0,
76
- }}
77
- >
78
- <ContentCopy fontSize="small" />
79
- </IconButton>
80
- </Tooltip>
81
- </FlexRow>
82
- {visible && showPhraseHeader
83
- ? (
84
- <FormLabel>
85
- <PhraseHeaderBox conditional={validSeedPhrase}>Saved Seed Phrase</PhraseHeaderBox>
86
- </FormLabel>
87
- )
88
- : null}
89
- <TextField
90
- defaultValue={seedPhrase}
91
- disabled
92
- error={validSeedPhrase === false}
93
- helperText={validSeedPhrase === false ? <InvalidPhraseTypography /> : null}
94
- fullWidth
95
- maxRows={Number.POSITIVE_INFINITY}
96
- multiline
97
- slotProps={{
98
- input: {
99
- style: {
100
- height: visible ? 'auto' : '0',
101
- overflow: 'hidden',
102
- opacity: visible ? 1 : 0,
103
- padding: visible ? theme.spacing(1) : 0,
104
- transition: 'all .25s ease-in-out',
105
- },
106
- },
107
- }}
108
- {...props}
109
- />
110
-
111
- </FormControl>
112
- )
113
- }
@@ -1,4 +0,0 @@
1
- export * from './NewPhraseTextField.tsx'
2
- export * from './PhraseDialogActions.tsx'
3
- export * from './SavedPhraseTextField.tsx'
4
- export * from './validation-messages/index.ts'