mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-01-12 12:04:21 +00:00
88532cdc3c
* progress * Normalize bity api response * Filter api response * Track swap information in component state * Update dropdown onchange * remove dead code * Update Min Max Validation * Update minmax err msg && fix onChangeOriginKind * Add origin & destination to redux state * Update types & Update tests * Update types * Update swap.spec.ts test * Remove commented out code * Remove hardcoded coin array * Create types.ts for swap reducer * Update swapinput type * Update bityRates in localStorage & Replace all instances of ...Kind / ...Amount props * Add shapeshift banner * initial work for sagas * Update Types * Update swap reducer initial state * Update Types & Store empty obj for bityRates / options * Update more types * added shapeshift file and rates comments * action reducers and prop mapping to components * add typings and swap icon * more actions reducers and sagas * debugging shapeshift service * add Headers * Fix content type * add order reset saga and ui fixes * remove console log and swap b/w Bity and Shapeshift * working state for Shapeshift and Bity - tested with mainnet * add icon component * UI improvements and fix select bug * fix timer bug * add bity fallback options and toFixed floats * tslint errors * add arrow to dropdown and add support footer * Add service provider * fix minor $ bug and stop timer on order complete * better load UX and dropdown UX * fixed single test * currRate prop bugs and reduce LS bloat * takeEvery on timer saga and don't clear state.options to restartSwap reducer * export tx sagas and fix minor type * Add ShapeShift Rates functionality when selecting a ShapeShift pair. * type fixes * BugFix: Don't change displayed ShapeShift Rate Inputs on every dropdown change Also contains some caching / performance improvements * BugFix: Don't remote rate inputs when falsy amount * fix type error * Progress commit * Implement saga logic * Make address field factory component * Shorten debounce time * Make new actions / sagas for handling single token lookup * Implement working version of litesend * Change saga into selector * Add failing spec * fix broken test * add debounce to error message * fix tests * update snapshots * test coverage * move setState disabled property from debounce so we instantly can go to next step on valid amounts * much deeper test coverage, fix debounce ux, and fix bity flashing at swap page load * fix minor failing test * seperate shapeshift erc20 token whitelist * fix saveState store bug * break orderTimeRemaining saga up and rewrite tests * add new swap icon * remove unused allowReadOnly prop * change offlineaware to walletdecrypt for litesend * fix LiteSend changewallet bug * fix error message UX * fix button styling to match develop * fix liteSend test * Fix LiteSend UX on unavl tokens, dropdown null value, and don't show decrypt in litesend after successful wallet decrypt. * add litesend network check
114 lines
4.0 KiB
TypeScript
114 lines
4.0 KiB
TypeScript
import { RestartSwapAction } from 'actions/swap';
|
|
import { SwapInput } from 'reducers/swap/types';
|
|
import React, { Component } from 'react';
|
|
import translate from 'translations';
|
|
import classnames from 'classnames';
|
|
import { toFixedIfLarger } from 'utils/formatters';
|
|
import './SwapInfoHeader.scss';
|
|
import SwapInfoHeaderTitle from './SwapInfoHeaderTitle';
|
|
|
|
export interface SwapInfoHeaderProps {
|
|
origin: SwapInput;
|
|
destination: SwapInput;
|
|
reference: string;
|
|
secondsRemaining: number | null;
|
|
provider: string;
|
|
restartSwap(): RestartSwapAction;
|
|
}
|
|
|
|
export default class SwapInfoHeader extends Component<SwapInfoHeaderProps, {}> {
|
|
public computedOriginDestinationRatio = () => {
|
|
const { origin, destination } = this.props;
|
|
if (!origin.amount || !destination.amount) {
|
|
return;
|
|
}
|
|
return (destination.amount as number) / (origin.amount as number);
|
|
};
|
|
|
|
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, provider } = this.props;
|
|
const SwapInfoHeaderTitleProps = {
|
|
restartSwap,
|
|
provider
|
|
};
|
|
const referenceClass = classnames(
|
|
provider === 'shapeshift' && 'SwapInfo-details-block-shapeshift',
|
|
'SwapInfo-details-block-value'
|
|
);
|
|
return (
|
|
<div className="SwapInfo">
|
|
<SwapInfoHeaderTitle {...SwapInfoHeaderTitleProps} />
|
|
<section className="SwapInfo-details row">
|
|
{/*Amount to send*/}
|
|
{!this.isExpanded() && (
|
|
<div className={this.computedClass()}>
|
|
<h3 className="SwapInfo-details-block-value">{` ${origin.amount} ${origin.id}`}</h3>
|
|
<p className="SwapInfo-details-block-label">{translate('SEND_amount')}</p>
|
|
</div>
|
|
)}
|
|
|
|
{/*Reference Number*/}
|
|
{this.isExpanded() && (
|
|
<div className={this.computedClass()}>
|
|
<h3 className={referenceClass}>{reference}</h3>
|
|
<p className="SwapInfo-details-block-label">{translate('SWAP_ref_num')}</p>
|
|
</div>
|
|
)}
|
|
|
|
{/*Time remaining*/}
|
|
{this.isExpanded() && (
|
|
<div className={this.computedClass()}>
|
|
<h3 className="SwapInfo-details-block-value">{this.formattedTime()}</h3>
|
|
<p className="SwapInfo-details-block-label">{translate('SWAP_time')}</p>
|
|
</div>
|
|
)}
|
|
|
|
{/*Amount to Receive*/}
|
|
<div className={this.computedClass()}>
|
|
<h3 className="SwapInfo-details-block-value">
|
|
{` ${toFixedIfLarger(destination.amount as number, 4)} ${destination.id}`}
|
|
</h3>
|
|
<p className="SwapInfo-details-block-label">{translate('SWAP_rec_amt')}</p>
|
|
</div>
|
|
|
|
{/*Your rate*/}
|
|
<div className={this.computedClass()}>
|
|
<h3 className="SwapInfo-details-block-value">
|
|
{`${computedOriginDestinationRatio &&
|
|
toFixedIfLarger(computedOriginDestinationRatio, 4)} ${destination.id}/${origin.id}`}
|
|
</h3>
|
|
<p className="SwapInfo-details-block-label">{translate('SWAP_your_rate')}</p>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
);
|
|
}
|
|
}
|