Skip to content

Commit 1435a4d

Browse files
authored
refactor: [LW-11802] enable strict null checks (#1536)
* chore: enable strict null checks in tsconfig * separate tags requiring co-signer and those which don't * enable strict null checks * update function return types to include nulls * refactor(nami): remove src director from tsconfig exclusions * refactor(core): make currentTimelineStep a required property of onboarding steps * refactor(core): update deep partial types for governance actions * add translation package to tsconfig references
1 parent b3b1d06 commit 1435a4d

File tree

137 files changed

+881
-636
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+881
-636
lines changed

apps/browser-extension-wallet/src/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"baseUrl": "../src",
77
"resolveJsonModule": true,
88
"noEmitOnError": false,
9+
"strictNullChecks": false,
910
"paths": {
1011
"@assets/*": ["assets/*"],
1112
"@components/*": ["components/*"],

apps/browser-extension-wallet/src/utils/format-number.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export const formatLocaleNumber = (value: string, decimalPlaces: number = DEFAUL
5454
* @param maxDecimals The maximum number of decimal places to include. Default is 0.
5555
* @returns The formatted number string.
5656
*/
57-
export const formatNumberForDisplay = (value: string, maxDecimals = 0): string => {
57+
export const formatNumberForDisplay = (value?: string, maxDecimals = 0): string => {
5858
if (!value) return '0';
5959
// Remove any character that is not a dot or a number
6060
const parsedStringValue = value.replace(/[^\d.]/g, '');
@@ -137,7 +137,7 @@ export const handleFormattedValueChange = (
137137
* @param decimals The desired decimal places (default = 2)
138138
* @returns The formatted value with the desired decimals and the unit as a string
139139
*/
140-
export const compactNumberWithUnit = (value: number | string, decimals = DEFAULT_DECIMALS): string => {
140+
export const compactNumberWithUnit = (value?: number | string, decimals = DEFAULT_DECIMALS): string => {
141141
const bigNumberValue = value ? new BigNumber(value) : new BigNumber(0);
142142

143143
if (bigNumberValue.isNaN()) return formatLocaleNumber('0', decimals);

apps/browser-extension-wallet/src/views/browser-view/features/send-transaction/components/Form/CoinInput/useSelectedCoins.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { MAX_NFT_TICKER_LENGTH, MAX_TOKEN_TICKER_LENGTH } from '../../../constan
2727

2828
interface InputFieldActionParams {
2929
id: string;
30-
value: string;
30+
value?: string;
3131
maxDecimals?: number;
3232
}
3333

@@ -176,10 +176,10 @@ export const useSelectedCoins = ({
176176
coinBalance,
177177
spendableCoin?.toString(),
178178
tokensUsed[cardanoCoin.id] || '0',
179-
assetInputItem?.value || '0'
179+
assetInputItem?.value ?? '0'
180180
);
181181
const fiatValue = Wallet.util.convertAdaToFiat({
182-
ada: assetInputItem?.value || '0',
182+
ada: assetInputItem?.value ?? '0',
183183
fiat: prices?.cardano?.price
184184
});
185185
return {

apps/browser-extension-wallet/src/views/browser-view/features/staking/components/StakingInfo/StakePoolInfo.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ export const StakePoolInfo = ({
1818
onClick?: () => void;
1919
popupView: boolean;
2020
}): React.ReactElement => {
21-
const title = name || ticker || '-';
22-
const subTitle: string | React.ReactElement = ticker || (
21+
const title = name ?? ticker ?? '-';
22+
const subTitle: string | React.ReactElement = ticker ?? (
2323
<Ellipsis className={styles.id} text={id} beforeEllipsis={6} afterEllipsis={8} />
2424
);
2525

apps/browser-extension-wallet/test/__mocks__/set-env-vars.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ process.env.USE_POSTHOG_ANALYTICS = 'true';
2020
process.env.USE_POSTHOG_ANALYTICS_FOR_OPTED_OUT = 'false';
2121
process.env.POSTHOG_HOST = 'https://e.lw.iog.io';
2222
process.env.POSTHOG_DEV_TOKEN = 'test-token';
23+
process.env.MIN_NUMBER_OF_COSIGNERS = '2';
24+
process.env.TWITTER_URL = 'TWITTER_URL';
25+
process.env.YOUTUBE_URL = 'YOUTUBE_URL';
26+
process.env.DISCORD_URL = 'DISCORD_URL';

packages/cardano/src/ui/components/StakePoolMetricsBrowser/StakePoolMetricsBrowser.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ import isNil from 'lodash/isNil';
33
import cn from 'classnames';
44
import styles from './StakePoolMetricsBrowser.module.scss';
55

6-
const formatNumericValue = (val: number | string, suffix: number | string): React.ReactElement => (
7-
<>
8-
{val ?? '-'} {!isNil(val) && <span className={styles.suffix}>{suffix}</span>}
9-
</>
10-
);
6+
const formatNumericValue = ({ value, unit }: { value?: number | string; unit: number | string }): React.ReactNode =>
7+
!isNil(value) ? (
8+
<>
9+
{value} <span className={styles.suffix}>{unit}</span>
10+
</>
11+
) : (
12+
'-'
13+
);
1114

1215
export interface StakePoolMetricsBrowserProps {
1316
data: {
@@ -27,7 +30,7 @@ export const StakePoolMetricsBrowser = ({ data, popupView }: StakePoolMetricsBro
2730
{t}
2831
</div>
2932
<div className={styles.statBody} data-testid={`${testId}-value`}>
30-
{unit ? formatNumericValue(value, unit) : value}
33+
{unit ? formatNumericValue({ value, unit }) : value}
3134
</div>
3235
</div>
3336
))}

packages/cardano/src/ui/components/StakePoolNameBrowser/StakePoolNameBrowser.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ export const StakePoolNameBrowser = ({
3232
isOversaturated,
3333
translations
3434
}: StakePoolNameBrowserProps): React.ReactElement => {
35-
const title = name || ticker || '-';
36-
const subTitle: string | React.ReactElement = ticker || (
37-
<Ellipsis className={styles.id} text={id} beforeEllipsis={6} afterEllipsis={8} />
35+
const title = name ?? ticker ?? '-';
36+
const subTitle: string | React.ReactElement = ticker ?? (
37+
<Ellipsis className={styles.id} text={id ?? ''} beforeEllipsis={6} afterEllipsis={8} />
3838
);
3939

4040
return (
@@ -48,13 +48,15 @@ export const StakePoolNameBrowser = ({
4848
<p className={styles.subTitle} data-testid="stake-pool-item-ticker">
4949
{subTitle}
5050
</p>
51-
<StatusLogo
52-
status={status}
53-
isDelegated={isDelegated}
54-
isOversaturated={isOversaturated}
55-
className={styles.statusLogo}
56-
translations={translations}
57-
/>
51+
{status && (
52+
<StatusLogo
53+
status={status}
54+
isDelegated={!!isDelegated}
55+
isOversaturated={isOversaturated}
56+
className={styles.statusLogo}
57+
translations={translations}
58+
/>
59+
)}
5860
</div>
5961
</div>
6062
</div>

packages/cardano/src/ui/components/StakePoolNameBrowser/__tests__/StakePoolNameBrowser.test.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@ import { StakePoolNameBrowser, StakePoolNameBrowserProps } from '../StakePoolNam
55
import '@testing-library/jest-dom';
66

77
describe('Testing StakePoolNameBrowser component', () => {
8+
const name = 'name';
9+
const ticker = 'ticker';
810
const props: StakePoolNameBrowserProps = {
9-
name: 'name',
10-
ticker: 'ticker',
11+
name,
12+
ticker,
1113
isDelegated: true,
1214
translations: { retiring: 'retiring', retired: 'retired', delegating: 'delegating', saturated: 'saturated' }
1315
};
1416
test('should display all stake pool metrics with icons', async () => {
1517
const { findByText, findByTestId } = render(<StakePoolNameBrowser {...props} />);
1618
const roiLabel = await findByTestId('stake-pool-item-logo');
17-
const nameValue = await findByText(props.name);
18-
const tickerValue = await findByText(props.ticker);
19+
const nameValue = await findByText(name);
20+
const tickerValue = await findByText(ticker);
1921

2022
expect(roiLabel).toBeVisible();
2123
expect(nameValue).toBeVisible();

packages/cardano/src/ui/components/StakePoolStatusLogo/StatusLogo.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ export const StatusLogo = ({
4444
if (status === 'retired' || status === 'retiring') {
4545
currentStatus = status;
4646
}
47-
const icon = statusIcons[currentStatus];
48-
const description = statusInfo[currentStatus];
47+
const icon = currentStatus ? statusIcons[currentStatus] : undefined;
48+
const description = currentStatus ? statusInfo[currentStatus] : undefined;
4949

5050
return (
5151
<>

packages/cardano/src/ui/components/Voting/CatalystConfirmationStep.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import styles from './Voting.module.scss';
33
import { Button } from '@lace/common';
44
import CatalystLogo from '../../assets/images/catalyst-logo.png';
5-
import Icon, { InfoCircleOutlined } from '@ant-design/icons';
5+
import { InfoCircleOutlined } from '@ant-design/icons';
66
import { TranslationsFor } from '@wallet/util/types';
77

88
export interface CatalystConfirmationStepProps {
@@ -52,7 +52,7 @@ export const CatalystConfirmationStep = ({
5252
<>
5353
<div className={styles.fee}>
5454
<p>
55-
{translations.totalFee} <Icon component={InfoCircleOutlined} />
55+
{translations.totalFee} <InfoCircleOutlined />
5656
</p>
5757
<b>{fee}</b>
5858
</div>

0 commit comments

Comments
 (0)