2017-11-15 05:51:09 +00:00
|
|
|
import * as React from 'react';
|
Sidebar refactor / style update (#173)
* 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.
* Break out files, style up account info.
* Style up token balances.
* Equivalent values styling.
* Sidebar promos.
* Fix up delete button and add custom form.
* Even spacing.
* Unlog
* Convert Big types to Ether types
* Fix test to expect Ether instead of Big
2017-09-08 19:26:51 +00:00
|
|
|
import translate from 'translations';
|
2017-09-26 03:41:11 +00:00
|
|
|
import { State } from 'reducers/rates';
|
2017-11-15 05:51:09 +00:00
|
|
|
import { rateSymbols, TFetchCCRates } from 'actions/rates';
|
|
|
|
import { TokenBalance } from 'selectors/wallet';
|
2017-11-15 03:44:55 +00:00
|
|
|
import { Balance } from 'libs/wallet';
|
|
|
|
import Spinner from 'components/ui/Spinner';
|
2017-11-15 05:51:09 +00:00
|
|
|
import UnitDisplay from 'components/ui/UnitDisplay';
|
|
|
|
import './EquivalentValues.scss';
|
Sidebar refactor / style update (#173)
* 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.
* Break out files, style up account info.
* Style up token balances.
* Equivalent values styling.
* Sidebar promos.
* Fix up delete button and add custom form.
* Even spacing.
* Unlog
* Convert Big types to Ether types
* Fix test to expect Ether instead of Big
2017-09-08 19:26:51 +00:00
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
interface Props {
|
2017-11-15 05:51:09 +00:00
|
|
|
balance?: Balance;
|
|
|
|
tokenBalances?: TokenBalance[];
|
|
|
|
rates: State['rates'];
|
2017-09-26 03:41:11 +00:00
|
|
|
ratesError?: State['ratesError'];
|
2017-11-15 05:51:09 +00:00
|
|
|
fetchCCRates: TFetchCCRates;
|
2017-09-25 02:06:28 +00:00
|
|
|
}
|
Sidebar refactor / style update (#173)
* 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.
* Break out files, style up account info.
* Style up token balances.
* Equivalent values styling.
* Sidebar promos.
* Fix up delete button and add custom form.
* Even spacing.
* Unlog
* Convert Big types to Ether types
* Fix test to expect Ether instead of Big
2017-09-08 19:26:51 +00:00
|
|
|
|
2017-11-15 05:51:09 +00:00
|
|
|
interface CmpState {
|
|
|
|
currency: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default class EquivalentValues extends React.Component<Props, CmpState> {
|
|
|
|
public state = {
|
|
|
|
currency: 'ETH'
|
|
|
|
};
|
|
|
|
private balanceLookup = {};
|
|
|
|
|
|
|
|
public constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.makeBalanceLookup(props);
|
|
|
|
}
|
|
|
|
|
|
|
|
public componentDidMount() {
|
|
|
|
this.props.fetchCCRates(this.state.currency);
|
|
|
|
}
|
|
|
|
|
|
|
|
public componentWillReceiveProps(nextProps) {
|
|
|
|
const { balance, tokenBalances } = this.props;
|
|
|
|
if (
|
|
|
|
nextProps.balance !== balance ||
|
|
|
|
nextProps.tokenBalances !== tokenBalances
|
|
|
|
) {
|
|
|
|
this.makeBalanceLookup(nextProps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
public render() {
|
2017-11-15 05:51:09 +00:00
|
|
|
const { tokenBalances, rates, ratesError } = this.props;
|
|
|
|
const { currency } = this.state;
|
|
|
|
const balance = this.balanceLookup[currency];
|
|
|
|
|
|
|
|
let values;
|
|
|
|
if (balance && rates && rates[currency]) {
|
|
|
|
values = rateSymbols.map(key => {
|
|
|
|
if (!rates[currency][key] || key === currency) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<li className="EquivalentValues-values-currency" key={key}>
|
|
|
|
<span className="EquivalentValues-values-currency-label">
|
|
|
|
{key}:
|
|
|
|
</span>{' '}
|
|
|
|
<span className="EquivalentValues-values-currency-value">
|
|
|
|
{balance.isPending ? (
|
|
|
|
<Spinner />
|
|
|
|
) : (
|
|
|
|
<UnitDisplay
|
|
|
|
unit={'ether'}
|
|
|
|
value={balance ? balance.muln(rates[currency][key]) : null}
|
|
|
|
displayShortBalance={2}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</span>
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
} else if (ratesError) {
|
|
|
|
values = <h5>{ratesError}</h5>;
|
|
|
|
} else {
|
|
|
|
values = (
|
|
|
|
<div className="EquivalentValues-values-loader">
|
|
|
|
<Spinner size="x3" />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
Sidebar refactor / style update (#173)
* 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.
* Break out files, style up account info.
* Style up token balances.
* Equivalent values styling.
* Sidebar promos.
* Fix up delete button and add custom form.
* Even spacing.
* Unlog
* Convert Big types to Ether types
* Fix test to expect Ether instead of Big
2017-09-08 19:26:51 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="EquivalentValues">
|
2017-11-15 05:51:09 +00:00
|
|
|
<h5 className="EquivalentValues-title">
|
|
|
|
{translate('sidebar_Equiv')} for{' '}
|
|
|
|
<select
|
|
|
|
className="EquivalentValues-title-symbol"
|
|
|
|
onChange={this.changeCurrency}
|
|
|
|
value={currency}
|
|
|
|
>
|
|
|
|
<option value="ETH">ETH</option>
|
|
|
|
{tokenBalances &&
|
|
|
|
tokenBalances.map(tk => {
|
|
|
|
if (!tk.balance || tk.balance.isZero()) {
|
|
|
|
return;
|
2017-09-25 02:06:28 +00:00
|
|
|
}
|
2017-11-15 05:51:09 +00:00
|
|
|
const sym = tk.symbol;
|
2017-09-12 22:15:23 +00:00
|
|
|
return (
|
2017-11-15 05:51:09 +00:00
|
|
|
<option key={sym} value={sym}>
|
|
|
|
{sym}
|
|
|
|
</option>
|
2017-09-12 22:15:23 +00:00
|
|
|
);
|
2017-11-15 05:51:09 +00:00
|
|
|
})}
|
|
|
|
</select>
|
|
|
|
</h5>
|
|
|
|
|
|
|
|
<ul className="EquivalentValues-values">{values}</ul>
|
Sidebar refactor / style update (#173)
* 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.
* Break out files, style up account info.
* Style up token balances.
* Equivalent values styling.
* Sidebar promos.
* Fix up delete button and add custom form.
* Even spacing.
* Unlog
* Convert Big types to Ether types
* Fix test to expect Ether instead of Big
2017-09-08 19:26:51 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2017-11-15 05:51:09 +00:00
|
|
|
|
|
|
|
private changeCurrency = (ev: React.FormEvent<HTMLSelectElement>) => {
|
|
|
|
const currency = ev.currentTarget.value;
|
|
|
|
this.setState({ currency });
|
|
|
|
if (!this.props.rates || !this.props.rates[currency]) {
|
|
|
|
this.props.fetchCCRates(currency);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
private makeBalanceLookup(props: Props) {
|
|
|
|
const tokenBalances = props.tokenBalances || [];
|
|
|
|
this.balanceLookup = tokenBalances.reduce(
|
|
|
|
(prev, tk) => {
|
|
|
|
return {
|
|
|
|
...prev,
|
|
|
|
[tk.symbol]: tk.balance
|
|
|
|
};
|
|
|
|
},
|
|
|
|
{ ETH: props.balance && props.balance.wei }
|
|
|
|
);
|
|
|
|
}
|
Sidebar refactor / style update (#173)
* 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.
* Break out files, style up account info.
* Style up token balances.
* Equivalent values styling.
* Sidebar promos.
* Fix up delete button and add custom form.
* Even spacing.
* Unlog
* Convert Big types to Ether types
* Fix test to expect Ether instead of Big
2017-09-08 19:26:51 +00:00
|
|
|
}
|