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 { chunkStr, Matrix, walk, rand } from 'lib/card';
10import { useSyncDetails } from 'lib/useSyncPoints';
12import './SigilMini.scss';
14function makeSigil(size, patp, colors) {
17 renderer: reactRenderer,
27const symbols = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
30 * Address is Maybe<string>
31 * point is Maybe<string>
32 * animationMode is 'slide' | 'step' | 'none'
39 animationMode = 'none',
42 const [cols, rows, tile] = [35, 12, 12];
44 const loading = Nothing.hasInstance(address) || Nothing.hasInstance(point);
45 const defaultMatrix = () => {
46 return Matrix.new(rows, cols);
49 const patp = ob.patp(point.value);
51 const makeMatrix = azimuthPoint => {
52 // convert point to hex
53 const azimuthPointHex = azimuthPoint.toString(16);
55 // make bigNum from hex
56 const int = new BN(azimuthPointHex, 16);
58 // make a bigger number
59 const big = int.pow(new BN(100));
60 // parse that to a string and pad
61 const b10 = big.toString(10).padStart(32, '0');
62 // split the big number into parts
63 const chunkSize = Math.ceil(b10.length / 8);
64 const chunks = chunkStr(b10, chunkSize).map(c => new BN(c));
65 // generate an empty matrix
66 const startMatrix = Matrix.new(rows, cols);
67 // do a few random walks starting at diff coordinates
68 const [, matrix] = chunks.reduce((acc, chunk) => {
69 return walk(chunk, acc[1]);
70 // start with the 'random' points (not actually random, they are deterministic)
71 }, rand(big, startMatrix));
76 const matrix = point.matchWith({
77 Just: ({ value }) => makeMatrix(value),
78 Nothing: defaultMatrix,
81 const bgColor = inverted ? 'white' : 'black';
83 const fgColor = inverted ? 'black' : 'white';
85 const sigil = useMemo(
86 () => Just.hasInstance(point) && makeSigil(64, patp, [bgColor, fgColor]),
87 [patp, point, bgColor, fgColor]
93 backgroundColor: bgColor,
94 border: inverted ? '2px solid #E6E6E6' : '2px solid black',
97 width: `${16 + 16 + cols * tile}px`,
98 minWidth: `${16 + 16 + cols * tile}px`,
100 flexDirection: 'column',
112 alignItems: 'center',
124 fontFamily: 'Source Code Pro',
126 {Just.hasInstance(point) && patp}
135 fontFamily: 'Source Code Pro',
148 flexDirection: 'column',
151 filter: inverted ? 'invert(1)' : '',
153 {matrix.map((row, _row) => {
156 key={`card:row:${_row}`}
157 style={{ display: 'flex', justifyContent: 'space-between' }}>
158 {row.map((v, _col) => {
163 value={typeof symbols[v] === 'undefined' ? 13 : v}
165 spriteSheetHeight={12}
166 spriteSheetWidth={168}
169 animationMode={animationMode}
182const Cell = props => {
185 key={`card:cell:${props.row}:${props.col}:${props.value}`}
189 : props.animationMode === 'none'
191 : `${props.animationMode}-h-${props.value}`
194 backgroundImage: `url(/spritesheet_a.png)`,
196 props.animationMode === 'none'
197 ? `-${props.spriteSheetHeight * props.value}px 0px`
199 backgroundSize: `${props.spriteSheetWidth}px ${props.spriteSheetHeight}px`,
200 width: `${props.spriteSheetHeight}px`,
201 maxWidth: `${props.spriteSheetHeight}px`,
202 height: `${props.spriteSheetHeight}px`,
203 maxHeight: `${props.spriteSheetHeight}px`,
204 animationDelay: `${props.value * 50}ms`,
214function MiniPassport({ point, inverted, locked = false, ...rest }) {
215 useSyncDetails([point]);
216 // const { wallet } = useWallet();
217 // const address = need.addressFromWallet(wallet);
218 // const permissions = usePermissionsForPoint(address, point);
219 // const keyType = buildKeyType(permissions);
220 const patp = ob.patp(point);
222 const contrast = locked ? '#666666' : 'black';
224 const sigil = useMemo(
226 makeSigil(50, patp, inverted ? ['white', contrast] : [contrast, 'white']),
227 [inverted, patp, contrast]
230 <div {...rest} className="sigil-mini">
231 <div className={`sigil ${locked ? 'locked' : ''}`}>{sigil}</div>
232 <span className="patp">{patp}</span>
233 {locked && <Icon color="white" icon="Locked" className="lock" />}
238Passport.Mini = MiniPassport;
240export 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