1import React, { useMemo } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
3import ob from 'urbit-ob';
5import 'style/anim.css';
6import { sigil, reactRenderer } from 'urbit-sigil-js';
7import { Icon } from '@tlon/indigo-react';
9import * as need from 'lib/need';
10import { chunkStr, Matrix, walk, rand } from 'lib/card';
11import usePermissionsForPoint from 'lib/usePermissionsForPoint';
12import { useSyncDetails } from 'lib/useSyncPoints';
13import { buildKeyType } from 'lib/point';
15import { useWallet } from 'store/wallet';
17import './SigilMini.scss';
19function makeSigil(size, patp, colors) {
22 renderer: reactRenderer,
32const symbols = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
35 * Address is Maybe<string>
36 * point is Maybe<string>
37 * animationMode is 'slide' | 'step' | 'none'
44 animationMode = 'none',
47 const [cols, rows, tile] = [35, 12, 12];
49 const loading = Nothing.hasInstance(address) || Nothing.hasInstance(point);
50 const defaultMatrix = () => {
51 return Matrix.new(rows, cols);
54 const patp = ob.patp(point.value);
56 const makeMatrix = addr => {
58 const onlyTheNumberPart = addr.substring(2);
59 // make bigNum from hex
60 const int = new BN(onlyTheNumberPart, 16);
61 // make a bigger number
62 const big = int.pow(new BN(10));
63 // parse that to a string and pad
64 const b10 = big.toString(10).padStart(32, '0');
65 // split the big number into parts
66 const chunkSize = Math.ceil(b10.length / 8);
67 const chunks = chunkStr(b10, chunkSize).map(c => new BN(c));
68 // generate an empty matrix
69 const startMatrix = Matrix.new(rows, cols);
70 // do a few random walks starting at diff coordinates
71 const [, matrix] = chunks.reduce((acc, chunk) => {
72 return walk(chunk, acc[1]);
73 // start with the 'random' points (not actually random, they are deterministic)
74 }, rand(big, startMatrix));
79 const matrix = address.matchWith({
80 Just: ({ value }) => makeMatrix(value),
81 Nothing: defaultMatrix,
84 const bgColor = inverted ? 'white' : 'black';
86 const fgColor = inverted ? 'black' : 'white';
88 const sigil = useMemo(
89 () => Just.hasInstance(point) && makeSigil(64, patp, [bgColor, fgColor]),
90 [patp, point, bgColor, fgColor]
96 backgroundColor: bgColor,
97 border: inverted ? '2px solid #E6E6E6' : '2px solid black',
100 width: `${16 + 16 + cols * tile}px`,
101 minWidth: `${16 + 16 + cols * tile}px`,
103 flexDirection: 'column',
115 alignItems: 'center',
127 fontFamily: 'Source Code Pro',
129 {Just.hasInstance(point) && patp}
138 fontFamily: 'Source Code Pro',
151 flexDirection: 'column',
154 filter: inverted ? 'invert(1)' : '',
156 {matrix.map((row, _row) => {
159 key={`card:row:${_row}`}
160 style={{ display: 'flex', justifyContent: 'space-between' }}>
161 {row.map((v, _col) => {
166 value={typeof symbols[v] === 'undefined' ? 13 : v}
168 spriteSheetHeight={12}
169 spriteSheetWidth={168}
172 animationMode={animationMode}
184const Cell = props => {
187 key={`card:cell:${props.row}:${props.col}:${props.value}`}
191 : props.animationMode === 'none'
193 : `${props.animationMode}-h-${props.value}`
196 backgroundImage: `url(/spritesheet_a.png)`,
198 props.animationMode === 'none'
199 ? `-${props.spriteSheetHeight * props.value}px 0px`
201 backgroundSize: `${props.spriteSheetWidth}px ${props.spriteSheetHeight}px`,
202 width: `${props.spriteSheetHeight}px`,
203 maxWidth: `${props.spriteSheetHeight}px`,
204 height: `${props.spriteSheetHeight}px`,
205 maxHeight: `${props.spriteSheetHeight}px`,
206 animationDelay: `${props.value * 50}ms`,
216function MiniPassport({ point, inverted, locked = false, ...rest }) {
217 useSyncDetails([point]);
218 const { wallet } = useWallet();
219 const address = need.addressFromWallet(wallet);
221 const patp = ob.patp(point);
222 const permissions = usePermissionsForPoint(address, point);
223 const keyType = buildKeyType(permissions);
225 const contrast = locked ? '#666666' : 'black'
227 const sigil = useMemo(
229 makeSigil(50, patp, inverted ? ['white', contrast] : [contrast, 'white']),
230 [inverted, patp, contrast]
233 <div {...rest} className="sigil-mini">
234 <div className={`sigil ${locked ? 'locked' : ''}`}>{sigil}</div>
235 <span className="patp">{patp}</span>
236 {locked && <Icon color="white" icon="Locked" className="lock" />}
241Passport.Mini = MiniPassport;
243export 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