1import React, { useMemo } 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';
110 const sigil = useMemo(
111 () => Just.hasInstance(point) && makeSigil(64, patp, [bgColor, fgColor]),
112 [patp, point, bgColor, fgColor]
118 backgroundColor: bgColor,
119 border: inverted ? '2px solid #E6E6E6' : '2px solid black',
120 borderRadius: '20px',
121 marginBottom: '16px',
122 width: `${16 + 16 + cols * tile}px`,
123 minWidth: `${16 + 16 + cols * tile}px`,
125 flexDirection: 'column',
137 alignItems: 'center',
149 fontFamily: 'Source Code Pro',
151 {Just.hasInstance(point) && patp}
160 fontFamily: 'Source Code Pro',
173 flexDirection: 'column',
176 filter: inverted ? 'invert(1)' : '',
178 {matrix.map((row, _row) => {
181 key={`card:row:${_row}`}
182 style={{ display: 'flex', justifyContent: 'space-between' }}>
183 {row.map((v, _col) => {
188 value={typeof symbols[v] === 'undefined' ? 13 : v}
190 spriteSheetHeight={12}
191 spriteSheetWidth={168}
194 animationMode={animationMode}
206const Cell = props => {
209 key={`card:cell:${props.row}:${props.col}:${props.value}`}
213 : props.animationMode === 'none'
215 : `${props.animationMode}-h-${props.value}`
218 backgroundImage: `url(/spritesheet_a.png)`,
220 props.animationMode === 'none'
221 ? `-${props.spriteSheetHeight * props.value}px 0px`
223 backgroundSize: `${props.spriteSheetWidth}px ${props.spriteSheetHeight}px`,
224 width: `${props.spriteSheetHeight}px`,
225 maxWidth: `${props.spriteSheetHeight}px`,
226 height: `${props.spriteSheetHeight}px`,
227 maxHeight: `${props.spriteSheetHeight}px`,
228 animationDelay: `${props.value * 50}ms`,
238function MiniPassport({ point, inverted, ...rest }) {
239 useSyncOwnedPoints([point]);
240 const { wallet } = useWallet();
241 const address = need.addressFromWallet(wallet);
243 const patp = ob.patp(point);
244 const permissions = usePermissionsForPoint(address, point);
245 const keyType = buildKeyType(permissions);
246 const sigil = useMemo(
248 makeSigil(44, patp, inverted ? ['white', 'black'] : ['black', 'white']),
255 backgroundColor: inverted ? 'white' : 'black',
256 border: inverted ? '2px solid #E6E6E6' : '2px solid black',
257 borderRadius: '20px',
258 marginBottom: '16px',
259 maxWidth: `${230}px`,
261 flexDirection: 'column',
274 alignItems: 'center',
281 flexDirection: 'column',
282 justifyContent: 'space-between',
287 color: inverted ? 'black' : 'white',
289 fontFamily: 'Source Code Pro',
298 color: inverted ? 'black' : 'white',
300 fontFamily: 'Source Code Pro',
314Passport.Mini = MiniPassport;
316export 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