on 1171039 help sign in
bridge/src/views/ViewPoint.js
88 lines 2.2 kB history raw
1import Maybe from 'folktale/maybe';
2import React from 'react';
3import * as ob from 'urbit-ob';
5import { Button } from '../components/old/Base';
6import { H1, P } from '../components/old/Base';
7import { InnerLabel, PointInput, ValidatedSigil } from '../components/old/Base';
9import { ROUTE_NAMES } from '../lib/routeNames';
10import { withHistory } from '../store/history';
11import { compose } from '../lib/lib';
12import { withPointCursor } from '../store/pointCursor';
13import View from 'components/View';
15class ViewPoint extends React.Component {
16 constructor(props) {
17 super(props);
19 this.state = {
20 pointName: '',
21 };
23 this.handlePointInput = this.handlePointInput.bind(this);
24 }
26 handlePointInput = pointName => {
27 if (pointName.length < 15) {
28 this.setState({ pointName });
29 }
30 };
32 render() {
33 const { pointName } = this.state;
34 const { history, setPointCursor } = this.props;
36 // NB (jtobin):
37 //
38 // could use a better patp parser in urbit-ob
39 let valid;
40 try {
41 valid = ob.isValidPatp(pointName);
42 } catch (err) {
43 valid = false;
44 }
46 return (
47 <View>
48 <H1>{'View a Point'}</H1>
50 <P>{'Enter a point name to view its public information.'}</P>
52 <PointInput
53 autoFocus
54 prop-size="lg"
55 prop-format="innerLabel"
56 className="mono"
57 placeholder="e.g. ~zod"
58 onChange={this.handlePointInput}
59 value={pointName}>
60 <InnerLabel>{'Point Name'}</InnerLabel>
61 <ValidatedSigil
62 className={'tr-0 mt-05 mr-0 abs'}
63 patp={pointName}
64 show
65 size={68}
66 margin={8}
67 />
68 </PointInput>
70 <Button
71 className={'mt-8'}
72 disabled={valid === false}
73 onClick={() => {
74 setPointCursor(Maybe.Just(parseInt(ob.patp2dec(pointName), 10)));
75 // ^ pointCursor expects native number type, not string
76 history.popAndPush(ROUTE_NAMES.SHIP);
77 }}>
78 {'Continue →'}
79 </Button>
80 </View>
81 );
82 }
85export default compose(
86 withHistory,
87 withPointCursor
88)(ViewPoint);