1import React from 'react';
2import { Just, Nothing } from 'folktale/maybe';
3import ob from 'urbit-ob';
6import * as need from 'lib/need';
7import { chunkStr, Matrix, walk, rand } from 'lib/card';
8import usePermissionsForPoint from 'lib/usePermissionsForPoint';
9import { useSyncOwnedPoints } from 'lib/useSyncPoints';
11import { useWallet } from 'store/wallet';
13import MaybeSigil from './MaybeSigil';
14import { sigil, reactRenderer } from 'urbit-sigil-js';
16function makeSigil(size, patp, colors) {
21 renderer: reactRenderer,
25 if (patp.length === 14) {
32 if (patp.length === 7) {
41 if (patp.length === 4) {
50const buildKeyType = permissions => {
51 if (permissions.isOwner) {
53 } else if (permissions.isManagementProxy) {
55 } else if (permissions.isSpawnProxy) {
57 } else if (permissions.isVotingProxy) {
59 } else if (permissions.isTransferProxy) {
64const symbols = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
67 * Address is Maybe<string>
68 * point is Maybe<string>
69 * animationMode is 'slide' | 'step' | 'none'
72function Passport({ address, point, inverted, animationMode, keyType }) {
73 const [cols, rows, tile] = [35, 12, 12];
75 const loading = Nothing.hasInstance(address) || Nothing.hasInstance(point);
76 const defaultMatrix = () => {
77 return Matrix.new(rows, cols);
80 const patp = ob.patp(point.value);
82 const makeMatrix = addr => {
84 const onlyTheNumberPart = addr.substring(2);
85 // make bigNum from hex
86 const int = new BN(onlyTheNumberPart, 16);
87 // make a bigger number
88 const big = int.pow(new BN(10));
89 // parse that to a string and pad
90 const b10 = big.toString(10).padStart(32, '0');
91 // split the big number into parts
92 const chunkSize = Math.ceil(b10.length / 8);
93 const chunks = chunkStr(b10, chunkSize).map(c => new BN(c));
94 // generate an empty matrix
95 const startMatrix = Matrix.new(rows, cols);
96 // do a few random walks starting at diff coordinates
97 const [, matrix] = chunks.reduce((acc, chunk) => {
98 return walk(chunk, acc[1]);
99 // start with the 'random' points (not actually random, they are deterministic)
100 }, rand(big, startMatrix));
105 const matrix = address.matchWith({
106 Just: ({ value }) => makeMatrix(value),
107 Nothing: defaultMatrix,
110 const bgColor = inverted ? 'white' : 'black';
112 const fgColor = inverted ? 'black' : 'white';
118 backgroundColor: bgColor,
119 border: inverted ? '2px solid #E6E6E6' : '2px solid black',
120 borderRadius: '20px',
121 marginBottom: '16px',
122 minWidth: `${16 + 16 + cols * tile}px`,
124 flexDirection: 'column',
136 alignItems: 'center',
138 {Just.hasInstance(point) && (
139 <MaybeSigil patp={patp.map(ob.patp).value} />
150 fontFamily: 'Source Code Pro',
161 fontFamily: 'Source Code Pro',
174 flexDirection: 'column',
177 filter: inverted ? 'invert(1)' : '',
179 {matrix.map((row, _row) => {
182 key={`card:row:${_row}`}
183 style={{ display: 'flex', justifyContent: 'space-between' }}>
184 {row.map((v, _col) => {
189 value={typeof symbols[v] === 'undefined' ? 13 : v}
191 spriteSheetHeight={12}
192 spriteSheetWidth={168}
195 animationMode={animationMode}
207const Cell = props => {
210 key={`card:cell:${props.row}:${props.col}:${props.value}`}
214 : props.animationMode === 'none'
216 : `${props.animationMode}-h-${props.value}`
219 backgroundImage: `url(/spritesheet_a.png)`,
221 props.animationMode === 'none'
222 ? `-${props.spriteSheetHeight * props.value}px 0px`
224 backgroundSize: `${props.spriteSheetWidth}px ${props.spriteSheetHeight}px`,
225 width: `${props.spriteSheetHeight}px`,
226 maxWidth: `${props.spriteSheetHeight}px`,
227 height: `${props.spriteSheetHeight}px`,
228 maxHeight: `${props.spriteSheetHeight}px`,
229 animationDelay: `${props.value * 50}ms`,
239function MiniPassport({ point, inverted, ...rest }) {
240 useSyncOwnedPoints([point]);
241 const { wallet } = useWallet();
242 const address = need.addressFromWallet(wallet);
244 const patp = ob.patp(point);
245 const permissions = usePermissionsForPoint(address, point);
246 const keyType = buildKeyType(permissions);
251 backgroundColor: inverted ? 'white' : 'black',
252 border: inverted ? '2px solid #E6E6E6' : '2px solid black',
253 borderRadius: '20px',
254 marginBottom: '16px',
257 flexDirection: 'column',
270 alignItems: 'center',
275 inverted ? ['white', 'black'] : ['black', 'white']
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