v3 Style Import (#151)
* Convert bootstrap to sass instead of checked in and less
* Darken body, adjust header.
* First pass at tab styles, each tab will need a lot of individual love tho.
* Update footer to main site content, improve responsiveness.
* Missing key added.
* Fix dropdowns.
* Convert GenerateWallet HTML over, still needs styling.
* Send form.
* Current rates styled.
* CurrencySwap form styles.
* SwapInfoHeader styled.
* Finish up swap restyling, minor usability improvements for mobile.
* Fix up notifications / alert customizations
* Import v3 variables.
* Fix notification spacing.
* Align input height base with buttons.
* Revert height base, add additional bootstrap overrides.
* Grid overrides.
* Move overrides to their own folder. Adjust naming.
* Fix inconsistencies.
* Style generate wallet pt 1.
* Style generate wallet pt 2
* Style generate wallet pt 3
* Fix swap
* Added some missing overries, fixed the fallout.
* Remove header text, indicate alpha version.
* Fix radio / checkbox weights.
* Bind => arrow
* Convert simpledropdown to proper form select, instead of weirdly implemented nonfuncitoning dropdown.
* Fix token balances buttons, footr icons.
2017-09-05 19:52:01 +00:00
|
|
|
import './CurrencySwap.scss';
|
2017-07-31 23:14:30 +00:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import translate from 'translations';
|
|
|
|
import { combineAndUpper } from 'utils/formatters';
|
|
|
|
import SimpleDropDown from 'components/ui/SimpleDropdown';
|
|
|
|
import SimpleButton from 'components/ui/SimpleButton';
|
|
|
|
import type {
|
|
|
|
OriginKindSwapAction,
|
|
|
|
DestinationKindSwapAction,
|
|
|
|
OriginAmountSwapAction,
|
|
|
|
DestinationAmountSwapAction,
|
|
|
|
ChangeStepSwapAction
|
|
|
|
} from 'actions/swapTypes';
|
|
|
|
import bityConfig from 'config/bity';
|
|
|
|
import { toFixedIfLarger } from 'utils/formatters';
|
|
|
|
|
|
|
|
export type StateProps = {
|
|
|
|
bityRates: {},
|
|
|
|
originAmount: ?number,
|
|
|
|
destinationAmount: ?number,
|
|
|
|
originKind: string,
|
|
|
|
destinationKind: string,
|
|
|
|
destinationKindOptions: String[],
|
|
|
|
originKindOptions: String[]
|
|
|
|
};
|
|
|
|
|
|
|
|
export type ActionProps = {
|
|
|
|
originKindSwap: (value: string) => OriginKindSwapAction,
|
|
|
|
destinationKindSwap: (value: string) => DestinationKindSwapAction,
|
|
|
|
originAmountSwap: (value: ?number) => OriginAmountSwapAction,
|
|
|
|
destinationAmountSwap: (value: ?number) => DestinationAmountSwapAction,
|
|
|
|
changeStepSwap: () => ChangeStepSwapAction,
|
|
|
|
showNotification: Function
|
|
|
|
};
|
|
|
|
|
|
|
|
export default class CurrencySwap extends Component {
|
|
|
|
props: StateProps & ActionProps;
|
|
|
|
|
|
|
|
state = {
|
|
|
|
disabled: true,
|
|
|
|
showedMinMaxError: false
|
|
|
|
};
|
|
|
|
|
|
|
|
isMinMaxValid = (amount, kind) => {
|
|
|
|
let bityMin;
|
|
|
|
let bityMax;
|
|
|
|
if (kind !== 'BTC') {
|
|
|
|
const bityPairRate = this.props.bityRates['BTC' + kind];
|
|
|
|
bityMin = bityConfig[kind + 'Min'](bityPairRate);
|
|
|
|
bityMax = bityConfig[kind + 'Max'](bityPairRate);
|
|
|
|
} else {
|
|
|
|
bityMin = bityConfig.BTCMin;
|
|
|
|
bityMax = bityConfig.BTCMax;
|
|
|
|
}
|
|
|
|
let higherThanMin = amount >= bityMin;
|
|
|
|
let lowerThanMax = amount <= bityMax;
|
|
|
|
return higherThanMin && lowerThanMax;
|
|
|
|
};
|
|
|
|
|
|
|
|
isDisabled = (originAmount, originKind, destinationAmount) => {
|
|
|
|
const hasOriginAmountAndDestinationAmount =
|
|
|
|
originAmount && destinationAmount;
|
|
|
|
const minMaxIsValid = this.isMinMaxValid(originAmount, originKind);
|
|
|
|
return !(hasOriginAmountAndDestinationAmount && minMaxIsValid);
|
|
|
|
};
|
|
|
|
|
|
|
|
setDisabled(originAmount, originKind, destinationAmount) {
|
|
|
|
const disabled = this.isDisabled(
|
|
|
|
originAmount,
|
|
|
|
originKind,
|
|
|
|
destinationAmount
|
|
|
|
);
|
|
|
|
|
|
|
|
if (disabled && originAmount && !this.state.showedMinMaxError) {
|
|
|
|
const { bityRates } = this.props;
|
|
|
|
const ETHMin = bityConfig.ETHMin(bityRates.BTCETH);
|
|
|
|
const ETHMax = bityConfig.ETHMax(bityRates.BTCETH);
|
|
|
|
const REPMin = bityConfig.REPMax(bityRates.BTCREP);
|
|
|
|
|
|
|
|
const notificationMessage = `
|
v3 Style Import (#151)
* Convert bootstrap to sass instead of checked in and less
* Darken body, adjust header.
* First pass at tab styles, each tab will need a lot of individual love tho.
* Update footer to main site content, improve responsiveness.
* Missing key added.
* Fix dropdowns.
* Convert GenerateWallet HTML over, still needs styling.
* Send form.
* Current rates styled.
* CurrencySwap form styles.
* SwapInfoHeader styled.
* Finish up swap restyling, minor usability improvements for mobile.
* Fix up notifications / alert customizations
* Import v3 variables.
* Fix notification spacing.
* Align input height base with buttons.
* Revert height base, add additional bootstrap overrides.
* Grid overrides.
* Move overrides to their own folder. Adjust naming.
* Fix inconsistencies.
* Style generate wallet pt 1.
* Style generate wallet pt 2
* Style generate wallet pt 3
* Fix swap
* Added some missing overries, fixed the fallout.
* Remove header text, indicate alpha version.
* Fix radio / checkbox weights.
* Bind => arrow
* Convert simpledropdown to proper form select, instead of weirdly implemented nonfuncitoning dropdown.
* Fix token balances buttons, footr icons.
2017-09-05 19:52:01 +00:00
|
|
|
Minimum amount ${bityConfig.BTCMin} BTC,
|
|
|
|
${toFixedIfLarger(ETHMin, 3)} ETH.
|
|
|
|
Max amount ${bityConfig.BTCMax} BTC,
|
|
|
|
${toFixedIfLarger(ETHMax, 3)} ETH, or
|
2017-07-31 23:14:30 +00:00
|
|
|
${toFixedIfLarger(REPMin, 3)} REP
|
|
|
|
`;
|
|
|
|
|
|
|
|
this.setState(
|
|
|
|
{
|
|
|
|
disabled: disabled,
|
|
|
|
showedMinMaxError: true
|
|
|
|
},
|
|
|
|
() => {
|
|
|
|
this.props.showNotification('danger', notificationMessage, 10000);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
this.setState({
|
|
|
|
disabled: disabled
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onClickStartSwap = () => {
|
|
|
|
this.props.changeStepSwap(2);
|
|
|
|
};
|
|
|
|
|
|
|
|
setOriginAndDestinationToNull = () => {
|
|
|
|
this.props.originAmountSwap(null);
|
|
|
|
this.props.destinationAmountSwap(null);
|
|
|
|
this.setDisabled(null, this.props.originKind, null);
|
|
|
|
};
|
|
|
|
|
|
|
|
onChangeOriginAmount = (event: SyntheticInputEvent) => {
|
|
|
|
const { destinationKind, originKind } = this.props;
|
|
|
|
const amount = event.target.value;
|
|
|
|
let originAmountAsNumber = parseFloat(amount);
|
|
|
|
if (originAmountAsNumber || originAmountAsNumber === 0) {
|
|
|
|
let pairName = combineAndUpper(originKind, destinationKind);
|
|
|
|
let bityRate = this.props.bityRates[pairName];
|
|
|
|
this.props.originAmountSwap(originAmountAsNumber);
|
|
|
|
let destinationAmount = originAmountAsNumber * bityRate;
|
|
|
|
this.props.destinationAmountSwap(destinationAmount);
|
|
|
|
this.setDisabled(originAmountAsNumber, originKind, destinationAmount);
|
|
|
|
} else {
|
|
|
|
this.setOriginAndDestinationToNull();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
onChangeDestinationAmount = (event: SyntheticInputEvent) => {
|
|
|
|
const { destinationKind, originKind } = this.props;
|
|
|
|
const amount = event.target.value;
|
|
|
|
let destinationAmountAsNumber = parseFloat(amount);
|
|
|
|
if (destinationAmountAsNumber || destinationAmountAsNumber === 0) {
|
|
|
|
this.props.destinationAmountSwap(destinationAmountAsNumber);
|
|
|
|
let pairNameReversed = combineAndUpper(destinationKind, originKind);
|
|
|
|
let bityRate = this.props.bityRates[pairNameReversed];
|
|
|
|
let originAmount = destinationAmountAsNumber * bityRate;
|
|
|
|
this.props.originAmountSwap(originAmount, originKind);
|
|
|
|
this.setDisabled(originAmount, originKind, destinationAmountAsNumber);
|
|
|
|
} else {
|
|
|
|
this.setOriginAndDestinationToNull();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
onChangeDestinationKind = (event: SyntheticInputEvent) => {
|
|
|
|
let newDestinationKind = event.target.value;
|
|
|
|
this.props.destinationKindSwap(newDestinationKind);
|
|
|
|
};
|
|
|
|
|
|
|
|
onChangeOriginKind = (event: SyntheticInputEvent) => {
|
|
|
|
let newOriginKind = event.target.value;
|
|
|
|
this.props.originKindSwap(newOriginKind);
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
originAmount,
|
|
|
|
destinationAmount,
|
|
|
|
originKind,
|
|
|
|
destinationKind,
|
|
|
|
destinationKindOptions,
|
|
|
|
originKindOptions
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
return (
|
v3 Style Import (#151)
* Convert bootstrap to sass instead of checked in and less
* Darken body, adjust header.
* First pass at tab styles, each tab will need a lot of individual love tho.
* Update footer to main site content, improve responsiveness.
* Missing key added.
* Fix dropdowns.
* Convert GenerateWallet HTML over, still needs styling.
* Send form.
* Current rates styled.
* CurrencySwap form styles.
* SwapInfoHeader styled.
* Finish up swap restyling, minor usability improvements for mobile.
* Fix up notifications / alert customizations
* Import v3 variables.
* Fix notification spacing.
* Align input height base with buttons.
* Revert height base, add additional bootstrap overrides.
* Grid overrides.
* Move overrides to their own folder. Adjust naming.
* Fix inconsistencies.
* Style generate wallet pt 1.
* Style generate wallet pt 2
* Style generate wallet pt 3
* Fix swap
* Added some missing overries, fixed the fallout.
* Remove header text, indicate alpha version.
* Fix radio / checkbox weights.
* Bind => arrow
* Convert simpledropdown to proper form select, instead of weirdly implemented nonfuncitoning dropdown.
* Fix token balances buttons, footr icons.
2017-09-05 19:52:01 +00:00
|
|
|
<article className="CurrencySwap">
|
|
|
|
<h1 className="CurrencySwap-title">
|
2017-07-31 23:14:30 +00:00
|
|
|
{translate('SWAP_init_1')}
|
|
|
|
</h1>
|
|
|
|
|
v3 Style Import (#151)
* Convert bootstrap to sass instead of checked in and less
* Darken body, adjust header.
* First pass at tab styles, each tab will need a lot of individual love tho.
* Update footer to main site content, improve responsiveness.
* Missing key added.
* Fix dropdowns.
* Convert GenerateWallet HTML over, still needs styling.
* Send form.
* Current rates styled.
* CurrencySwap form styles.
* SwapInfoHeader styled.
* Finish up swap restyling, minor usability improvements for mobile.
* Fix up notifications / alert customizations
* Import v3 variables.
* Fix notification spacing.
* Align input height base with buttons.
* Revert height base, add additional bootstrap overrides.
* Grid overrides.
* Move overrides to their own folder. Adjust naming.
* Fix inconsistencies.
* Style generate wallet pt 1.
* Style generate wallet pt 2
* Style generate wallet pt 3
* Fix swap
* Added some missing overries, fixed the fallout.
* Remove header text, indicate alpha version.
* Fix radio / checkbox weights.
* Bind => arrow
* Convert simpledropdown to proper form select, instead of weirdly implemented nonfuncitoning dropdown.
* Fix token balances buttons, footr icons.
2017-09-05 19:52:01 +00:00
|
|
|
<div className="form-inline">
|
|
|
|
<input
|
|
|
|
className={`CurrencySwap-input form-control ${originAmount !== '' &&
|
|
|
|
this.isMinMaxValid(originAmount, originKind)
|
|
|
|
? 'is-valid'
|
|
|
|
: 'is-invalid'}`}
|
|
|
|
type="number"
|
|
|
|
placeholder="Amount"
|
|
|
|
value={
|
|
|
|
parseFloat(originAmount) === 0 ? originAmount : originAmount || ''
|
|
|
|
}
|
|
|
|
onChange={this.onChangeOriginAmount}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<SimpleDropDown
|
|
|
|
value={originKind}
|
|
|
|
onChange={this.onChangeOriginKind.bind(this)}
|
|
|
|
options={originKindOptions}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<h1 className="CurrencySwap-divider">
|
|
|
|
{translate('SWAP_init_2')}
|
|
|
|
</h1>
|
|
|
|
|
|
|
|
<input
|
|
|
|
className={`CurrencySwap-input form-control ${destinationAmount !==
|
|
|
|
'' && this.isMinMaxValid(originAmount, originKind)
|
|
|
|
? 'is-valid'
|
|
|
|
: 'is-invalid'}`}
|
|
|
|
type="number"
|
|
|
|
placeholder="Amount"
|
|
|
|
value={
|
|
|
|
parseFloat(destinationAmount) === 0
|
|
|
|
? destinationAmount
|
|
|
|
: destinationAmount || ''
|
|
|
|
}
|
|
|
|
onChange={this.onChangeDestinationAmount}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<SimpleDropDown
|
|
|
|
value={destinationKind}
|
|
|
|
onChange={this.onChangeDestinationKind}
|
|
|
|
options={destinationKindOptions}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="CurrencySwap-submit">
|
2017-07-31 23:14:30 +00:00
|
|
|
<SimpleButton
|
|
|
|
onClick={this.onClickStartSwap}
|
|
|
|
text={translate('SWAP_init_CTA')}
|
|
|
|
disabled={this.state.disabled}
|
v3 Style Import (#151)
* Convert bootstrap to sass instead of checked in and less
* Darken body, adjust header.
* First pass at tab styles, each tab will need a lot of individual love tho.
* Update footer to main site content, improve responsiveness.
* Missing key added.
* Fix dropdowns.
* Convert GenerateWallet HTML over, still needs styling.
* Send form.
* Current rates styled.
* CurrencySwap form styles.
* SwapInfoHeader styled.
* Finish up swap restyling, minor usability improvements for mobile.
* Fix up notifications / alert customizations
* Import v3 variables.
* Fix notification spacing.
* Align input height base with buttons.
* Revert height base, add additional bootstrap overrides.
* Grid overrides.
* Move overrides to their own folder. Adjust naming.
* Fix inconsistencies.
* Style generate wallet pt 1.
* Style generate wallet pt 2
* Style generate wallet pt 3
* Fix swap
* Added some missing overries, fixed the fallout.
* Remove header text, indicate alpha version.
* Fix radio / checkbox weights.
* Bind => arrow
* Convert simpledropdown to proper form select, instead of weirdly implemented nonfuncitoning dropdown.
* Fix token balances buttons, footr icons.
2017-09-05 19:52:01 +00:00
|
|
|
type="info"
|
2017-07-31 23:14:30 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</article>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|