Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Commit

Permalink
feat: verify address provided by user is valid (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 authored Mar 2, 2019
1 parent 7d22dbf commit d643d80
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/views/reverse/reverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class ReverseSwap extends React.Component {
isFetching,
swapResponse,
completeSwap,
goTimelockExpired,
startReverseSwap,
swapFailResponse,
goTimelockExpired,
setReverseSwapAddress,
} = this.props;

Expand Down Expand Up @@ -99,7 +99,7 @@ class ReverseSwap extends React.Component {
<Controls
loading={!swapInfo.address}
text={'Next'}
loadingText={`Input a ${getCurrencyName(
loadingText={`Input a valid ${getCurrencyName(
swapInfo.quote
)} address`}
loadingRender={() => undefined}
Expand Down
28 changes: 24 additions & 4 deletions src/views/reverse/steps/inputAddress.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import React from 'react';
import PropTypes from 'prop-types';
import injectSheet from 'react-jss';
import { address } from 'bitcoinjs-lib';
import View from '../../../components/view';
import InputArea from '../../../components/inputarea';
import { getCurrencyName, getSampleAddress } from '../../../scripts/utils';
import {
getCurrencyName,
getSampleAddress,
getNetwork,
} from '../../../scripts/utils';

const inputAddressStyles = () => ({
wrapper: {
Expand All @@ -22,12 +27,27 @@ class StyledInputAddress extends React.Component {
error: false,
};

showError = () => {
this.props.onChange(undefined);
this.setState({ error: true });
};

onChange = input => {
this.props.onChange(input);
const { onChange, swapInfo } = this.props;

if (input !== '') {
this.setState({ error: false });
try {
const swapAddress = input.trim();

address.toOutputScript(swapAddress, getNetwork(swapInfo.quote));

onChange(swapAddress);
this.setState({ error: false });
} catch (error) {
this.showError();
}
} else {
this.setState({ error: true });
this.showError();
}
};

Expand Down

0 comments on commit d643d80

Please sign in to comment.