1import { Just, Nothing } from 'folktale/maybe';
2import React from 'react';
12} from '../components/old/Base';
13import * as azimuth from 'azimuth-js';
14import * as need from '../lib/need';
16import { randomPatq, compose } from '../lib/lib';
17import { ROUTE_NAMES } from '../lib/routeNames';
18import { withHistory } from '../store/history';
21 ownershipWalletFromTicket,
23} from '../lib/wallet';
24import { BRIDGE_ERROR } from '../lib/error';
29} from '../lib/invite';
30import { generateWallet, startTransactions } from '../lib/invite';
31import { withNetwork } from '../store/network';
32import { withWallet } from '../store/wallet';
34class InviteTicket extends React.Component {
40 inviteWallet: Nothing(),
44 realWallet: Nothing(),
48 stage: INVITE_STAGES.INVITE_LOGIN,
49 transactionProgress: TRANSACTION_STATES.GENERATING,
52 this.pointPlaceholder = randomPatq(4);
53 this.ticketPlaceholder = randomPatq(12);
55 this.handleInviteTicketInput = this.handleInviteTicketInput.bind(this);
56 this.handleVerifyTicketInput = this.handleVerifyTicketInput.bind(this);
57 this.updateProgress = this.updateProgress.bind(this);
58 this.pushWalletState = this.pushWalletState.bind(this);
59 this.navigateLogin = this.navigateLogin.bind(this);
62 pushWalletState(walletState) {
64 walletStates: this.state.walletStates.concat(walletState),
69 this.props.history.pop();
70 this.props.history.push(ROUTE_NAMES.NETWORK);
73 handleInviteTicketInput(inviteTicket) {
74 this.setState({ inviteTicket });
77 handleVerifyTicketInput(verifyTicket) {
78 this.setState({ verifyTicket });
81 updateTransactionProgress(transactionProgress) {
82 this.setState({ transactionProgress });
85 async unlockInviteWallet(inviteTicket) {
87 walletStates: this.state.walletStates.concat(WALLET_STATES.UNLOCKING),
88 stage: INVITE_STAGES.INVITE_WALLET,
91 //NOTE ~zod because tmp wallet
92 const ownership = await ownershipWalletFromTicket(inviteTicket, 0);
93 const mnemonic = ownership.seed;
94 //TODO isn't all this accessible in the ownership object?
95 const inviteWallet = walletFromMnemonic(
101 throw BRIDGE_ERROR.MISSING_WALLET;
105 const addr = inviteWallet.address;
107 const ctrcs = need.contracts(this.props);
109 const incoming = await azimuth.azimuth.getTransferringFor(ctrcs, addr);
112 walletStates: this.state.walletStates.concat(WALLET_STATES.GENERATING),
115 let realPoint = Nothing();
116 let realWallet = Nothing();
119 if (incoming.length > 0) {
120 let pointNum = parseInt(incoming[0], 10);
121 realPoint = Just(pointNum);
127 let genWallet = await generateWallet(pointNum);
129 realWallet = Just(genWallet);
130 if (incoming.length > 1) {
131 //TODO notify user "...and others / ticket reusable"
135 'Invite code has no claimable ship. Check your invite code and try again.',
141 inviteWallet: Just(inviteWallet),
142 // dev mode: uncomment this out to autofill verified ticket
143 verifyTicket: !Nothing.hasInstance(realWallet)
144 ? realWallet.value.ticket
146 walletStates: this.state.walletStates.concat(WALLET_STATES.RENDERING),
152 const phTick = this.ticketPlaceholder;
154 let isLogin = this.state.stage === INVITE_STAGES.INVITE_LOGIN;
155 let isVerify = this.state.stage === INVITE_STAGES.INVITE_VERIFY;
157 if (isLogin || isVerify) {
158 let value = isLogin ? this.state.inviteTicket : this.state.verifyTicket;
159 let handler = isLogin
160 ? this.handleInviteTicketInput
161 : this.handleVerifyTicketInput;
162 let label = isLogin ? 'Activation code' : 'ticket';
164 // if realWallet is Just, then VerifyTicketInput appropriate contents; if Nothing, remain Nothing
165 const Verified = this.state.realWallet.map(realWallet =>
166 VerifyTicketInput(realWallet.ticket)
169 // Verified.getOrElse(TicketInput) falls back to TicketInput if Verified is Nothing
170 const TicketElem = isVerify
171 ? Verified.getOrElse(TicketInput)
176 className="mono mt-8"
178 prop-format="innerLabel"
182 placeholder={`e.g. ${phTick}`}
185 <InnerLabel>{label}</InnerLabel>
194 const { stage } = this.state;
196 let progressWidth = this.state.transactionProgress.pct;
199 stage === INVITE_STAGES.INVITE_LOGIN ? (
200 <h1 className="text-700 mt-15">Welcome</h1>
201 ) : stage === INVITE_STAGES.INVITE_WALLET ? (
203 <h1 className="fs-6 lh-8 mb-3">Passport</h1>
205 A passport is your digital identity. You will use your passport to
206 access your true computer, send payments, and administer your
207 identity. So naturally, you must keep this secure.
210 After you’ve downloaded your passport, back up the ticket manually
211 or store on a trusted device.
214 ) : stage === INVITE_STAGES.INVITE_VERIFY ? (
216 <h1 className="fs-6 lh-8 mb-3">Verify Passport</h1>
218 Afer you download your passport, verify your custody. Your passport
219 should be a folder of image files. One of them is your Master
220 Ticket. Open it and enter the 4 word phrase below (with hyphens).
223 ) : INVITE_STAGES.INVITE_TRANSACTIONS ? (
224 this.state.transactionProgress.label ===
225 TRANSACTION_STATES.DONE.label ? (
227 <h1 className="fs-6 lh-8 mb-3">
229 <span className="ml-4 green">✓</span>
231 <p>Transferring to Bridge...</p>
235 <h1 className="fs-6 lh-8 mb-3">Submitting</h1>
236 <p className="mt-4 mb-4">
237 This step can take up to five minutes. Please do not leave this
238 page until the transactions are complete.
240 <div className="passport-progress mb-2">
242 className="passport-progress-filled"
243 style={{ width: progressWidth }}
246 <div className="flex justify-between">
247 <div className="text-mono text-sm lh-6 green-dark">
248 {this.state.transactionProgress.label}
258 updateProgress(notification) {
260 notification.type === 'progress'
261 ? { transactionProgress: notification.value }
262 : notification.type === 'notify'
263 ? { errors: [notification.value] }
266 this.setState(newState);
269 getContinueButton() {
279 const { web3, contracts, setUrbitWallet } = this.props;
281 const btnColor = this.state.walletStates.includes(WALLET_STATES.PAPER_READY)
286 stage === INVITE_STAGES.INVITE_LOGIN
288 this.unlockInviteWallet(inviteTicket);
290 : stage === INVITE_STAGES.INVITE_WALLET
293 stage: INVITE_STAGES.INVITE_VERIFY,
296 : stage === INVITE_STAGES.INVITE_VERIFY
299 stage: INVITE_STAGES.INVITE_TRANSACTIONS,
300 walletStates: this.state.walletStates.concat(
301 WALLET_STATES.TRANSACTIONS
306 inviteWalletM: inviteWallet,
307 realWalletM: realWallet,
308 realPointM: realPoint,
309 realTicket: verifyTicket,
313 updateProgress: this.updateProgress,
316 this.props.history.pop();
322 const ticketMatches = this.state.realWallet.matchWith({
323 Just: wal => wal.value.ticket === this.state.verifyTicket,
324 Nothing: () => false,
327 const continueReady =
328 stage === INVITE_STAGES.INVITE_WALLET
329 ? walletStates.includes(WALLET_STATES.DOWNLOADED)
330 : stage === INVITE_STAGES.INVITE_VERIFY
335 stage === INVITE_STAGES.INVITE_TRANSACTIONS ? null : (
339 prop-color={btnColor}
340 disabled={!continueReady}
341 onClick={clickHandler}>
350 const { stage } = this.state;
352 if (stage === INVITE_STAGES.INVITE_LOGIN) return null;
355 <div className="mt-6 mb-8">
357 className={`fs-35 mr-3 ${stage !== INVITE_STAGES.INVITE_WALLET &&
362 className={`fs-35 mr-3 ${stage !== INVITE_STAGES.INVITE_VERIFY &&
367 className={`fs-35 mr-3 ${stage !==
368 INVITE_STAGES.INVITE_TRANSACTIONS && 'gray-20'}`}>
376 if (this.state.errors.length === 0) return null;
378 let errorElems = this.state.errors.map(e => <span>{e}</span>);
382 <h3 className={'mb-2'}>{'Warning'}</h3>
389 let stageDisplay = this.getStageDisplay();
390 let stageText = this.getStageText();
391 let ticketElem = this.getTicketElement();
392 let continueButton = this.getContinueButton();
393 let errorDisplay = this.getErrors();
397 <Col className="col-md-4 mt-">
404 {this.state.stage === INVITE_STAGES.INVITE_LOGIN && (
408 className={`block mt-4`}
409 onClick={this.navigateLogin}>
414 <Col className="col-md-offset-3 col-md-5 mt-18">
416 point={this.state.realPoint}
417 wallet={this.state.realWallet}
418 walletStates={this.state.walletStates}
419 pushWalletState={this.pushWalletState}
427export 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