1import ob from 'urbit-ob';
2import { patp2dec } from './patp2dec';
3import { fromWei, toWei, toBN } from 'web3-utils';
5const safeFromWei = (num, target) => {
7 return fromWei(toBN(num), target);
10 `(safeFromWei got ${typeof num} (${num}), made ${typeof toBN(
12 )}. Please report this issue!) ` + e.message;
17const safeToWei = (num, source) => {
19 return toWei(toBN(num), source);
22 `(safeToWei got ${typeof num} (${num}), made ${typeof toBN(
24 )}. Please report this issue!) ` + e.message;
29const compose = (...fs) =>
31 (pF, nF) => (...args) => nF(pF(...args)),
35const allFalse = (...args) => args.every(a => a === false);
37const isLast = (l, i) => i === l - 1;
39const isUndefined = v => v === undefined;
41const defaultTo = (v, d) => (isUndefined(v) ? d : v);
43const seq = n => Array.from(Array(n), (_, i) => i);
45const fill = (n, v) => Array.from(Array(n), () => v);
47const strSplice = (arr, i, val) => `${arr.slice(0, i)}${val}${arr.slice(i)}`;
49const isValidGalaxy = name => {
52 point = patp2dec(name);
56 return point >= 0 && point < 256;
59const randomPatq = len => {
60 let bytes = window.crypto.getRandomValues(new Uint8Array(len));
61 let hex = bytes.reduce(
62 (acc, byt) => acc + byt.toString(16).padStart(2, '0'),
65 return ob.hex2patq(hex);
68// TODO: is there a function for this calculation in urbit-ob or similar?
69// 3 characters per byte, plus a tilde and hypen prefix per pair of bytes
70const patpStringLength = byteLength =>
71 byteLength * 3 + Math.ceil(byteLength / 2);
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