on master help sign in
Merge pull request #188 from urbit/email-fixes

Email invite fixes

commitb18b8edc665b3b3329bf9c24052298e528e8e3c3 authorFang <Fang-@users.noreply.github.com> dateFri 12 Jul 2019, 21:13 (7 years ago) parentb447b7135c970a
4 files changed+41−17
src/components/old/StatelessTransaction.js+2−1 src/indigo-react/index.js+1 src/lib/useMailer.js+6−10 src/views/Invite/InviteEmail.js+32−6
src/components/old/StatelessTransaction.js+2−1
@@ -8,6 +8,7 @@ import { Button } from './Base';
88import { CheckboxButton, Input, InnerLabel, InnerLabelDropdown } from './Base';
99import { Warning } from './Base';
1010
11+import { GAS_LIMITS } from '../../lib/constants';
1112import { BRIDGE_ERROR } from '../../lib/error';
1213import { ROUTE_NAMES } from '../../lib/routeNames';
1314import { compose } from '../../lib/lib';
@@ -40,7 +41,7 @@ class StatelessTransaction extends React.Component {
4041
4142 this.state = {
4243 gasPrice: '5',
43− gasLimit: '600000',
44+ gasLimit: GAS_LIMITS.DEFAULT.toString(),
4445 showGasDetails: false,
4546 userApproval: false,
4647 chainId: '1',
src/indigo-react/index.js+1
@@ -2,6 +2,7 @@ export { default as IndigoApp } from './components/IndigoApp';
22export { default as Grid } from './components/Grid';
33export { default as Flex } from './components/Flex';
44export { default as Input } from './components/Input';
5+export { default as SelectInput } from './components/SelectInput';
56export { default as CheckboxInput } from './components/CheckboxInput';
67export { default as AccessoryIcon } from './components/AccessoryIcon';
78export { default as Button } from './components/Button';
src/lib/useMailer.js+6−10
@@ -9,14 +9,14 @@ const STUB_MAILER = process.env.REACT_APP_STUB_MAILER === 'true';
99function useHasReceivedCache() {
1010 const [cache, addToCache] = useSetState();
1111
12− const getHasRecieved = useCallback(
12+ const getHasReceived = useCallback(
1313 email => cache[email] || Nothing(), //
1414 [cache]
1515 );
1616
1717 const syncHasReceivedForEmail = useCallback(
1818 async email => {
19− if (Just.hasInstance(getHasRecieved(email))) {
19+ if (Just.hasInstance(getHasReceived(email))) {
2020 // never update the cache after we know about it
2121 return;
2222 }
@@ -29,10 +29,10 @@ function useHasReceivedCache() {
2929 const _hasReceived = await hasReceived(email);
3030 addToCache({ [email]: Just(_hasReceived) });
3131 },
32− [getHasRecieved, addToCache]
32+ [getHasReceived, addToCache]
3333 );
3434
35− return { getHasRecieved, syncHasReceivedForEmail };
35+ return { getHasReceived, syncHasReceivedForEmail };
3636}
3737
3838export default function useMailer(emails) {
@@ -43,14 +43,10 @@ export default function useMailer(emails) {
4343 const _sendMail = useCallback(async (email, ticket, rawTx) => {
4444 if (STUB_MAILER) {
4545 console.log(`${email} - ${ticket}`);
46− return;
46+ return true;
4747 }
4848
49− const mailSuccess = await sendMail(email, ticket, rawTx);
50−
51− if (!mailSuccess) {
52− throw new Error(`Internal mailing error when mailing ${email}`);
53− }
49+ return await sendMail(email, ticket, rawTx);
5450 }, []);
5551
5652 return { ...hasReceivedCache, sendMail: _sendMail };
src/views/Invite/InviteEmail.js+32−6
@@ -101,7 +101,7 @@ export default function InviteEmail() {
101101 const { syncInvites, getInvites } = usePointCache();
102102 const { pointCursor } = usePointCursor();
103103 const point = need.point(pointCursor);
104− const { getHasRecieved, syncHasReceivedForEmail, sendMail } = useMailer();
104+ const { getHasReceived, syncHasReceivedForEmail, sendMail } = useMailer();
105105
106106 const { availableInvites } = getInvites(point);
107107 const maxInvitesToSend = availableInvites.matchWith({
@@ -142,14 +142,14 @@ export default function InviteEmail() {
142142 () =>
143143 inputConfigs.map(config => {
144144 config.disabled = !canInput;
145− const hasReceivedError = getHasRecieved(config.name).matchWith({
145+ const hasReceivedError = getHasReceived(config.name).matchWith({
146146 Nothing: () => null, // loading
147147 Just: p => p.value && HAS_RECEIVED_TEXT,
148148 });
149149 config.error = hasReceivedError || errors[config.name];
150150 return config;
151151 }),
152− [inputConfigs, errors, canInput, getHasRecieved]
152+ [inputConfigs, errors, canInput, getHasReceived]
153153 );
154154
155155 // construct the state of the set of inputs we're rendering below
@@ -187,6 +187,27 @@ export default function InviteEmail() {
187187 throw new Error('Internal Error: Missing Contracts/Web3/Wallet');
188188 }
189189
190+ //TODO want to do this on-input, but that gets weird. see #188
191+ let errorCount = 0;
192+ await Promise.all(
193+ inputs.map(async input => {
194+ const email = input.data;
195+ const hasReceived = getHasReceived(email).matchWith({
196+ Nothing: () => false, // loading
197+ Just: p => p.value,
198+ });
199+ if (hasReceived) {
200+ errorCount++;
201+ addError({
202+ [input.name]: `${email} has already received an invite.`,
203+ });
204+ }
205+ })
206+ );
207+ if (errorCount > 0) {
208+ throw new Error(`Some of these already have a point!`);
209+ }
210+
190211 const nonce = await _web3.eth.getTransactionCount(_wallet.address);
191212 const chainId = await _web3.eth.net.getId();
192213 const planets = await azimuth.delegatedSending.getPlanetsToSend(
@@ -207,7 +228,6 @@ export default function InviteEmail() {
207228 );
208229 }
209230
210− let errorCount = 0;
211231 clearInvites();
212232 // NB(shrugs) - must be processed in serial because main thread, etc
213233 for (let i = 0; i < inputs.length; i++) {
@@ -318,12 +338,18 @@ export default function InviteEmail() {
318338 }
319339
320340 try {
321− await sendMail(invite.email, invite.ticket, invite.rawTx);
341+ const success = await sendMail(
342+ invite.email,
343+ invite.ticket,
344+ invite.rawTx
345+ );
346+ if (!success) throw new Error('Failed to send mail');
322347 } catch (error) {
323348 console.error(error);
324349 errorCount++;
350+ //TODO make sure this actually gets displayed
325351 addError({
326− [input.name]: `Mailing Failure for ${invite.email}`,
352+ [input.name]: `Mailing Failure for ${invite.email}, please send them this code manually: ${invite.ticket}`,
327353 });
328354 }
329355