on master help sign in
Merge pull request #995 from urbit/t/994-mnemonic-passphrase-api-perf

perf: debounce Mnemonic login eager api call

commit2060219bbf69ecceb1d86c5b2527036c0a048df0 authortomholford <16504501+tomholford@users.noreply.github.com> dateFri 11 Mar 2022, 09:12 (5 years ago) parentd11f711af1b097
1 file changed+26−21
src/views/Login/Mnemonic.tsx+26−21
src/views/Login/Mnemonic.tsx+26−21
@@ -6,7 +6,7 @@ import { Grid } from 'indigo-react';
66import { useWallet } from 'store/wallet';
77
88import { walletFromMnemonic } from 'lib/wallet';
9−import { DEFAULT_HD_PATH, WALLET_TYPES } from 'lib/constants';
9+import { DEFAULT_HD_PATH, ONE_SECOND, WALLET_TYPES } from 'lib/constants';
1010import useLoginView from 'lib/useLoginView';
1111import { MnemonicInput, HdPathInput, PassphraseInput } from 'form/Inputs';
1212import {
@@ -25,6 +25,7 @@ import HeaderPane from 'components/L2/Window/HeaderPane';
2525import BodyPane from 'components/L2/Window/BodyPane';
2626import AdvancedOptions from 'components/L2/Headers/AdvancedOptions';
2727import { Row } from '@tlon/indigo-react';
28+import { debounce } from 'lodash';
2829
2930interface MnemonicProps {
3031 className?: string;
@@ -52,26 +53,30 @@ export default function Mnemonic({ className, goHome }: MnemonicProps) {
5253 }, [skipValidation]);
5354
5455 // when the properties change, re-derive wallet and set global state
55− const onValues = useCallback(
56− ({ valid, values }) => {
57− if (valid) {
58− setWalletHdPath(values.hdpath);
59− setAuthMnemonic(Just(values.mnemonic));
60− setWallet(
61− walletFromMnemonic(
62− values.mnemonic,
63− values.hdpath,
64− values.passphrase,
65− skipValidation
66− )
67− );
68− } else {
69− setAuthMnemonic(Nothing());
70− setWallet(Nothing());
71− }
72− },
73− [setAuthMnemonic, setWallet, setWalletHdPath, skipValidation]
74− );
56+ const debouncedOnValues = debounce(({ valid, values }) => {
57+ if (valid) {
58+ setWalletHdPath(values.hdpath);
59+ setAuthMnemonic(Just(values.mnemonic));
60+ setWallet(
61+ walletFromMnemonic(
62+ values.mnemonic,
63+ values.hdpath,
64+ values.passphrase,
65+ skipValidation
66+ )
67+ );
68+ } else {
69+ setAuthMnemonic(Nothing());
70+ setWallet(Nothing());
71+ }
72+ }, ONE_SECOND);
73+
74+ const onValues = useCallback(debouncedOnValues, [
75+ setAuthMnemonic,
76+ setWallet,
77+ setWalletHdPath,
78+ skipValidation,
79+ ]);
7580
7681 const initialValues = {
7782 hdpath: DEFAULT_HD_PATH,