1import { Just, Nothing } from 'folktale/maybe';
2import React from 'react';
3import * as azimuth from 'azimuth-js';
4import * as need from 'lib/need';
6import View from 'components/View';
15} from '../components/old/Base';
17import { randomPatq, compose } from '../lib/lib';
18import { ROUTE_NAMES } from '../lib/routeNames';
19import { withHistory } from '../store/history';
22 ownershipWalletFromTicket,
24} from '../lib/wallet';
25import { BRIDGE_ERROR } from '../lib/error';
30} from '../lib/invite';
31import { generateWallet, startTransactions } from '../lib/invite';
32import { withNetwork } from '../store/network';
33import { withWallet } from '../store/wallet';
34import Grid from 'components/Grid';
36class InviteTicket extends React.Component {
42 inviteWallet: Nothing(),
46 realWallet: Nothing(),
50 stage: INVITE_STAGES.INVITE_LOGIN,
51 transactionProgress: TRANSACTION_STATES.GENERATING,
54 this.pointPlaceholder = randomPatq(4);
55 this.ticketPlaceholder = randomPatq(12);
57 this.handleInviteTicketInput = this.handleInviteTicketInput.bind(this);
58 this.handleVerifyTicketInput = this.handleVerifyTicketInput.bind(this);
59 this.updateProgress = this.updateProgress.bind(this);
60 this.pushWalletState = this.pushWalletState.bind(this);
61 this.navigateLogin = this.navigateLogin.bind(this);
64 pushWalletState(walletState) {
66 walletStates: this.state.walletStates.concat(walletState),
71 this.props.history.pop();
72 this.props.history.push(ROUTE_NAMES.NETWORK);
75 handleInviteTicketInput(inviteTicket) {
76 this.setState({ inviteTicket });
79 handleVerifyTicketInput(verifyTicket) {
80 this.setState({ verifyTicket });
83 updateTransactionProgress(transactionProgress) {
84 this.setState({ transactionProgress });
87 async unlockInviteWallet(inviteTicket) {
89 walletStates: this.state.walletStates.concat(WALLET_STATES.UNLOCKING),
90 stage: INVITE_STAGES.INVITE_WALLET,
93 //NOTE ~zod because tmp wallet
94 const ownership = await ownershipWalletFromTicket(inviteTicket, 0);
95 const mnemonic = ownership.seed;
96 //TODO isn't all this accessible in the ownership object?
97 const inviteWallet = walletFromMnemonic(
103 throw BRIDGE_ERROR.MISSING_WALLET;
107 const addr = inviteWallet.address;
109 const contracts = need.contracts(this.props.contracts);
111 const incoming = await azimuth.azimuth.getTransferringFor(contracts, addr);
114 walletStates: this.state.walletStates.concat(WALLET_STATES.GENERATING),
117 let realPoint = Nothing();
118 let realWallet = Nothing();
121 if (incoming.length > 0) {
122 let pointNum = parseInt(incoming[0], 10);
123 realPoint = Just(pointNum);
129 let genWallet = await generateWallet(pointNum);
131 realWallet = Just(genWallet);
132 if (incoming.length > 1) {
133 //TODO notify user "...and others / ticket reusable"
137 'Invite code has no claimable ship. Check your invite code and try again.',
143 inviteWallet: Just(inviteWallet),
144 // dev mode: uncomment this out to autofill verified ticket
145 verifyTicket: !Nothing.hasInstance(realWallet)
146 ? realWallet.value.ticket
148 walletStates: this.state.walletStates.concat(WALLET_STATES.RENDERING),
154 const phTick = this.ticketPlaceholder;
156 let isLogin = this.state.stage === INVITE_STAGES.INVITE_LOGIN;
157 let isVerify = this.state.stage === INVITE_STAGES.INVITE_VERIFY;
159 if (isLogin || isVerify) {
160 let value = isLogin ? this.state.inviteTicket : this.state.verifyTicket;
161 let handler = isLogin
162 ? this.handleInviteTicketInput
163 : this.handleVerifyTicketInput;
164 let label = isLogin ? 'Activation code' : 'ticket';
166 // if realWallet is Just, then VerifyTicketInput appropriate contents; if Nothing, remain Nothing
167 const Verified = this.state.realWallet.map(realWallet =>
168 VerifyTicketInput(realWallet.ticket)
171 // Verified.getOrElse(TicketInput) falls back to TicketInput if Verified is Nothing
172 const TicketElem = isVerify
173 ? Verified.getOrElse(TicketInput)
178 className="mono mt-8"
180 prop-format="innerLabel"
184 placeholder={`e.g. ${phTick}`}
187 <InnerLabel>{label}</InnerLabel>
196 const { stage } = this.state;
198 let progressWidth = this.state.transactionProgress.pct;
201 stage === INVITE_STAGES.INVITE_LOGIN ? (
202 <h1 className="text-700 mt-15">Welcome</h1>
203 ) : stage === INVITE_STAGES.INVITE_WALLET ? (
205 <h1 className="fs-6 lh-8 mb-3">Passport</h1>
207 A passport is your digital identity. You will use your passport to
208 access your true computer, send payments, and administer your
209 identity. So naturally, you must keep this secure.
212 After you’ve downloaded your passport, back up the ticket manually
213 or store on a trusted device.
216 ) : stage === INVITE_STAGES.INVITE_VERIFY ? (
218 <h1 className="fs-6 lh-8 mb-3">Verify Passport</h1>
220 Afer you download your passport, verify your custody. Your passport
221 should be a folder of image files. One of them is your Master
222 Ticket. Open it and enter the 4 word phrase below (with hyphens).
225 ) : INVITE_STAGES.INVITE_TRANSACTIONS ? (
226 this.state.transactionProgress.label ===
227 TRANSACTION_STATES.DONE.label ? (
229 <h1 className="fs-6 lh-8 mb-3">
231 <span className="ml-4 green">✓</span>
233 <p>Transferring to Bridge...</p>
237 <h1 className="fs-6 lh-8 mb-3">Submitting</h1>
238 <p className="mt-4 mb-4">
239 This step can take up to five minutes. Please do not leave this
240 page until the transactions are complete.
242 <div className="passport-progress mb-2">
244 className="passport-progress-filled"
245 style={{ width: progressWidth }}
248 <div className="flex justify-between">
249 <div className="text-mono text-sm lh-6 green-dark">
250 {this.state.transactionProgress.label}
260 updateProgress(notification) {
262 notification.type === 'progress'
263 ? { transactionProgress: notification.value }
264 : notification.type === 'notify'
265 ? { errors: [notification.value] }
268 this.setState(newState);
271 getContinueButton() {
281 const { web3, contracts, setUrbitWallet } = this.props;
283 const btnColor = this.state.walletStates.includes(WALLET_STATES.PAPER_READY)
288 stage === INVITE_STAGES.INVITE_LOGIN
290 this.unlockInviteWallet(inviteTicket);
292 : stage === INVITE_STAGES.INVITE_WALLET
295 stage: INVITE_STAGES.INVITE_VERIFY,
298 : stage === INVITE_STAGES.INVITE_VERIFY
301 stage: INVITE_STAGES.INVITE_TRANSACTIONS,
302 walletStates: this.state.walletStates.concat(
303 WALLET_STATES.TRANSACTIONS
308 inviteWalletM: inviteWallet,
309 realWalletM: realWallet,
310 realPointM: realPoint,
311 realTicket: verifyTicket,
315 updateProgress: this.updateProgress,
318 this.props.history.pop();
324 const ticketMatches = this.state.realWallet.matchWith({
325 Just: wal => wal.value.ticket === this.state.verifyTicket,
326 Nothing: () => false,
329 const continueReady =
330 stage === INVITE_STAGES.INVITE_WALLET
331 ? walletStates.includes(WALLET_STATES.DOWNLOADED)
332 : stage === INVITE_STAGES.INVITE_VERIFY
337 stage === INVITE_STAGES.INVITE_TRANSACTIONS ? null : (
341 prop-color={btnColor}
342 disabled={!continueReady}
343 onClick={clickHandler}>
352 const { stage } = this.state;
354 if (stage === INVITE_STAGES.INVITE_LOGIN) return null;
357 <div className="mt-6 mb-8">
359 className={`fs-35 mr-3 ${stage !== INVITE_STAGES.INVITE_WALLET &&
364 className={`fs-35 mr-3 ${stage !== INVITE_STAGES.INVITE_VERIFY &&
369 className={`fs-35 mr-3 ${stage !==
370 INVITE_STAGES.INVITE_TRANSACTIONS && 'gray-20'}`}>
378 if (this.state.errors.length === 0) return null;
380 let errorElems = this.state.errors.map(e => <span>{e}</span>);
384 <h3 className={'mb-2'}>{'Warning'}</h3>
391 let stageDisplay = this.getStageDisplay();
392 let stageText = this.getStageText();
393 let ticketElem = this.getTicketElement();
394 let continueButton = this.getContinueButton();
395 let errorDisplay = this.getErrors();
407 {this.state.stage === INVITE_STAGES.INVITE_LOGIN && (
411 className={`block mt-4`}
412 onClick={this.navigateLogin}>
419 point={this.state.realPoint}
420 wallet={this.state.realWallet}
421 walletStates={this.state.walletStates}
422 pushWalletState={this.pushWalletState}
431export default compose(
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list