All files / src/components/elements DidSearchWithMessagingInfo.tsx

0% Statements 0/9
0% Branches 0/6
0% Functions 0/3
0% Lines 0/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52                                                                                                       
import { useState } from "react";
import { Flash, Flex, Text } from "rimble-ui";
import { Warning } from "@rimble/icons";
import { DidSearch, DidSearchProps } from "./DidSearch";
import { SelectedDid } from "../../types";
import { colors } from "../../themes";
 
export interface DidSearchWithMessagingInfoProps extends DidSearchProps {
  messagingUnsupportedText?: string;
  supportsMessaging?: boolean;
  setSupportsMessaging(supported: boolean): void;
}
 
export const DidSearchWithMessagingInfo: React.FunctionComponent<DidSearchWithMessagingInfoProps> = (props) => {
  const { messagingUnsupportedText, onChange, supportsMessaging, setSupportsMessaging } = props;
 
  const [didSearchBlurred, setDidSearchBlurred] = useState(false);
  const [value, setValue] = useState<SelectedDid | undefined>();
 
  return (
    <>
      <DidSearch
        {...{
          ...props,
          onChange: (val) => {
            setValue(val);
            setSupportsMessaging(!!val.messagingSupported);
            onChange(val);
          },
          onBlur: () => setDidSearchBlurred(true),
        }}
      />
      {didSearchBlurred && value && !supportsMessaging && (
        <Flash my={3} variant="warning">
          <Flex>
            <Warning color={colors.warning.dark} />
            <Text ml={2} fontSize={1}>
              {messagingUnsupportedText || (
                <>
                  The subject DID you selected does not support DIDComm messaging, so they cannot seamlessly receive the
                  VC you are issuing. You may still issue the VC here, and on the next screen can share it with the
                  subject via email, link, or QR code.
                </>
              )}
            </Text>
          </Flex>
        </Flash>
      )}
    </>
  );
};