@@ -16,7 +16,7 @@ import ReactSVGComponents from '../components/ReactSVGComponents'
1616import KeysAndMetadata from './Point/KeysAndMetadata'
1717import Actions from './Point/Actions'
1818import { BRIDGE_ERROR } from '../lib/error'
19−import { sendMail } from '../lib/inviteMail'
19+import { hasReceived, sendMail } from '../lib/inviteMail'
2020import { Row, Col, Warning, Button, H1, H3,
2121 Input, InnerLabel
2222} from '../components/Base'
@@ -46,7 +46,8 @@ class InvitesSend extends React.Component {
4646 haveInvited: Nothing(),
4747 randomPlanet: Nothing(),
4848 inviteWallet: Nothing(),
49− targetEmail: ''
49+ targetEmail: '',
50+ targetHasReceived: Nothing()
5051 }
5152
5253 this.findInvited = this.findInvited.bind(this);
@@ -126,19 +127,33 @@ class InvitesSend extends React.Component {
126127 }
127128
128129 handleEmailInput(email) {
129− //TODO simple .*@.*\..* email validation
130− this.setState({ targetEmail: email });
130+ let newState = { targetEmail: email };
131+ if (email.match(/.*@.*\...+/)) {
132+ hasReceived(email)
133+ .then(res => {
134+ console.log('hasReceived', res);
135+ this.setState({ targetHasReceived: Just(res) });
136+ });
137+ } else {
138+ newState.targetHasReceived = Nothing();
139+ }
140+ this.setState(newState);
131141 }
132142
133143 canGenerate() {
134144 //TODO and canSend()
135− let res = this.state.invitesAvailable.matchWith({
145+ let invites = this.state.invitesAvailable.matchWith({
136146 Nothing: () => false,
137− Just: invites => ((invites.value > 0)
138− && Just.hasInstance(this.state.randomPlanet)
139− && Just.hasInstance(this.state.inviteWallet))
147+ Just: invites => (invites.value > 0)
140148 });
141− return res;
149+ let alreadyGotInvited = this.state.targetHasReceived.matchWith({
150+ Nothing: () => false,
151+ Just: has => has.value
152+ });
153+ return invites
154+ && !alreadyGotInvited
155+ && Just.hasInstance(this.state.randomPlanet)
156+ && Just.hasInstance(this.state.inviteWallet);
142157 }
143158
144159 createUnsignedTxn() {
@@ -188,6 +203,19 @@ class InvitesSend extends React.Component {
188203 })
189204 });
190205
206+ const recipientWarning = this.state.targetHasReceived.matchWith({
207+ Nothing: () => null,
208+ Just: hasReceived => {
209+ if (!hasReceived.value) return null;
210+ return (
211+ <Warning>
212+ <h3 className={'mb-2'}>{'Warning'}</h3>
213+ { 'That email address has already received an invite!' }
214+ </Warning>
215+ );
216+ }
217+ });
218+
191219 return (
192220 <Row>
193221 <Col>
@@ -206,6 +234,8 @@ class InvitesSend extends React.Component {
206234 </InnerLabel>
207235 </Input>
208236
237+ { recipientWarning }
238+
209239 <StatelessTransaction
210240 // Upper scope
211241 web3={this.props.web3}