on master help sign in
fix: expand ensurePatFormat to cover prependSig case
d72cd54Matt Condon (shrugs)
src/form/Inputs.js+2−8
@@ -3,11 +3,10 @@ import { Input, AccessoryIcon } from 'indigo-react';
3import { useField } from 'react-final-form';
3import { useField } from 'react-final-form';
4
4
5import {
5import {
6− prependSig,
7 convertToNumber,
6 convertToNumber,
8 buildFormatter,
7 buildFormatter,
9 downcase,
8 downcase,
10− ensurePatQDashes,
9+ ensurePatFormat,
11} from 'form/formatters';
10} from 'form/formatters';
12import { DEFAULT_HD_PATH } from 'lib/wallet';
11import { DEFAULT_HD_PATH } from 'lib/wallet';
13import InputSigil from 'components/InputSigil';
12import InputSigil from 'components/InputSigil';
@@ -22,12 +21,7 @@ const PLACEHOLDER_PRIVATE_KEY =
22 '0x12345abcdee6beb2f323fab48b432925c9785808d33a6ca6d7ba00b45e9370c3';
21 '0x12345abcdee6beb2f323fab48b432925c9785808d33a6ca6d7ba00b45e9370c3';
23const PLACEHOLDER_EMAIL = 'Email Address';
22const PLACEHOLDER_EMAIL = 'Email Address';
24
23
25−const TICKET_MAX_BYTE_LEN = 32; // tickets can be as large as 32 bytes
26−const formatPat = buildFormatter([
24+const formatPat = buildFormatter([downcase, ensurePatFormat]);
27− downcase,
28− prependSig,
29− ensurePatQDashes(TICKET_MAX_BYTE_LEN),
30−]);
31
25
32export function TicketInput({ name, ...rest }) {
26export function TicketInput({ name, ...rest }) {
33 const {
27 const {
src/form/formatters.js+10−16
@@ -1,39 +1,33 @@
1import { compose, strSplice } from 'lib/lib';
1import { compose, strSplice } from 'lib/lib';
2
2
3+const TICKET_MAX_BYTE_LEN = 32; // tickets can be as large as 32 bytes
4+
3export const buildFormatter = (formatters = []) =>
5export const buildFormatter = (formatters = []) =>
4 compose(...formatters.reverse());
6 compose(...formatters.reverse());
5
7
6−export const prependSig = s => {
7− if (!s || s.length === 0) {
8− return s || '';
9− }
10−
11− return s.charAt(0) === '~' ? s : `~${s}`;
12−};
13−
14/**
8/**
15− * inserts a - every 7 characters
9+ * inserts a ~ or - every 7 characters
16− * (must be preceeded by prependSig to work correctly)
17− * @param {number} maxByteLength the maximum number of patq blocks to have in a string
18 */
10 */
19−export const ensurePatQDashes = maxByteLength => s => {
11+export const ensurePatFormat = s => {
20 if (!s || s.length === 0) {
12 if (!s || s.length === 0) {
21 return s || '';
13 return s || '';
22 }
14 }
23
15
24 // ensure there's a dash every 6 + 1 characters
16 // ensure there's a dash every 6 + 1 characters
25 const dashAt = i => i * (6 + 1);
17 const dashAt = i => i * (6 + 1);
26− const maxBlocks = maxByteLength / 2;
18+ const maxBlocks = TICKET_MAX_BYTE_LEN / 2;
27
19
28− for (let i = 1; i !== maxBlocks; i++) {
20+ for (let i = 0; i !== maxBlocks; i++) {
29 const dashIndex = dashAt(i);
21 const dashIndex = dashAt(i);
30
22
31 if (s.length - 1 < dashIndex) {
23 if (s.length - 1 < dashIndex) {
32 return s;
24 return s;
33 }
25 }
34
26
27+ const sep = i === 0 ? '~' : '-';
28+
35− if (s.charAt(dashIndex) !== '-') {
29+ if (s.charAt(dashIndex) !== sep) {
36− s = strSplice(s, dashIndex, '-');
30+ s = strSplice(s, dashIndex, sep);
37 }
31 }
38 }
32 }
39
33
src/lib/useImpliedPoint.js+2−2
@@ -1,13 +1,13 @@
1import * as ob from 'urbit-ob';
1import * as ob from 'urbit-ob';
2
2
3−import { prependSig } from 'form/formatters';
3+import { ensurePatFormat } from 'form/formatters';
4
4
5/**
5/**
6 * pull the suggested point from the subdomain
6 * pull the suggested point from the subdomain
7 */
7 */
8export default function useImpliedPoint() {
8export default function useImpliedPoint() {
9 const subdomain = window.location.host.split('.')[0];
9 const subdomain = window.location.host.split('.')[0];
10− const patp = prependSig(subdomain);
10+ const patp = ensurePatFormat(subdomain);
11 const isValid = ob.isValidPatp(patp);
11 const isValid = ob.isValidPatp(patp);
12
12
13 return isValid ? patp : null;
13 return isValid ? patp : null;
src/lib/useImpliedTicket.js+2−2
@@ -1,13 +1,13 @@
1import * as ob from 'urbit-ob';
1import * as ob from 'urbit-ob';
2
2
3−import { prependSig } from 'form/formatters';
3+import { ensurePatFormat } from 'form/formatters';
4
4
5/**
5/**
6 * pull the suggested ticket from the #hash in the url
6 * pull the suggested ticket from the #hash in the url
7 */
7 */
8export default function useImpliedTicket() {
8export default function useImpliedTicket() {
9 const hash = window.location.hash.slice(1);
9 const hash = window.location.hash.slice(1);
10− const ticket = prependSig(hash);
10+ const ticket = ensurePatFormat(hash);
11 const isValid = ob.isValidPatq(ticket);
11 const isValid = ob.isValidPatq(ticket);
12
12
13 return isValid ? ticket : null;
13 return isValid ? ticket : null;