Skip to content

Commit

Permalink
fix(linter): remove all of any types
Browse files Browse the repository at this point in the history
  • Loading branch information
benaor committed Dec 29, 2024
1 parent d3671b1 commit da7b6cf
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC, useEffect, useRef, useState } from 'react';
import { FC, ReactNode, useEffect, useRef, useState } from 'react';

import ChevronRightIcon from '@mui/icons-material/ChevronRight';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
Expand All @@ -7,7 +7,7 @@ import { IconButton, Paper, Typography } from '@mui/material';
import { SECONDARY_GRAY } from '../../../constants';

export interface DataCardProps {
formattedData: string;
formattedData: ReactNode;
dataName?: string;
isExpanded: boolean;
setIsExpanded: (value: boolean) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export const Transaction: FC = () => {

const transaction = buildPayment(
{
...parseBaseParamsFromStoredData(fetchedData),
...parseBaseParamsFromStoredData(fetchedData as SendPaymentRequest),
amount: amount ?? '0',
destination: destination ?? '',
...(destinationTag && { destinationTag }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const useFetchFromSessionStorage = (key?: string) => {
const fetchData = async () => {
try {
if (key) {
const storedData = await loadFromChromeSessionStorage(key, true);
const storedData = await loadFromChromeSessionStorage<string>(key, true);
if (storedData) {
setFetchedData(JSON.parse(storedData));
}
Expand Down
7 changes: 4 additions & 3 deletions packages/extension/src/utils/baseParams.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
AnyBaseTransactionParamsNew,
getBaseFromParams,
initialBaseTransactionParams,
parseBaseParamsFromStoredData,
Expand Down Expand Up @@ -81,7 +82,7 @@ describe('parseBaseParamsFromURLParams', () => {

describe('getBaseFromParams', () => {
test('should get base transaction parameters from an object', () => {
const params = {
const params: AnyBaseTransactionParamsNew = {
fee: '10',
sequence: 1,
accountTxnID: '123',
Expand All @@ -100,7 +101,7 @@ describe('getBaseFromParams', () => {
});

test('should handle undefined parameters', () => {
const params = {};
const params: AnyBaseTransactionParamsNew = {};

const result = getBaseFromParams(params);

Expand All @@ -121,7 +122,7 @@ describe('getBaseFromParams', () => {

describe('parseBaseParamsFromStoredData', () => {
it('should parse all values correctly', () => {
const storedObject = {
const storedObject: AnyBaseTransactionParamsNew = {
fee: '12',
sequence: '2',
accountTxnID: 'abc123',
Expand Down
23 changes: 18 additions & 5 deletions packages/extension/src/utils/baseParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Memo, Signer } from '@gemwallet/constants';

import { parseMemos, parseSigners } from './parseParams';
import { checkFee } from './transaction';
import { DeepPartialExcept } from '../types';

export type BaseTransactionParamsNew = {
fee?: string;
Expand All @@ -18,6 +17,20 @@ export type BaseTransactionParamsNew = {
txnSignature?: string;
};

export type AnyBaseTransactionParamsNew = Partial<{
fee: string;
sequence: string | number;
accountTxnID: string;
lastLedgerSequence: string | number;
memos: Record<string, unknown>[] | unknown[] | Memo[];
networkID: string | number;
signers: Record<string, unknown>[] | unknown[] | Signer[];
sourceTag: string | number;
signingPubKey: string;
ticketSequence: string | number;
txnSignature: string;
}>;

export const parseBaseParamsFromURLParamsNew = (
urlParams: URLSearchParams
): BaseTransactionParamsNew => {
Expand Down Expand Up @@ -56,13 +69,13 @@ export const parseBaseParamsFromURLParamsNew = (
};

export const parseBaseParamsFromStoredData = (
storedObject: DeepPartialExcept<BaseTransactionParamsNew, 'memos' | 'signers'>
storedObject: AnyBaseTransactionParamsNew
): BaseTransactionParamsNew => {
const result: Partial<BaseTransactionParamsNew> = {};

const addParam = <T extends keyof BaseTransactionParamsNew>(
key: T,
value: BaseTransactionParamsNew[T] | null
value: BaseTransactionParamsNew[T]
) => {
if (value !== null && value !== undefined) {
result[key] = value;
Expand All @@ -77,7 +90,7 @@ export const parseBaseParamsFromStoredData = (
'lastLedgerSequence' in storedObject ? Number(storedObject.lastLedgerSequence) : undefined
);
addParam('memos', 'memos' in storedObject ? parseMemos(storedObject.memos) : undefined);
addParam('networkID', 'networkID' in storedObject ? storedObject.networkID : undefined);
addParam('networkID', 'networkID' in storedObject ? Number(storedObject.networkID) : undefined);
addParam('signers', 'signers' in storedObject ? parseSigners(storedObject.signers) : undefined);
addParam('sourceTag', 'sourceTag' in storedObject ? Number(storedObject.sourceTag) : undefined);
addParam(
Expand Down Expand Up @@ -141,7 +154,7 @@ export const parseBaseParamsFromURLParams = (urlParams: URLSearchParams): BaseTr
};
};

export const getBaseFromParams = (params: Partial<BaseTransactionParams>) => {
export const getBaseFromParams = (params: AnyBaseTransactionParamsNew) => {
return {
fee: params.fee || undefined,
sequence: params.sequence || undefined,
Expand Down
12 changes: 8 additions & 4 deletions packages/extension/src/utils/parseParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,15 @@ export const parseLimitAmount = (
return null;
};

export const parseMemos = (input: Memo[] | string | undefined): Memo[] | undefined => {
export const parseMemos = (
input: Memo[] | Record<string, unknown>[] | unknown[] | string | undefined
): Memo[] | undefined => {
if (!input) {
return;
}

if (typeof input === 'object' && Array.isArray(input)) {
return input;
return input as Memo[];
}

// For API version < 3.6
Expand All @@ -158,13 +160,15 @@ export const parseMemos = (input: Memo[] | string | undefined): Memo[] | undefin
return;
};

export const parseSigners = (input: Signer[] | string | undefined): Signer[] | undefined => {
export const parseSigners = (
input: Signer[] | Record<string, unknown>[] | unknown[] | string | undefined
): Signer[] | undefined => {
if (!input) {
return;
}

if (typeof input === 'object' && Array.isArray(input)) {
return input;
return input as Signer[];
}

// For API version < 3.6
Expand Down

0 comments on commit da7b6cf

Please sign in to comment.