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, Form } 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 {
31 this.pointPlaceholder = placeholder(4)
32 this.ticketPlaceholder = placeholder(8)
34 this.handleTicketInput = this.handleTicketInput.bind(this)
35 this.handlePointNameInput = this.handlePointNameInput.bind(this)
38 handleTicketInput(ticket) {
39 this.setState({ ticket })
42 handlePointNameInput(pointName) {
43 if (pointName.length < 15) {
44 this.setState({ pointName })
48 // buttonTriState = (wallet) => {
49 // if (wallet.isNothing()) return 'blue'
50 // if (wallet === false) return 'yellow'
51 // if (Maybe.Nothing.hasInstance(wallet)) return 'green'
54 async walletFromTicket(ticket, pointName) {
55 const { setWallet, setUrbitWallet } = this.props
56 const urbitWallet = await kg.generateWallet({
58 ship: ob.patp2dec(pointName)
60 const mnemonic = urbitWallet.ownership.seed
61 const wallet = walletFromMnemonic(mnemonic, DEFAULT_HD_PATH)
63 setUrbitWallet(Maybe.Just(urbitWallet))
67 const { popRoute, pushRoute, wallet } = this.props
68 const { ticket, pointName } = this.state
70 const phPoint = this.pointPlaceholder
71 const phTick = this.ticketPlaceholder
76 <H1>{ 'Authenticate' }</H1>
79 { `Please enter your point and Urbit master ticket here. This information is written on your Urbit HD paper wallets.` }
87 prop-format='innerLabel'
90 placeholder={ `e.g. ${phPoint}` }
92 onChange={ this.handlePointNameInput }>
93 <InnerLabel>{ 'Point' }</InnerLabel>
95 className={'tr-0 mt-05 mr-0 abs'}
103 className='mono mt-8'
105 prop-format='innerLabel'
108 placeholder={ `e.g. ${phTick}` }
110 onChange={ this.handleTicketInput }>
111 <InnerLabel>{ 'Ticket' }</InnerLabel>
116 prop-size={'lg wide'}
117 // prop-color={this.buttonTriState(wallet)}
118 onClick={() => this.walletFromTicket(ticket, pointName)}>
124 prop-size={'xl wide'}
125 disabled={ Maybe.Nothing.hasInstance(wallet) }
128 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