2018-01-29 20:00:43 +00:00
|
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
|
import { connect } from 'react-redux';
|
2018-06-18 01:53:00 +00:00
|
|
|
|
|
2018-02-12 20:43:07 +00:00
|
|
|
|
import { getAddressMessage } from 'config';
|
|
|
|
|
import { Token } from 'types/network';
|
2018-06-18 01:53:00 +00:00
|
|
|
|
import { ICurrentTo } from 'features/types';
|
|
|
|
|
import { AppState } from 'features/reducers';
|
|
|
|
|
import * as derivedSelectors from 'features/selectors';
|
|
|
|
|
import { getAllTokens } from 'features/config';
|
|
|
|
|
import { walletSelectors } from 'features/wallet';
|
|
|
|
|
import { Address } from 'components/ui';
|
2018-01-29 20:00:43 +00:00
|
|
|
|
|
|
|
|
|
interface ReduxProps {
|
|
|
|
|
currentTo: ICurrentTo;
|
|
|
|
|
tokens: Token[];
|
|
|
|
|
wallet: AppState['wallet']['inst'];
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-16 20:34:58 +00:00
|
|
|
|
type Props = ReduxProps;
|
|
|
|
|
|
2018-01-29 20:00:43 +00:00
|
|
|
|
interface State {
|
|
|
|
|
walletAddress: string | null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-16 20:34:58 +00:00
|
|
|
|
class CurrentCustomMessageClass extends PureComponent<Props, State> {
|
2018-01-29 20:00:43 +00:00
|
|
|
|
public state: State = {
|
|
|
|
|
walletAddress: null
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public async componentDidMount() {
|
2018-02-16 20:34:58 +00:00
|
|
|
|
this.setAddressState(this.props);
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-11 02:34:27 +00:00
|
|
|
|
public UNSAFE_componentWillReceiveProps(nextProps: Props) {
|
2018-02-16 20:34:58 +00:00
|
|
|
|
if (this.props.wallet !== nextProps.wallet) {
|
|
|
|
|
this.setAddressState(nextProps);
|
2018-01-29 20:00:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public render() {
|
|
|
|
|
const message = this.getMessage();
|
|
|
|
|
if (message) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="clearfix form-group">
|
|
|
|
|
<div className={`alert alert-${message.severity} col-xs-12`}>{message.message}</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-21 18:23:04 +00:00
|
|
|
|
private setAddressState(props: Props) {
|
2018-02-16 20:34:58 +00:00
|
|
|
|
if (props.wallet) {
|
2018-02-21 18:23:04 +00:00
|
|
|
|
const walletAddress = props.wallet.getAddressString();
|
2018-02-16 20:34:58 +00:00
|
|
|
|
this.setState({ walletAddress });
|
|
|
|
|
} else {
|
|
|
|
|
this.setState({ walletAddress: '' });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-29 20:00:43 +00:00
|
|
|
|
private getMessage() {
|
|
|
|
|
const { currentTo, tokens } = this.props;
|
|
|
|
|
const { walletAddress } = this.state;
|
|
|
|
|
// Make sure all comparisons are lower-cased.
|
|
|
|
|
const address = currentTo.raw.toLowerCase();
|
|
|
|
|
|
|
|
|
|
let message;
|
|
|
|
|
let severity;
|
|
|
|
|
|
|
|
|
|
// First check against our hard-coded messages
|
|
|
|
|
const msg = getAddressMessage(address);
|
|
|
|
|
if (msg) {
|
|
|
|
|
message = (
|
|
|
|
|
<React.Fragment>
|
|
|
|
|
<p>
|
|
|
|
|
<small>
|
2018-03-01 02:54:43 +00:00
|
|
|
|
A message regarding{' '}
|
|
|
|
|
<strong>
|
|
|
|
|
<Address address={address} />
|
|
|
|
|
</strong>:
|
2018-01-29 20:00:43 +00:00
|
|
|
|
</small>
|
|
|
|
|
</p>
|
|
|
|
|
<p>{msg.msg}</p>
|
|
|
|
|
</React.Fragment>
|
|
|
|
|
);
|
|
|
|
|
severity = msg.severity || 'info';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Otherwise check if any of our tokens match the address
|
|
|
|
|
if (!message) {
|
|
|
|
|
const token = tokens.find(tk => tk.address.toLowerCase() === address);
|
|
|
|
|
if (token) {
|
|
|
|
|
message = `
|
|
|
|
|
You’re currently sending to the ${token.symbol} contract. If you
|
|
|
|
|
wanted to send ${token.symbol} to an address, change the To Address to
|
|
|
|
|
where you want it to go, make sure you have a positive ${token.symbol}
|
|
|
|
|
balance in your wallet, and select it from the dropdown next to the
|
|
|
|
|
Amount field.
|
|
|
|
|
`;
|
|
|
|
|
severity = 'warning';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Finally check if they're sending to themselves (lol)
|
|
|
|
|
if (walletAddress === address) {
|
|
|
|
|
message = 'You’re sending to yourself. Are you sure you want to do that?';
|
|
|
|
|
severity = 'warning';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (message) {
|
|
|
|
|
return {
|
|
|
|
|
message,
|
|
|
|
|
severity
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const CurrentCustomMessage = connect((state: AppState): ReduxProps => ({
|
2018-06-18 01:53:00 +00:00
|
|
|
|
currentTo: derivedSelectors.getCurrentTo(state),
|
2018-01-29 20:00:43 +00:00
|
|
|
|
tokens: getAllTokens(state),
|
2018-06-18 01:53:00 +00:00
|
|
|
|
wallet: walletSelectors.getWalletInst(state)
|
2018-01-29 20:00:43 +00:00
|
|
|
|
}))(CurrentCustomMessageClass);
|