From 4698803ff5f4a6be2efbf0903cf2a8083b50a0d4 Mon Sep 17 00:00:00 2001 From: mroz Date: Tue, 30 Aug 2022 16:50:41 +0200 Subject: [PATCH] wip --- packages/components/package.json | 2 +- .../Passphrase/PassphraseTypeCard.tsx | 99 +++++++++++-------- .../src/components/Tooltip/index.tsx | 2 +- packages/components/src/config/motion.ts | 4 + packages/connect-explorer/README.md | 2 +- packages/connect-popup/package.json | 10 +- packages/connect-popup/src/index.tsx | 36 +++---- packages/connect-popup/src/view/common.tsx | 21 ++-- .../src/view/react/StylesSheetWrapper.tsx | 6 +- packages/connect-ui/package.json | 7 +- .../src/components/ThemeWrapper.tsx | 24 ----- packages/connect-ui/src/components/View.tsx | 13 ++- packages/connect-ui/src/index.ts | 8 -- packages/connect-ui/src/index.tsx | 39 ++++++++ .../connect-ui/src/support/ErrorBoundary.tsx | 28 ++++++ .../connect-ui/src/support/IntlWrapper.tsx | 23 +++++ .../connect-ui/src/support/ThemeWrapper.tsx | 13 +++ packages/connect-ui/src/views/Passphrase.tsx | 66 ++++++++++--- .../src/views/PassphraseOnDevice.tsx | 5 +- packages/connect-ui/src/views/Transport.tsx | 3 + packages/connect-ui/tsconfig.json | 1 + packages/connect/src/events/ui-request.ts | 69 ++++++++++--- .../suite/src/components/onboarding/Box.tsx | 7 +- .../ConnectDevicePromptManager/index.tsx | 4 +- .../src/components/suite/CollapsibleBox.tsx | 4 +- .../components/suite/ConnectDevicePrompt.tsx | 4 +- .../suite/PrerequisitesGuide/index.tsx | 5 +- .../suite/modals/Passphrase/index.tsx | 22 +++++ yarn.lock | 27 ++++- 29 files changed, 384 insertions(+), 170 deletions(-) delete mode 100644 packages/connect-ui/src/components/ThemeWrapper.tsx delete mode 100644 packages/connect-ui/src/index.ts create mode 100644 packages/connect-ui/src/index.tsx create mode 100644 packages/connect-ui/src/support/ErrorBoundary.tsx create mode 100644 packages/connect-ui/src/support/IntlWrapper.tsx create mode 100644 packages/connect-ui/src/support/ThemeWrapper.tsx diff --git a/packages/components/package.json b/packages/components/package.json index c430268d24be..afb821a31c97 100644 --- a/packages/components/package.json +++ b/packages/components/package.json @@ -5,7 +5,6 @@ "main": "src/index", "author": "SatoshiLabs s.r.o.", "license": "SEE LICENSE IN LICENSE.md", - "sideEffects": false, "scripts": { "lint": "yarn lint:js && yarn lint:styles", "lint:js": "yarn g:eslint '**/*.{ts,tsx,js}'", @@ -24,6 +23,7 @@ "lottie-react": "^2.3.1", "polished": "^4.2.2", "react-date-range": "^1.4.0", + "react-intl": "^6.0.5", "react-select": "^5.4.0", "react-svg": "^15.1.6", "react-truncate": "^2.4.0", diff --git a/packages/components/src/components/Passphrase/PassphraseTypeCard.tsx b/packages/components/src/components/Passphrase/PassphraseTypeCard.tsx index 81140e17f1e6..493330708fb1 100644 --- a/packages/components/src/components/Passphrase/PassphraseTypeCard.tsx +++ b/packages/components/src/components/Passphrase/PassphraseTypeCard.tsx @@ -1,40 +1,36 @@ // pull this component up to some share logic. // todo: reorganize imports - import React, { useState, useRef, useEffect, useCallback } from 'react'; +import { FormattedMessage, useIntl } from 'react-intl'; + import { AnimatePresence, motion } from 'framer-motion'; +import styled, { css } from 'styled-components'; + import { useKeyPress } from '@trezor/react-utils'; import { setCaretPosition } from '@trezor/dom-utils'; -import styled, { css } from 'styled-components'; +import { countBytesInString } from '@trezor/utils'; -// ok import { Button, useTheme, variables, Input, Tooltip, + TooltipProps, Checkbox, Icon, motionProps, -} from '@trezor/components'; -import { countBytesInString } from '@trezor/utils'; - -// move to another package, shared package should not import from suite - -// moved +} from '../..'; import PasswordStrengthIndicator from './PasswordStrengthIndicator'; const MAX_LENGTH = 50; // todo: refactor these, translations, modal, etc -// import { useTranslation } from '@suite-hooks'; -// import { OpenGuideFromTooltip } from '@guide-components'; -// import { Translation } from '@suite-components/Translation'; + // import { isAndroid } from '@trezor/suite/src/utils/suite/env'; -const Wrapper = styled.div>` +const Wrapper = styled.div>` display: flex; flex: 1; /* align-items: center; */ @@ -61,7 +57,7 @@ const Wrapper = styled.div>` `} `; -const IconWrapper = styled.div>` +const IconWrapper = styled.div>` width: 38px; height: 38px; background: ${props => @@ -96,7 +92,7 @@ const WalletTitle = styled.div<{ withMargin: boolean }>` ${props => props.withMargin && `margin-bottom: 5px;`} `; -const Description = styled.div>` +const Description = styled.div>` display: flex; color: ${props => props.theme.TYPE_LIGHT_GREY}; font-size: ${variables.FONT_SIZE.TINY}; @@ -172,10 +168,7 @@ const RetryButton = styled(Button)` margin-top: 16px; `; -// todo: how about translations? pass translation component? pass translated string? -const Translation = ({ id }: { id: string }) =>
{id}
; - -type Props = { +type PassphraseTypeCardProps = { title?: React.ReactNode; description?: React.ReactNode; submitLabel: React.ReactNode; @@ -185,13 +178,17 @@ type Props = { authConfirmation?: boolean; onSubmit: (value: string, passphraseOnDevice?: boolean) => void; recreateWallet?: () => void; + learnMoreTooltipOnClick?: TooltipProps['guideAnchor']; + learnMoreTooltipAppendTo?: TooltipProps['appendTo']; }; const DOT = '●'; -export const PassphraseTypeCard = (props: Props) => { +export const PassphraseTypeCard = (props: PassphraseTypeCardProps) => { + console.log('PassphraseTypeCard', props); + const theme = useTheme(); - // const { translationString } = useTranslation(); + const intl = useIntl(); const [value, setValue] = useState(''); const [enabled, setEnabled] = useState(!props.authConfirmation); const [showPassword, setShowPassword] = useState(false); @@ -208,7 +205,6 @@ export const PassphraseTypeCard = (props: Props) => { const { onSubmit } = props; const submit = useCallback( (value: string, passphraseOnDevice?: boolean) => { - console.log('enabled', enabled); if (!enabled) return; onSubmit(value, passphraseOnDevice); }, @@ -309,16 +305,22 @@ export const PassphraseTypeCard = (props: Props) => { > {props.type === 'hidden' ? ( } - // guideAnchor={instance => ( - // - // )} - // content={} - title={
"todo: pass tooltip as prop?"
} + appendTo={props.learnMoreTooltipAppendTo} + title={ + + } + guideAnchor={props.learnMoreTooltipOnClick} + content={ +