MyCrypto/common/components/ui/SimpleButton.jsx
Daniel Ternyak a66337ac0a Swap Part 4 (#101)
### Re-implements:
* min/max validators on initial currency swap selection
* polling of order status
* timer that persists across refreshes via localStorage (computed based on `createdTime` and `validFor` amount)
* swap persists across refreshes once order is created.
* various type refactors

### New additions:
* *SimpleButton* (can be PRd separately on request)
* clear loading state after order create (via SimpleButton and font-awesome)
* buffers for non-BTC swaps (bity does not actually accept 0.01 BTC worth of ETH as they claim they do in their JSON response, so a magic number of 10% is added to the minimum).
2017-07-31 18:14:30 -05:00

61 lines
1.2 KiB
JavaScript

// @flow
import React, { Component } from 'react';
const DEFAULT_BUTTON_TYPE = 'primary';
const DEFAULT_BUTTON_SIZE = 'lg';
const Spinner = () => {
return <i className="fa fa-spinner fa-spin fa-fw" />;
};
type ButtonType =
| 'default'
| 'primary'
| 'success'
| 'info'
| 'warning'
| 'danger';
type ButtonSize = 'lg' | 'sm' | 'xs';
type Props = {
onClick: () => any,
text: string,
loading?: boolean,
disabled?: boolean,
loadingText?: string,
size?: ButtonSize,
type?: ButtonType
};
export default class SimpleButton extends Component {
props: Props;
computedClass = () => {
return `btn btn-${this.props.size || DEFAULT_BUTTON_TYPE} btn-${this.props
.type || DEFAULT_BUTTON_SIZE}`;
};
render() {
let { loading, disabled, loadingText, text, onClick } = this.props;
return (
<div>
<button
onClick={onClick}
disabled={loading || disabled}
className={this.computedClass()}
>
{loading
? <div>
<Spinner />
{` ${loadingText || text}`}
</div>
: <div>
{text}
</div>}
</button>
</div>
);
}
}