• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

input-output-hk / lace / 9413237952

08 Feb 2024 01:46PM UTC coverage: 52.934% (-0.9%) from 53.839%
9413237952

push

github

f98d1b
rhyslbw
chore: bump version

1989 of 4673 branches covered (42.56%)

Branch coverage included in aggregate %.

4487 of 7561 relevant lines covered (59.34%)

56.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

32.65
/apps/browser-extension-wallet/src/features/dapp/components/SignData.tsx
1
import React, { useCallback, useState, useMemo } from 'react';
24✔
2
import { Spin } from 'antd';
24✔
3
import { Wallet } from '@lace/cardano';
24✔
4
import { useTranslation } from 'react-i18next';
24✔
5
import { Button, inputProps, Password } from '@lace/common';
24✔
6
import { useWalletStore } from '@stores';
24✔
7
import { useRedirection, useWalletManager } from '@hooks';
24✔
8
import { dAppRoutePaths } from '@routes';
24✔
9
import { Layout } from './Layout';
24✔
10
import { useViewsFlowContext } from '@providers/ViewFlowProvider';
24✔
11
import styles from './SignTransaction.module.scss';
24✔
12
import { exposeApi, RemoteApiPropertyType } from '@cardano-sdk/web-extension';
24✔
13
import { DAPP_CHANNELS } from '@src/utils/constants';
24✔
14
import { runtime } from 'webextension-polyfill';
24✔
15
import { UserPromptService } from '@lib/scripts/background/services';
16
import { of } from 'rxjs';
24✔
17

18
export const SignData = (): React.ReactElement => {
24✔
19
  const { t } = useTranslation();
×
20
  const {
21
    utils: { setPreviousView }
22
  } = useViewsFlowContext();
×
23
  const redirectToSignFailure = useRedirection(dAppRoutePaths.dappTxSignFailure);
×
24
  const { executeWithPassword } = useWalletManager();
×
25
  const [isLoading, setIsLoading] = useState(false);
×
26
  const [password, setPassword] = useState<string>();
×
27
  const [validPassword, setValidPassword] = useState<boolean>();
×
28
  const { keyAgentData } = useWalletStore();
×
29

30
  const handleVerifyPass = useCallback(async () => {
×
31
    setIsLoading(true);
×
32
    try {
×
33
      const valid = await Wallet.validateWalletPassword(keyAgentData, password);
×
34
      setValidPassword(valid);
×
35
      if (!valid) {
×
36
        setIsLoading(false);
×
37
        return;
×
38
      }
39
      exposeApi<Pick<UserPromptService, 'allowSignData'>>(
×
40
        {
41
          api$: of({
42
            allowSignData(): Promise<boolean> {
43
              return Promise.resolve(valid);
×
44
            }
45
          }),
46
          baseChannel: DAPP_CHANNELS.userPrompt,
47
          properties: { allowSignData: RemoteApiPropertyType.MethodReturningPromise }
48
        },
49
        { logger: console, runtime }
50
      );
51
    } catch {
52
      redirectToSignFailure();
×
53
    } finally {
54
      setIsLoading(false);
×
55
    }
56
  }, [password, redirectToSignFailure, keyAgentData]);
57

58
  const onConfirm = useCallback(
×
59
    () => executeWithPassword(password, handleVerifyPass, false),
×
60
    [executeWithPassword, handleVerifyPass, password]
61
  );
62

63
  const handleChange: inputProps['onChange'] = ({ target: { value } }) => setPassword(value);
×
64

65
  const confirmIsDisabled = useMemo(() => {
×
66
    if (keyAgentData.__typename !== 'InMemory') return false;
×
67
    return !password;
×
68
  }, [keyAgentData.__typename, password]);
69

70
  return (
×
71
    <Layout title={undefined}>
72
      <div className={styles.passwordContainer}>
73
        <Spin spinning={isLoading}>
74
          <h5 className={styles.message}>
75
            {t('browserView.transaction.send.enterWalletPasswordToConfirmTransaction')}
76
          </h5>
77
          <Password
78
            onChange={handleChange}
79
            value={password}
80
            error={validPassword === false}
81
            errorMessage={t('browserView.transaction.send.error.invalidPassword')}
82
          />
83
        </Spin>
84
      </div>
85
      <div className={styles.actions}>
86
        <Button
87
          onClick={onConfirm}
88
          disabled={confirmIsDisabled || isLoading}
×
89
          className={styles.actionBtn}
90
          data-testid="sign-transaction-confirm"
91
        >
92
          {t('dapp.confirm.btn.confirm')}
93
        </Button>
94
        <Button
95
          onClick={setPreviousView}
96
          color="secondary"
97
          className={styles.actionBtn}
98
          data-testid="sign-transaction-cancel"
99
        >
100
          {t('dapp.confirm.btn.cancel')}
101
        </Button>
102
      </div>
103
    </Layout>
104
  );
105
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc