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';
12import { useWallet } from 'store/wallet';
14import { sigil, reactRenderer } from 'urbit-sigil-js';
16function makeSigil(size, patp, colors) {
21 renderer: reactRenderer,
25 if (patp.length === 14) {
33 if (patp.length === 7) {
43 if (patp.length === 4) {
53const buildKeyType = permissions => {
54 if (permissions.isOwner) {
56 } else if (permissions.isManagementProxy) {
58 } else if (permissions.isSpawnProxy) {
60 } else if (permissions.isVotingProxy) {
62 } else if (permissions.isTransferProxy) {
67const symbols = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
70 * Address is Maybe<string>
71 * point is Maybe<string>
72 * animationMode is 'slide' | 'step' | 'none'
79 animationMode = 'none',
82 const [cols, rows, tile] = [35, 12, 12];
84 const loading = Nothing.hasInstance(address) || Nothing.hasInstance(point);
85 const defaultMatrix = () => {
86 return Matrix.new(rows, cols);
89 const patp = ob.patp(point.value);
91 const makeMatrix = addr => {
93 const onlyTheNumberPart = addr.substring(2);
94 // make bigNum from hex
95 const int = new BN(onlyTheNumberPart, 16);
96 // make a bigger number
97 const big = int.pow(new BN(10));
98 // parse that to a string and pad
99 const b10 = big.toString(10).padStart(32, '0');
100 // split the big number into parts
101 const chunkSize = Math.ceil(b10.length / 8);
102 const chunks = chunkStr(b10, chunkSize).map(c => new BN(c));
103 // generate an empty matrix
104 const startMatrix = Matrix.new(rows, cols);
105 // do a few random walks starting at diff coordinates
106 const [, matrix] = chunks.reduce((acc, chunk) => {
107 return walk(chunk, acc[1]);
108 // start with the 'random' points (not actually random, they are deterministic)
109 }, rand(big, startMatrix));
114 const matrix = address.matchWith({
115 Just: ({ value }) => makeMatrix(value),
116 Nothing: defaultMatrix,
119 const bgColor = inverted ? 'white' : 'black';
121 const fgColor = inverted ? 'black' : 'white';
123 const sigil = useMemo(
124 () => Just.hasInstance(point) && makeSigil(64, patp, [bgColor, fgColor]),
125 [patp, point, bgColor, fgColor]
131 backgroundColor: bgColor,
132 border: inverted ? '2px solid #E6E6E6' : '2px solid black',
133 borderRadius: '20px',
134 marginBottom: '16px',
135 width: `${16 + 16 + cols * tile}px`,
136 minWidth: `${16 + 16 + cols * tile}px`,
138 flexDirection: 'column',
150 alignItems: 'center',
162 fontFamily: 'Source Code Pro',
164 {Just.hasInstance(point) && patp}
173 fontFamily: 'Source Code Pro',
186 flexDirection: 'column',
189 filter: inverted ? 'invert(1)' : '',
191 {matrix.map((row, _row) => {
194 key={`card:row:${_row}`}
195 style={{ display: 'flex', justifyContent: 'space-between' }}>
196 {row.map((v, _col) => {
201 value={typeof symbols[v] === 'undefined' ? 13 : v}
203 spriteSheetHeight={12}
204 spriteSheetWidth={168}
207 animationMode={animationMode}
219const Cell = props => {
222 key={`card:cell:${props.row}:${props.col}:${props.value}`}
226 : props.animationMode === 'none'
228 : `${props.animationMode}-h-${props.value}`
231 backgroundImage: `url(/spritesheet_a.png)`,
233 props.animationMode === 'none'
234 ? `-${props.spriteSheetHeight * props.value}px 0px`
236 backgroundSize: `${props.spriteSheetWidth}px ${props.spriteSheetHeight}px`,
237 width: `${props.spriteSheetHeight}px`,
238 maxWidth: `${props.spriteSheetHeight}px`,
239 height: `${props.spriteSheetHeight}px`,
240 maxHeight: `${props.spriteSheetHeight}px`,
241 animationDelay: `${props.value * 50}ms`,
251function MiniPassport({ point, inverted, ...rest }) {
252 useSyncOwnedPoints([point]);
253 const { wallet } = useWallet();
254 const address = need.addressFromWallet(wallet);
256 const patp = ob.patp(point);
257 const permissions = usePermissionsForPoint(address, point);
258 const keyType = buildKeyType(permissions);
259 const sigil = useMemo(
261 makeSigil(44, patp, inverted ? ['white', 'black'] : ['black', 'white']),
268 backgroundColor: inverted ? 'white' : 'black',
269 border: inverted ? '2px solid #E6E6E6' : '2px solid black',
270 borderRadius: '20px',
271 marginBottom: '16px',
272 maxWidth: `${230}px`,
274 flexDirection: 'column',
287 alignItems: 'center',
294 flexDirection: 'column',
295 justifyContent: 'space-between',
300 color: inverted ? 'black' : 'white',
302 fontFamily: 'Source Code Pro',
311 color: inverted ? 'black' : 'white',
313 fontFamily: 'Source Code Pro',
327Passport.Mini = MiniPassport;
329export 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