1import React from 'react';
2import { Just, Nothing } from 'folktale/maybe';
3import ob from 'urbit-ob';
5import 'style/anim.css';
7import * as need from 'lib/need';
8import { chunkStr, Matrix, walk, rand } from 'lib/card';
9import usePermissionsForPoint from 'lib/usePermissionsForPoint';
10import { useSyncOwnedPoints } from 'lib/useSyncPoints';
11import { buildKeyType } from 'lib/point';
13import { useWallet } from 'store/wallet';
15import { sigil, reactRenderer } from 'urbit-sigil-js';
17function makeSigil(size, patp, colors) {
22 renderer: reactRenderer,
26 if (patp.length === 14) {
34 if (patp.length === 7) {
44 if (patp.length === 4) {
54const symbols = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
57 * Address is Maybe<string>
58 * point is Maybe<string>
59 * animationMode is 'slide' | 'step' | 'none'
66 animationMode = 'none',
69 const [cols, rows, tile] = [35, 12, 12];
71 const loading = Nothing.hasInstance(address) || Nothing.hasInstance(point);
72 const defaultMatrix = () => {
73 return Matrix.new(rows, cols);
76 const patp = ob.patp(point.value);
78 const makeMatrix = addr => {
80 const onlyTheNumberPart = addr.substring(2);
81 // make bigNum from hex
82 const int = new BN(onlyTheNumberPart, 16);
83 // make a bigger number
84 const big = int.pow(new BN(10));
85 // parse that to a string and pad
86 const b10 = big.toString(10).padStart(32, '0');
87 // split the big number into parts
88 const chunkSize = Math.ceil(b10.length / 8);
89 const chunks = chunkStr(b10, chunkSize).map(c => new BN(c));
90 // generate an empty matrix
91 const startMatrix = Matrix.new(rows, cols);
92 // do a few random walks starting at diff coordinates
93 const [, matrix] = chunks.reduce((acc, chunk) => {
94 return walk(chunk, acc[1]);
95 // start with the 'random' points (not actually random, they are deterministic)
96 }, rand(big, startMatrix));
101 const matrix = address.matchWith({
102 Just: ({ value }) => makeMatrix(value),
103 Nothing: defaultMatrix,
106 const bgColor = inverted ? 'white' : 'black';
108 const fgColor = inverted ? 'black' : 'white';
114 backgroundColor: bgColor,
115 border: inverted ? '2px solid #E6E6E6' : '2px solid black',
116 borderRadius: '20px',
117 marginBottom: '16px',
118 width: `${16 + 16 + cols * tile}px`,
119 minWidth: `${16 + 16 + cols * tile}px`,
121 flexDirection: 'column',
133 alignItems: 'center',
135 {Just.hasInstance(point) && makeSigil(64, patp, [bgColor, fgColor])}
145 fontFamily: 'Source Code Pro',
147 {Just.hasInstance(point) && patp}
156 fontFamily: 'Source Code Pro',
169 flexDirection: 'column',
172 filter: inverted ? 'invert(1)' : '',
174 {matrix.map((row, _row) => {
177 key={`card:row:${_row}`}
178 style={{ display: 'flex', justifyContent: 'space-between' }}>
179 {row.map((v, _col) => {
184 value={typeof symbols[v] === 'undefined' ? 13 : v}
186 spriteSheetHeight={12}
187 spriteSheetWidth={168}
190 animationMode={animationMode}
202const Cell = props => {
205 key={`card:cell:${props.row}:${props.col}:${props.value}`}
209 : props.animationMode === 'none'
211 : `${props.animationMode}-h-${props.value}`
214 backgroundImage: `url(/spritesheet_a.png)`,
216 props.animationMode === 'none'
217 ? `-${props.spriteSheetHeight * props.value}px 0px`
219 backgroundSize: `${props.spriteSheetWidth}px ${props.spriteSheetHeight}px`,
220 width: `${props.spriteSheetHeight}px`,
221 maxWidth: `${props.spriteSheetHeight}px`,
222 height: `${props.spriteSheetHeight}px`,
223 maxHeight: `${props.spriteSheetHeight}px`,
224 animationDelay: `${props.value * 50}ms`,
234function MiniPassport({ point, inverted, ...rest }) {
235 useSyncOwnedPoints([point]);
236 const { wallet } = useWallet();
237 const address = need.addressFromWallet(wallet);
239 const patp = ob.patp(point);
240 const permissions = usePermissionsForPoint(address, point);
241 const keyType = buildKeyType(permissions);
246 backgroundColor: inverted ? 'white' : 'black',
247 border: inverted ? '2px solid #E6E6E6' : '2px solid black',
248 borderRadius: '20px',
249 marginBottom: '16px',
250 maxWidth: `${230}px`,
252 flexDirection: 'column',
265 alignItems: 'center',
270 inverted ? ['white', 'black'] : ['black', 'white']
276 flexDirection: 'column',
277 justifyContent: 'space-between',
282 color: inverted ? 'black' : 'white',
284 fontFamily: 'Source Code Pro',
293 color: inverted ? 'black' : 'white',
295 fontFamily: 'Source Code Pro',
309Passport.Mini = MiniPassport;
311export default Passport;
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