-
Notifications
You must be signed in to change notification settings - Fork 557
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add image component for showing images as part of snaps custom UI. Also adds support for this feature in the snaps simulator. This PR will need follow-up work in the extension. Progresses MetaMask/MetaMask-planning#1345 --------- Co-authored-by: MetaMask Bot <metamaskbot@users.noreply.github.com>
- Loading branch information
1 parent
eeab196
commit 50ce7fd
Showing
37 changed files
with
356 additions
and
99 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
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,62 @@ | ||
import { Flex, Text } from '@chakra-ui/react'; | ||
import type { FunctionComponent } from 'react'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
import { Icon } from './Icon'; | ||
|
||
export type CopyableProps = { | ||
value: string; | ||
}; | ||
|
||
export const Copyable: FunctionComponent<CopyableProps> = ({ value }) => { | ||
const [copied, setCopied] = useState(false); | ||
|
||
const handleClick = () => { | ||
navigator.clipboard | ||
.writeText(value) | ||
.then(() => { | ||
setCopied(true); | ||
}) | ||
.catch((error) => { | ||
// eslint-disable-next-line no-console | ||
console.error(error); | ||
}); | ||
}; | ||
|
||
// eslint-disable-next-line consistent-return | ||
useEffect(() => { | ||
if (copied) { | ||
const timeout = setTimeout(() => { | ||
setCopied(false); | ||
}, 2000); | ||
|
||
return () => clearTimeout(timeout); | ||
} | ||
}, [copied]); | ||
|
||
return ( | ||
<Flex | ||
padding="2" | ||
borderRadius="md" | ||
background="background.alternative" | ||
justifyContent="space-between" | ||
marginBottom="1" | ||
wordBreak="break-word" | ||
> | ||
<Text | ||
fontFamily="custom" | ||
color="text.alternative" | ||
fontSize="sm" | ||
lineHeight="157%" | ||
> | ||
{value} | ||
</Text> | ||
<Icon | ||
icon={copied ? 'copied' : 'copy'} | ||
width="15px" | ||
cursor="pointer" | ||
onClick={handleClick} | ||
/> | ||
</Flex> | ||
); | ||
}; |
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
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
41 changes: 41 additions & 0 deletions
41
packages/snaps-simulator/src/features/builder/components/ErrorBoundary.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,41 @@ | ||
import React from 'react'; | ||
|
||
type ErrorBoundaryProps = { | ||
fallback: React.ReactNode; | ||
children: React.ReactNode; | ||
}; | ||
|
||
type ErrorBoundaryState = { | ||
hasError: boolean; | ||
}; | ||
|
||
export class ErrorBoundary extends React.Component< | ||
ErrorBoundaryProps, | ||
ErrorBoundaryState | ||
> { | ||
constructor(props: ErrorBoundaryProps) { | ||
super(props); | ||
|
||
this.state = { hasError: false }; | ||
} | ||
|
||
componentDidUpdate(prevProps: ErrorBoundaryProps) { | ||
if (prevProps.children !== this.props.children) { | ||
this.setState({ hasError: false }); | ||
} | ||
} | ||
|
||
static getDerivedStateFromError() { | ||
// Update state so the next render will show the fallback UI. | ||
return { hasError: true }; | ||
} | ||
|
||
render() { | ||
if (this.state.hasError) { | ||
// You can render any custom fallback UI | ||
return this.props.fallback; | ||
} | ||
|
||
return this.props.children; | ||
} | ||
} |
Oops, something went wrong.