From 0599ff2e01ce210246873a1f1220f51c01062091 Mon Sep 17 00:00:00 2001 From: HenryNguyen5 Date: Thu, 8 Feb 2018 16:52:06 -0500 Subject: [PATCH] POC --- common/components/NonceField.tsx | 44 ++++++++++++++------- common/components/ui/InlineSpinner.tsx | 54 +++++++++++++++++++++++++- 2 files changed, 82 insertions(+), 16 deletions(-) diff --git a/common/components/NonceField.tsx b/common/components/NonceField.tsx index 3bf41a78..83936bff 100644 --- a/common/components/NonceField.tsx +++ b/common/components/NonceField.tsx @@ -3,7 +3,7 @@ import { NonceFieldFactory } from 'components/NonceFieldFactory'; import Help from 'components/ui/Help'; import RefreshIcon from 'assets/images/refresh.svg'; import './NonceField.scss'; -import { InlineSpinner } from 'components/ui/InlineSpinner'; +import { InlineSpinner, DelayLoader } from 'components/ui/InlineSpinner'; import { connect } from 'react-redux'; import { getNonceRequested, TGetNonceRequested } from 'actions/transaction'; import { nonceRequestPending } from 'selectors/transaction'; @@ -26,6 +26,23 @@ type Props = OwnProps & DispatchProps & StateProps; class NonceField extends React.Component { public render() { const { alwaysDisplay, requestNonce, nonePending } = this.props; + + const X = ({ value, raw, readOnly, onChange }) => ( +
+ + +
+ ); + return ( { @@ -39,21 +56,18 @@ class NonceField extends React.Component { 'https://myetherwallet.github.io/knowledge-base/transactions/what-is-nonce.html' } /> -
- -
-
- + +
+ + } + passedProps={{ value, raw, readOnly, onChange }} + showLoader={nonePending} + withProps={p => } /> -
) : null; diff --git a/common/components/ui/InlineSpinner.tsx b/common/components/ui/InlineSpinner.tsx index 193c3d10..1695cdad 100644 --- a/common/components/ui/InlineSpinner.tsx +++ b/common/components/ui/InlineSpinner.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { Component } from 'react'; import { CSSTransition } from 'react-transition-group'; import { Spinner } from 'components/ui'; import './InlineSpinner.scss'; @@ -15,3 +15,55 @@ export const InlineSpinner: React.SFC<{
); + +interface Props { + passedProps: T; + showLoader: boolean; + loader: React.ReactElement; + delay: number; + withProps(props: T): React.ReactElement | null; +} + +interface State { + shouldShowLoader: boolean; + propsToPass: T; + waitOnTimeout: boolean; +} + +export class DelayLoader extends Component, State> { + constructor(props: Props) { + super(props); + this.state = { + propsToPass: props.passedProps, + shouldShowLoader: props.showLoader, + waitOnTimeout: false + }; + } + + public componentWillReceiveProps(nextProps: Props) { + if (this.state.shouldShowLoader === nextProps.showLoader && !this.state.waitOnTimeout) { + this.setState({ propsToPass: nextProps.passedProps }); + } else if (nextProps.showLoader) { + this.setState({ shouldShowLoader: true, waitOnTimeout: true }); + } else { + window.setTimeout( + () => + this.setState({ + propsToPass: nextProps.passedProps, + shouldShowLoader: false, + waitOnTimeout: false + }), + this.props.delay + ); + } + } + + public render() { + return ( + <> + {this.state.shouldShowLoader && this.props.loader}{' '} + {this.props.withProps(this.state.propsToPass)}{' '} + + ); + } +}