import { TBityOrderCreateRequestedSwap, TChangeStepSwap, TDestinationAddressSwap, TShapeshiftOrderCreateRequestedSwap, TStopLoadBityRatesSwap } from 'actions/swap'; import { SwapInput } from 'reducers/swap/types'; import classnames from 'classnames'; import SimpleButton from 'components/ui/SimpleButton'; import { donationAddressMap } from 'config/data'; import { isValidBTCAddress, isValidETHAddress } from 'libs/validators'; import React, { Component } from 'react'; import translate from 'translations'; import { combineAndUpper } from 'utils/formatters'; import './ReceivingAddress.scss'; export interface StateProps { origin: SwapInput; destinationId: keyof typeof donationAddressMap; isPostingOrder: boolean; destinationAddress: string; destinationKind: number; provider: string; } export interface ActionProps { destinationAddressSwap: TDestinationAddressSwap; changeStepSwap: TChangeStepSwap; stopLoadBityRatesSwap: TStopLoadBityRatesSwap; bityOrderCreateRequestedSwap: TBityOrderCreateRequestedSwap; shapeshiftOrderCreateRequestedSwap: TShapeshiftOrderCreateRequestedSwap; } export default class ReceivingAddress extends Component { public onChangeDestinationAddress = (event: React.FormEvent) => { const value = event.currentTarget.value; this.props.destinationAddressSwap(value); }; public onClickPartTwoComplete = () => { const { origin, destinationId, destinationAddress, destinationKind, provider } = this.props; if (!origin) { return; } if (provider === 'shapeshift') { this.props.shapeshiftOrderCreateRequestedSwap( destinationAddress, origin.id, destinationId, destinationKind ); } else { this.props.bityOrderCreateRequestedSwap( origin.amount as number, this.props.destinationAddress, combineAndUpper(origin.id, destinationId) ); } }; public render() { const { destinationId, destinationAddress, isPostingOrder } = this.props; let validAddress; // TODO - find better pattern here once currencies move beyond BTC, ETH, REP if (destinationId === 'BTC') { validAddress = isValidBTCAddress(destinationAddress); } else { validAddress = isValidETHAddress(destinationAddress); } const inputClasses = classnames({ 'SwapAddress-address-input': true, 'form-control': true, 'is-valid': validAddress, 'is-invalid': !validAddress }); return (
); } }