import React, { useState } from 'react'; import { Just } from 'folktale/maybe'; import View from 'components/View'; import { ForwardButton } from 'components/Buttons'; import { Warning } from 'components/old/Base'; import { TRANSACTION_STATES, claimPointFromInvite } from 'lib/invite'; import * as need from 'lib/need'; import { useNetwork } from 'store/network'; import { useWallet } from 'store/wallet'; import { usePointCursor } from 'store/pointCursor'; import useLifecycle from 'lib/useLifecycle'; export default function DoReticket({ newWallet, completed }) { const { web3, contracts } = useNetwork(); const { wallet, setUrbitWallet } = useWallet(); const { pointCursor } = usePointCursor(); const [transactionProgress, setTransactionProgress] = useState( TRANSACTION_STATES.GENERATING ); const [errors, setErrors] = useState([]); // start reticketing transactions on mount useLifecycle(() => { claimPointFromInvite({ inviteWallet: need.wallet(wallet), wallet: newWallet.value.wallet, point: need.point(pointCursor), web3: need.web3(web3), contracts: need.contracts(contracts), onUpdate: updateProgress, }).then(() => { setUrbitWallet(newWallet.value.wallet); }); }); const updateProgress = notification => { if (notification.type === 'progress') { setTransactionProgress(notification.value); } else if (notification.type === 'notify') { setErrors([notification.value]); } }; const next = () => { completed(); }; const getErrors = () => { if (errors.length === 0) return null; let errorElems = errors.map(e => {e}); return (

{'Warning'}

{errorElems}
); }; const errorDisplay = getErrors(); return ( {errorDisplay} {transactionProgress.label === TRANSACTION_STATES.DONE.label ? (

Success ✓

Done!
) : (

Submitting

This step can take up to five minutes. Please do not leave this page until the transactions are complete.

{transactionProgress.label}
)} ); }