2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-06-26 00:08:58 +00:00
|
|
|
import * as React from 'react';
|
2020-09-12 00:46:52 +00:00
|
|
|
import { action } from '@storybook/addon-actions';
|
2023-10-11 19:06:43 +00:00
|
|
|
import type { Meta } from '@storybook/react';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { PropsType } from './SafetyNumberViewer';
|
|
|
|
import { SafetyNumberViewer } from './SafetyNumberViewer';
|
2021-09-18 00:30:08 +00:00
|
|
|
import { setupI18n } from '../util/setupI18n';
|
2020-06-26 00:08:58 +00:00
|
|
|
import enMessages from '../../_locales/en/messages.json';
|
2021-08-06 00:17:05 +00:00
|
|
|
import { getDefaultConversation } from '../test-both/helpers/getDefaultConversation';
|
2020-06-26 00:08:58 +00:00
|
|
|
|
2023-07-13 19:06:42 +00:00
|
|
|
function generateQRData() {
|
|
|
|
const data = new Uint8Array(128);
|
|
|
|
for (let i = 0; i < data.length; i += 1) {
|
|
|
|
data[i] = Math.floor(Math.random() * 256);
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
function generateNumberBlocks() {
|
|
|
|
const result = new Array<string>();
|
|
|
|
for (let i = 0; i < 12; i += 1) {
|
|
|
|
let digits = '';
|
|
|
|
for (let j = 0; j < 5; j += 1) {
|
|
|
|
digits += Math.floor(Math.random() * 10);
|
|
|
|
}
|
|
|
|
result.push(digits);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-06-26 00:08:58 +00:00
|
|
|
const i18n = setupI18n('en', enMessages);
|
|
|
|
|
2021-08-06 00:17:05 +00:00
|
|
|
const contactWithAllData = getDefaultConversation({
|
2020-07-29 23:20:05 +00:00
|
|
|
title: 'Summer Smith',
|
2020-07-24 01:35:32 +00:00
|
|
|
name: 'Summer Smith',
|
|
|
|
phoneNumber: '(305) 123-4567',
|
|
|
|
isVerified: true,
|
2021-08-06 00:17:05 +00:00
|
|
|
});
|
2020-07-24 01:35:32 +00:00
|
|
|
|
2021-08-06 00:17:05 +00:00
|
|
|
const contactWithJustProfile = getDefaultConversation({
|
2024-07-11 19:44:09 +00:00
|
|
|
avatarUrl: undefined,
|
2020-07-29 23:20:05 +00:00
|
|
|
title: '-*Smartest Dude*-',
|
2020-07-24 01:35:32 +00:00
|
|
|
profileName: '-*Smartest Dude*-',
|
|
|
|
name: undefined,
|
|
|
|
phoneNumber: '(305) 123-4567',
|
2021-08-06 00:17:05 +00:00
|
|
|
});
|
2020-07-24 01:35:32 +00:00
|
|
|
|
2021-08-06 00:17:05 +00:00
|
|
|
const contactWithJustNumber = getDefaultConversation({
|
2024-07-11 19:44:09 +00:00
|
|
|
avatarUrl: undefined,
|
2020-07-24 01:35:32 +00:00
|
|
|
profileName: undefined,
|
|
|
|
name: undefined,
|
2020-07-29 23:20:05 +00:00
|
|
|
title: '(305) 123-4567',
|
2020-07-24 01:35:32 +00:00
|
|
|
phoneNumber: '(305) 123-4567',
|
2021-08-06 00:17:05 +00:00
|
|
|
});
|
2020-07-24 01:35:32 +00:00
|
|
|
|
2021-08-06 00:17:05 +00:00
|
|
|
const contactWithNothing = getDefaultConversation({
|
2020-07-24 01:35:32 +00:00
|
|
|
id: 'some-guid',
|
2024-07-11 19:44:09 +00:00
|
|
|
avatarUrl: undefined,
|
2020-07-24 01:35:32 +00:00
|
|
|
profileName: undefined,
|
2020-07-29 23:20:05 +00:00
|
|
|
title: 'Unknown contact',
|
2020-07-24 01:35:32 +00:00
|
|
|
name: undefined,
|
|
|
|
phoneNumber: undefined,
|
2021-08-06 00:17:05 +00:00
|
|
|
});
|
2020-07-24 01:35:32 +00:00
|
|
|
|
2020-10-07 00:49:22 +00:00
|
|
|
const createProps = (overrideProps: Partial<PropsType> = {}): PropsType => ({
|
|
|
|
contact: overrideProps.contact || contactWithAllData,
|
2020-06-26 00:08:58 +00:00
|
|
|
generateSafetyNumber: action('generate-safety-number'),
|
|
|
|
i18n,
|
2023-11-01 22:55:30 +00:00
|
|
|
safetyNumber:
|
|
|
|
'safetyNumber' in overrideProps
|
2024-03-14 19:35:03 +00:00
|
|
|
? overrideProps.safetyNumber ?? null
|
2023-11-01 22:55:30 +00:00
|
|
|
: {
|
|
|
|
numberBlocks: generateNumberBlocks(),
|
|
|
|
qrData: generateQRData(),
|
|
|
|
},
|
2020-06-26 00:08:58 +00:00
|
|
|
toggleVerified: action('toggle-verified'),
|
2023-10-11 19:06:43 +00:00
|
|
|
verificationDisabled:
|
2020-10-07 00:49:22 +00:00
|
|
|
overrideProps.verificationDisabled !== undefined
|
|
|
|
? overrideProps.verificationDisabled
|
2023-10-11 19:06:43 +00:00
|
|
|
: false,
|
2022-03-02 18:24:28 +00:00
|
|
|
onClose: action('onClose'),
|
2020-10-07 00:49:22 +00:00
|
|
|
});
|
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
export default {
|
|
|
|
title: 'Components/SafetyNumberViewer',
|
2023-10-11 19:06:43 +00:00
|
|
|
} satisfies Meta<PropsType>;
|
2020-10-07 00:49:22 +00:00
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function SafetyNumber(): JSX.Element {
|
2020-10-07 00:49:22 +00:00
|
|
|
return <SafetyNumberViewer {...createProps({})} />;
|
2022-11-18 00:45:19 +00:00
|
|
|
}
|
2020-10-07 00:49:22 +00:00
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function SafetyNumberNotVerified(): JSX.Element {
|
2020-10-07 00:49:22 +00:00
|
|
|
return (
|
|
|
|
<SafetyNumberViewer
|
|
|
|
{...createProps({
|
|
|
|
contact: {
|
|
|
|
...contactWithAllData,
|
|
|
|
isVerified: false,
|
|
|
|
},
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
2022-11-18 00:45:19 +00:00
|
|
|
}
|
2022-06-07 00:48:02 +00:00
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function VerificationDisabled(): JSX.Element {
|
2020-10-07 00:49:22 +00:00
|
|
|
return (
|
|
|
|
<SafetyNumberViewer
|
|
|
|
{...createProps({
|
|
|
|
verificationDisabled: true,
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
2022-11-18 00:45:19 +00:00
|
|
|
}
|
2020-10-07 00:49:22 +00:00
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function SafetyNumberDialogClose(): JSX.Element {
|
2020-10-07 00:49:22 +00:00
|
|
|
return (
|
|
|
|
<SafetyNumberViewer
|
|
|
|
{...createProps({
|
|
|
|
onClose: action('close'),
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
2022-11-18 00:45:19 +00:00
|
|
|
}
|
2022-06-07 00:48:02 +00:00
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function JustProfileAndNumber(): JSX.Element {
|
2020-10-07 00:49:22 +00:00
|
|
|
return (
|
|
|
|
<SafetyNumberViewer
|
|
|
|
{...createProps({
|
|
|
|
contact: contactWithJustProfile,
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
2022-11-18 00:45:19 +00:00
|
|
|
}
|
2022-06-07 00:48:02 +00:00
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function JustNumber(): JSX.Element {
|
2020-10-07 00:49:22 +00:00
|
|
|
return (
|
|
|
|
<SafetyNumberViewer
|
|
|
|
{...createProps({
|
|
|
|
contact: contactWithJustNumber,
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
2022-11-18 00:45:19 +00:00
|
|
|
}
|
2020-10-07 00:49:22 +00:00
|
|
|
|
2023-11-01 22:55:30 +00:00
|
|
|
export function NoACICannotVerify(): JSX.Element {
|
2020-10-07 00:49:22 +00:00
|
|
|
return (
|
|
|
|
<SafetyNumberViewer
|
|
|
|
{...createProps({
|
|
|
|
contact: contactWithNothing,
|
2023-11-01 22:55:30 +00:00
|
|
|
safetyNumber: undefined,
|
2020-10-07 00:49:22 +00:00
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
2022-11-18 00:45:19 +00:00
|
|
|
}
|