import { RestartSwapAction } from 'actions/swap'; import { SwapInput } from 'reducers/swap/types'; import React, { Component } from 'react'; import translate from 'translations'; import { toFixedIfLarger } from 'utils/formatters'; import './SwapInfoHeader.scss'; import SwapInfoHeaderTitle from './SwapInfoHeaderTitle'; export interface SwapInfoHeaderProps { origin: SwapInput; destination: SwapInput; reference: string; secondsRemaining: number | null; restartSwap(): RestartSwapAction; } export default class SwapInfoHeader extends Component { public computedOriginDestinationRatio = () => { const { origin, destination } = this.props; if (!origin.amount || !destination.amount) { return; } return destination.amount / origin.amount; }; public isExpanded = () => { const { reference, restartSwap } = this.props; return reference && restartSwap; }; public computedClass = () => { if (this.isExpanded()) { return 'SwapInfo-details-block col-sm-3'; } else { return 'SwapInfo-details-block col-sm-4'; } }; public formattedTime = () => { const { secondsRemaining } = this.props; if (secondsRemaining || secondsRemaining === 0) { const minutes = Math.floor(secondsRemaining / 60); const seconds = secondsRemaining - minutes * 60; const stringMinutes = minutes < 10 ? '0' + minutes : minutes; const stringSeconds = seconds < 10 ? '0' + seconds : seconds; return stringMinutes + ':' + stringSeconds; } else { throw Error('secondsRemaining must be a number'); } }; public render() { const computedOriginDestinationRatio = this.computedOriginDestinationRatio(); const { reference, origin, destination, restartSwap } = this.props; return (
{/*Amount to send*/} {!this.isExpanded() && (

{` ${origin.amount} ${origin.id}`}

{translate('SEND_amount')}

)} {/*Reference Number*/} {this.isExpanded() && (

{reference}

{translate('SWAP_ref_num')}

)} {/*Time remaining*/} {this.isExpanded() && (

{this.formattedTime()}

{translate('SWAP_time')}

)} {/*Amount to Receive*/}

{` ${destination.amount} ${destination.id}`}

{translate('SWAP_rec_amt')}

{/*Your rate*/}

{`${computedOriginDestinationRatio && toFixedIfLarger(computedOriginDestinationRatio)} ${destination.id}/${origin.id}`}

{translate('SWAP_your_rate')}

); } }