1import Maybe from 'folktale/maybe'
2import React from 'react'
3import { Button } from '../components/Base'
4import { InnerLabel, ValidatedSigil, PointInput, TicketInput } from '../components/Base'
5import { Row, Col, H1, P } from '../components/Base'
6import * as kg from '../../node_modules/urbit-key-generation/dist/index'
7import * as ob from 'urbit-ob'
9import { ROUTE_NAMES } from '../lib/router'
10import { DEFAULT_HD_PATH, walletFromMnemonic } from '../lib/wallet'
12const placeholder = (len) => {
13 let bytes = window.crypto.getRandomValues(new Uint8Array(len))
14 let hex = bytes.reduce((acc, byt) =>
15 acc + byt.toString(16).padStart(2, '0'),
18 return ob.hex2patq(hex)
21class Ticket extends React.Component {
32 this.pointPlaceholder = placeholder(4)
33 this.ticketPlaceholder = placeholder(8)
35 this.handleTicketInput = this.handleTicketInput.bind(this)
36 this.handlePointNameInput = this.handlePointNameInput.bind(this)
39 handleTicketInput(ticket) {
40 this.setState({ ticket })
43 handlePointNameInput(pointName) {
44 if (pointName.length < 15) {
45 this.setState({ pointName })
49 // buttonTriState = (wallet) => {
50 // if (wallet.isNothing()) return 'blue'
51 // if (wallet === false) return 'yellow'
52 // if (Maybe.Nothing.hasInstance(wallet)) return 'green'
55 async walletFromTicket(ticket, pointName) {
56 const { setWallet, setUrbitWallet } = this.props
62 const urbitWallet = await kg.generateWallet({
64 ship: ob.patp2dec(pointName)
66 const mnemonic = urbitWallet.ownership.seed
67 const wallet = walletFromMnemonic(mnemonic, DEFAULT_HD_PATH)
69 setUrbitWallet(Maybe.Just(urbitWallet))
77 const { popRoute, pushRoute, wallet } = this.props
78 const { ticket, pointName } = this.state
80 const phPoint = this.pointPlaceholder
81 const phTick = this.ticketPlaceholder
86 <H1>{ 'Authenticate' }</H1>
89 { `Please enter your point and Urbit master ticket here. This information is written on your Urbit HD paper wallets.` }
95 prop-format='innerLabel'
98 placeholder={ `e.g. ${phPoint}` }
100 onChange={ this.handlePointNameInput }>
101 <InnerLabel>{ 'Point' }</InnerLabel>
103 className={'tr-0 mt-05 mr-0 abs'}
111 className='mono mt-8'
113 prop-format='innerLabel'
116 placeholder={ `e.g. ${phTick}` }
118 onChange={ this.handleTicketInput }>
119 <InnerLabel>{ 'Ticket' }</InnerLabel>
124 prop-size={'lg wide'}
125 disabled={this.state.isUnlocking || Maybe.Just.hasInstance(wallet)}
126 // prop-color={this.buttonTriState(wallet)}
127 onClick={() => this.walletFromTicket(ticket, pointName)}>
129 <span className="relative">
130 {this.state.isUnlocking &&
131 <span className="btn-spinner"></span>
139 prop-size={'xl wide'}
140 disabled={ Maybe.Nothing.hasInstance(wallet) }
143 pushRoute(ROUTE_NAMES.SHIPS)
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