on master help sign in
qol: address PR feedback
3a5f70ctomholford
src/lib/useWalletConnect.ts+3−4
@@ -7,7 +7,7 @@ import { Just } from 'folktale/maybe';
7
7
8import { useWallet } from 'store/wallet';
8import { useWallet } from 'store/wallet';
9import { getAuthToken } from './authToken';
9import { getAuthToken } from './authToken';
10−import { DEFAULT_HD_PATH, WALLET_TYPES } from './constants';
10+import { WALLET_TYPES } from './constants';
11import WalletConnectWallet from './types/WalletConnectWallet';
11import WalletConnectWallet from './types/WalletConnectWallet';
12
12
13type PeerMeta = {
13type PeerMeta = {
@@ -30,7 +30,7 @@ type ConnectEvent = {
30};
30};
31
31
32export const useWalletConnect = () => {
32export const useWalletConnect = () => {
33− const { setWallet, setWalletHdPath, setAuthToken, resetWallet } = useWallet();
33+ const { setWallet, setAuthToken, resetWallet } = useWallet();
34 const [connector, setConnector] = useState<WalletConnect | null>(null);
34 const [connector, setConnector] = useState<WalletConnect | null>(null);
35 const [address, setAddress] = useState<string | null>(null);
35 const [address, setAddress] = useState<string | null>(null);
36 const [peerMeta, setPeerMeta] = useState<PeerMeta | null>(null);
36 const [peerMeta, setPeerMeta] = useState<PeerMeta | null>(null);
@@ -76,7 +76,7 @@ export const useWalletConnect = () => {
76 await connector.killSession();
76 await connector.killSession();
77 };
77 };
78
78
79− const authenticate = async ({ hdPath = DEFAULT_HD_PATH }) => {
79+ const authenticate = async () => {
80 if (!(address && connector)) {
80 if (!(address && connector)) {
81 return;
81 return;
82 }
82 }
@@ -93,7 +93,6 @@ export const useWalletConnect = () => {
93
93
94 setAuthToken(Just(authToken));
94 setAuthToken(Just(authToken));
95 setWallet(Just(wallet));
95 setWallet(Just(wallet));
96− setWalletHdPath(hdPath);
97 };
96 };
98
97
99 const isConnected = () => {
98 const isConnected = () => {
src/lib/utils/address.ts−9
@@ -37,12 +37,3 @@ export const eqAddr = (addr0, addr1) =>
37export const publicToAddress = (publicKey: Buffer): string => {
37export const publicToAddress = (publicKey: Buffer): string => {
38 return toHex(pubToAddress(publicKey, true).toString('hex'));
38 return toHex(pubToAddress(publicKey, true).toString('hex'));
39};
39};
40−
41−export function sanitizeHex(hex: string): string {
42− hex = hex.substring(0, 2) === '0x' ? hex.substring(2) : hex;
43− if (hex === '') {
44− return '';
45− }
46− hex = hex.length % 2 !== 0 ? '0' + hex : hex;
47− return '0x' + hex;
48−}
src/views/Login/WalletConnect.tsx+5−62
@@ -1,17 +1,9 @@
1−import { useCallback, useMemo } from 'react';
2import { Image } from '@tlon/indigo-react';
1import { Image } from '@tlon/indigo-react';
3import BridgeForm from 'form/BridgeForm';
2import BridgeForm from 'form/BridgeForm';
4−import Condition from 'form/Condition';
5import FormError from 'form/FormError';
3import FormError from 'form/FormError';
6−import { HdPathInput } from 'form/Inputs';
7import SubmitButton from 'form/SubmitButton';
4import SubmitButton from 'form/SubmitButton';
8−import {
9− buildCheckboxValidator,
10− buildHdPathValidator,
11− composeValidator,
12−} from 'form/validators';
13−import { CheckboxInput, Grid, Text as LegacyText } from 'indigo-react';
5+import { Grid, Text as LegacyText } from 'indigo-react';
14−import { DEFAULT_HD_PATH, WALLET_TYPES } from 'lib/constants';
6+import { WALLET_TYPES } from 'lib/constants';
15import useLoginView from 'lib/useLoginView';
7import useLoginView from 'lib/useLoginView';
16import { useWalletConnect } from 'lib/useWalletConnect';
8import { useWalletConnect } from 'lib/useWalletConnect';
17import { abbreviateAddress } from 'lib/utils/address';
9import { abbreviateAddress } from 'lib/utils/address';
@@ -30,35 +22,8 @@ const WalletConnectLogin = ({ className, goHome }) => {
30 peerMeta,
22 peerMeta,
31 } = useWalletConnect();
23 } = useWalletConnect();
32
24
33− const initialValues = useMemo(
34− () => ({
35− useCustomPath: false,
36− hdPath: DEFAULT_HD_PATH,
37− }),
38− []
39− );
40−
41− const validate = useMemo(
42− () =>
43− composeValidator({
44− useCustomPath: buildCheckboxValidator(),
45− hdPath: buildHdPathValidator(),
46− }),
47− []
48− );
49−
50− const onValues = useCallback(({ valid, values, form }) => {
51− if (!valid) {
52− return;
53− }
54−
55− if (!values.useCustomPath) {
56− form.change('hdPath', DEFAULT_HD_PATH);
57− }
58− }, []);
59−
60− const onSubmit = async (values: typeof initialValues) => {
25+ const onSubmit = async () => {
61− await authenticate({ hdPath: values.hdPath });
26+ await authenticate();
62 return;
27 return;
63 };
28 };
64
29
@@ -100,33 +65,11 @@ const WalletConnectLogin = ({ className, goHome }) => {
100 </Grid.Item>
65 </Grid.Item>
101 )}
66 )}
102
67
103− <BridgeForm
104− validate={validate}
105− onSubmit={onSubmit}
106− onValues={onValues}
107− afterSubmit={goHome}
68+ <BridgeForm onSubmit={onSubmit} afterSubmit={goHome}>
108− initialValues={initialValues}>
109 {({ handleSubmit, submitting }) => (
69 {({ handleSubmit, submitting }) => (
110 <>
70 <>
111 {isConnected() ? (
71 {isConnected() ? (
112 <>
72 <>
113− <Grid.Item
114− full
115− as={CheckboxInput}
116− className="mv3"
117− name="useCustomPath"
118− label="Custom HD Path"
119− />
120−
121− <Condition when="useCustomPath" is={true}>
122− <Grid.Item
123− full
124− as={HdPathInput}
125− name="hdPath"
126− label="HD Path"
127− />
128− </Condition>
129−
130 <Grid.Item full as={FormError} />
73 <Grid.Item full as={FormError} />
131
74
132 <Grid.Item
75 <Grid.Item