Browse Source

Merge pull request #654 from gre/fix-error-step

fix errors in steps
master
Meriadec Pillet 7 years ago
committed by GitHub
parent
commit
91d7fc14e1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/components/Breadcrumb/Step.js
  2. 8
      src/components/modals/Receive/index.js
  3. 20
      src/components/modals/Send/index.js

2
src/components/Breadcrumb/Step.js

@ -29,7 +29,7 @@ const Wrapper = styled(Box).attrs({
const StepNumber = styled(Box).attrs({ const StepNumber = styled(Box).attrs({
alignItems: 'center', alignItems: 'center',
justifyContent: 'center', justifyContent: 'center',
color: p => (['active', 'valid'].includes(p.status) ? 'white' : 'fog'), color: p => (['active', 'valid', 'error'].includes(p.status) ? 'white' : 'fog'),
bg: p => bg: p =>
['active', 'valid'].includes(p.status) ? 'wallet' : p.status === 'error' ? 'alertRed' : 'white', ['active', 'valid'].includes(p.status) ? 'wallet' : p.status === 'error' ? 'alertRed' : 'white',
ff: 'Rubik|Regular', ff: 'Rubik|Regular',

8
src/components/modals/Receive/index.js

@ -61,6 +61,8 @@ const INITIAL_STATE = {
stepIndex: 0, stepIndex: 0,
stepsDisabled: [], stepsDisabled: [],
stepsErrors: [], stepsErrors: [],
// FIXME the two above can be derivated from other info (if we keep error etc)
// we can get rid of it after a big refactoring (see how done in Send)
} }
const mapStateToProps = createStructuredSelector({ const mapStateToProps = createStructuredSelector({
@ -232,12 +234,12 @@ class ReceiveModal extends PureComponent<Props, State> {
}) })
} }
this.setState({ addressVerified: true, stepIndex: 3 }) this.handleCheckAddress(true)
} else { } else {
this.setState({ addressVerified: false }) this.handleCheckAddress(false)
} }
} catch (err) { } catch (err) {
this.setState({ addressVerified: false }) this.handleCheckAddress(false)
} }
} }

20
src/components/modals/Send/index.js

@ -57,6 +57,7 @@ type Step = {
canNext: (State<*>) => boolean, canNext: (State<*>) => boolean,
canPrev: (State<*>) => boolean, canPrev: (State<*>) => boolean,
canClose: (State<*>) => boolean, canClose: (State<*>) => boolean,
hasError: (State<*>) => boolean,
prevStep?: number, prevStep?: number,
} }
@ -91,6 +92,7 @@ class SendModal extends Component<Props, State<*>> {
bridge && account && transaction bridge && account && transaction
? bridge.isValidTransaction(account, transaction) ? bridge.isValidTransaction(account, transaction)
: false, : false,
hasError: () => false,
}, },
{ {
label: t('app:send.steps.connectDevice.title'), label: t('app:send.steps.connectDevice.title'),
@ -99,6 +101,7 @@ class SendModal extends Component<Props, State<*>> {
deviceSelected !== null && appStatus === 'success', deviceSelected !== null && appStatus === 'success',
prevStep: 0, prevStep: 0,
canPrev: () => true, canPrev: () => true,
hasError: () => false,
}, },
{ {
label: t('app:send.steps.verification.title'), label: t('app:send.steps.verification.title'),
@ -106,6 +109,7 @@ class SendModal extends Component<Props, State<*>> {
canNext: () => true, canNext: () => true,
canPrev: ({ error }) => !!error, canPrev: ({ error }) => !!error,
prevStep: 0, prevStep: 0,
hasError: ({ error }) => (error && error.name === 'UserRefusedOnDevice') || false,
}, },
{ {
label: t('app:send.steps.confirmation.title'), label: t('app:send.steps.confirmation.title'),
@ -113,6 +117,7 @@ class SendModal extends Component<Props, State<*>> {
canClose: () => true, canClose: () => true,
canPrev: () => true, canPrev: () => true,
canNext: () => false, canNext: () => false,
hasError: ({ error }) => (error && error.name !== 'UserRefusedOnDevice') || false,
}, },
] ]
} }
@ -273,6 +278,13 @@ class SendModal extends Component<Props, State<*>> {
const canNext = step.canNext(this.state) const canNext = step.canNext(this.state)
const canPrev = step.canPrev(this.state) const canPrev = step.canPrev(this.state)
const stepsErrors = []
this.steps.forEach((s, i) => {
if (s.hasError(this.state)) {
stepsErrors.push(i)
}
})
return ( return (
<Modal <Modal
name={MODAL_SEND} name={MODAL_SEND}
@ -290,7 +302,13 @@ class SendModal extends Component<Props, State<*>> {
</ModalTitle> </ModalTitle>
<ModalContent> <ModalContent>
<Breadcrumb t={t} mb={6} currentStep={stepIndex} items={this.steps} /> <Breadcrumb
t={t}
mb={6}
currentStep={stepIndex}
stepsErrors={stepsErrors}
items={this.steps}
/>
<ChildSwitch index={stepIndex}> <ChildSwitch index={stepIndex}>
<StepAmount <StepAmount

Loading…
Cancel
Save