diff --git a/packages/apps/src/Content/index.tsx b/packages/apps/src/Content/index.tsx index 9e8e5ca39c..8042549f73 100644 --- a/packages/apps/src/Content/index.tsx +++ b/packages/apps/src/Content/index.tsx @@ -58,7 +58,7 @@ function Content ({ className }: Props): React.ReactElement { : ( <> - + void; -} +function Propose ({ isMine, sudoKey }: Props): React.ReactElement { + const { t } = useTranslation(); + const { apiDefaultTxSudo } = useApi(); + const [method, setMethod] = useState | null>(null); -interface State { - method: SubmittableExtrinsic<'promise'> | null; - isValid: boolean; -} + const _onChangeExtrinsic = useCallback( + (method: SubmittableExtrinsic<'promise'> | null = null) => + setMethod(() => method), + [] + ); -class Propose extends TxComponent { - public state: State = { - isValid: false, - method: null - }; - - public render (): React.ReactNode { - const { apiDefaultTxSudo, isMine, sudoKey, t } = this.props; - const { isValid, method } = this.state; - - return isMine - ? ( -
- + +
+ + -
- - - -
- ) - : ( -
-
- - {t('You do not have access to the current sudo key')} -
-
- ); - } - - private nextState (newState: Partial): void { - this.setState( - (prevState: State): State => { - const { method = prevState.method } = newState; - - return { - isValid: !!method, - method - }; - } + + + ) + : ( +
+
+ + {t('You do not have access to the current sudo key')} +
+
); - } - - private onChangeExtrinsic = (method?: SubmittableExtrinsic<'promise'>): void => { - if (!method) { - return; - } - - this.nextState({ method }); - } } -export default withMulti( - Propose, - translate, - withApi -); +export default React.memo(Propose); diff --git a/packages/react-components/src/ErrorBoundary.tsx b/packages/react-components/src/ErrorBoundary.tsx index c5c616aa82..a275025f9b 100644 --- a/packages/react-components/src/ErrorBoundary.tsx +++ b/packages/react-components/src/ErrorBoundary.tsx @@ -12,24 +12,31 @@ interface Props extends I18nProps { children: React.ReactNode; doThrow?: boolean; onError?: () => void; + trigger?: any; } interface State { - hasError: boolean; + error: Error | null; + prevTrigger: string | null; } // NOTE: This is the only way to do an error boundary, via extend class ErrorBoundary extends React.Component { - state: State = { hasError: false }; + state: State = { error: null, prevTrigger: null }; - // eslint-disable-next-line @typescript-eslint/no-unused-vars - static getDerivedStateFromError (_error: Error): State { - // Update state so the next render will show the fallback UI. - return { hasError: true }; + static getDerivedStateFromError (error: Error): Partial { + return { error }; } - // eslint-disable-next-line @typescript-eslint/no-unused-vars - public componentDidCatch (error: Error, _errorInfo: any): void { + static getDerivedStateFromProps ({ trigger }: Props, { prevTrigger }: State): State | null { + const newTrigger = JSON.stringify({ trigger }); + + return (prevTrigger !== newTrigger) + ? { error: null, prevTrigger: newTrigger } + : null; + } + + public componentDidCatch (error: Error): void { const { doThrow, onError } = this.props; onError && onError(); @@ -41,12 +48,16 @@ class ErrorBoundary extends React.Component { public render (): React.ReactNode { const { children, t } = this.props; - const { hasError } = this.state; + const { error } = this.state; - return hasError + return error ? (
- {t('Uncaught error. Something went wrong with the query and rendering of this component.')} + {t('Uncaught error. Something went wrong with the query and rendering of this component. {{message}}', { + replace: { + message: error.message + } + })}
) : children; diff --git a/packages/react-components/src/IdentityIcon.tsx b/packages/react-components/src/IdentityIcon.tsx index 47d6c04197..c030d87d84 100644 --- a/packages/react-components/src/IdentityIcon.tsx +++ b/packages/react-components/src/IdentityIcon.tsx @@ -60,11 +60,12 @@ function IdentityIcon ({ className, onCopy, prefix, size, theme, value }: Props) return ( .text > .ui--KeyPair { - .ui--IdentityIcon { + .ui--IdentityIcon-Outer { border: 1px solid #888; border-radius: 50%; left: -2.75rem;