Skip to content

Commit

Permalink
fix: decouple choose crypto asset components and add a new lint rule
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarkhanzadian committed Dec 5, 2023
1 parent eb96ac2 commit 7b11213
Show file tree
Hide file tree
Showing 42 changed files with 120 additions and 128 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ module.exports = {
'@typescript-eslint/no-unnecessary-condition': 'off',
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
'@typescript-eslint/array-type': ['error'],
'@typescript-eslint/method-signature-style': ['error', 'method'],
'no-warning-comments': [0],

'react-hooks/rules-of-hooks': 'error',
Expand Down
2 changes: 1 addition & 1 deletion src/app/common/hooks/use-copy-to-clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect, useRef, useState } from 'react';

interface UiClipboard {
value: string;
onCopy: () => void;
onCopy(): void;
hasCopied: boolean;
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/common/theme-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const getThemeLabel = (theme: UserSelectedTheme) => {
const ThemeContext = createContext<{
theme: ComputedTheme;
userSelectedTheme: UserSelectedTheme;
setUserSelectedTheme: (theme: UserSelectedTheme) => void;
setUserSelectedTheme(theme: UserSelectedTheme): void;
}>({
// These values are not used, but are set to satisfy the context's value type.
theme: 'light',
Expand Down
4 changes: 2 additions & 2 deletions src/app/common/validation/forms/fee-validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { btcToSat, moneyToBaseUnit, stxToMicroStx } from '../../money/unit-conve

interface FeeValidatorFactoryArgs {
availableBalance?: Money;
unitConverter: (unit: string | number | BigNumber) => BigNumber;
validator: (errorMsg: string) => NumberSchema<number | undefined, AnyObject>;
unitConverter(unit: string | number | BigNumber): BigNumber;
validator(errorMsg: string): NumberSchema<number | undefined, AnyObject>;
}
function feeValidatorFactory({
availableBalance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface BitcoinContractEntryPointLayoutProps {
usdBalance?: string;
isLoading?: boolean;
cursor?: 'pointer' | 'default';
onClick: () => void;
onClick(): void;
}
export function BitcoinContractEntryPointLayout(props: BitcoinContractEntryPointLayoutProps) {
const { balance, caption, icon, usdBalance, isLoading, cursor, onClick } = props;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface FeesListItemProps {
feeRate: number;
feeType: string;
isSelected?: boolean;
onClick: () => void;
onClick(): void;
}
export function FeesListItem({
arrivesIn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Brc20TokenAssetItemLayout } from './brc20-token-asset-item.layout';
interface Brc20TokenAssetItemProps {
token: Brc20Token;
isPressable?: boolean;
onClick?: () => void;
onClick?(): void;
}
export function Brc20TokenAssetItem({ token, isPressable, onClick }: Brc20TokenAssetItemProps) {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { AllTransferableCryptoAssetBalances } from '@shared/models/crypto-asset-balance.model';

import { CryptoCurrencyAssetItem } from '@app/components/crypto-assets/crypto-currency-asset/crypto-currency-asset-item';

import { CryptoCurrencyAssetIcon } from './crypto-currency-asset-icon';
import { FungibleTokenAssetItem } from './fungible-token-asset-item';

interface CryptoAssetListItemProps {
assetBalance: AllTransferableCryptoAssetBalances;
onClick(): void;
}
export function CryptoAssetListItem(props: CryptoAssetListItemProps) {
const { assetBalance, onClick } = props;
const { blockchain, type } = assetBalance;

switch (type) {
case 'crypto-currency':
return (
<CryptoCurrencyAssetItem
assetBalance={assetBalance}
icon={<CryptoCurrencyAssetIcon blockchain={blockchain} />}
isPressable
onClick={onClick}
/>
);
case 'fungible-token':
return <FungibleTokenAssetItem assetBalance={assetBalance} onClick={onClick} />;
default:
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ import { CryptoAssetListLayout } from './crypto-asset-list.layout';

interface CryptoAssetListProps {
cryptoAssetBalances: AllTransferableCryptoAssetBalances[];
onItemClick(cryptoAssetBalance: AllTransferableCryptoAssetBalances): void;
}
export function CryptoAssetList({ cryptoAssetBalances }: CryptoAssetListProps) {
export function CryptoAssetList({ cryptoAssetBalances, onItemClick }: CryptoAssetListProps) {
return (
<CryptoAssetListLayout>
{cryptoAssetBalances.map(assetBalance => (
<CryptoAssetListItem assetBalance={assetBalance} key={assetBalance.asset.name} />
{cryptoAssetBalances.map(cryptoAssetBalance => (
<CryptoAssetListItem
onClick={() => onItemClick(cryptoAssetBalance)}
assetBalance={cryptoAssetBalance}
key={cryptoAssetBalance.asset.name}
/>
))}
</CryptoAssetListLayout>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { StacksFungibleTokenAssetItem } from '@app/components/crypto-assets/stac

interface FungibleTokenAssetItemProps extends FlexProps {
assetBalance: StacksFungibleTokenAssetBalance;
onClick: () => void;
onClick(): void;
}
export function FungibleTokenAssetItem({ assetBalance, onClick }: FungibleTokenAssetItemProps) {
const { blockchain } = assetBalance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface CryptoCurrencyAssetItemProps {
additionalBalanceInfo?: React.ReactNode;
additionalUsdBalanceInfo?: React.ReactNode;
rightElement?: React.ReactNode;
onClick?: () => void;
onClick?(): void;
}
export function CryptoCurrencyAssetItem({
additionalBalanceInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface StacksFungibleTokenAssetItemLayoutProps extends FlexProps {
imageCanonicalUri?: string;
isPressable?: boolean;
title: string;
onClick?: () => void;
onClick?(): void;
}
export function StacksFungibleTokenAssetItemLayout({
avatar,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface StacksFungibleTokenAssetItemProps extends FlexProps {
assetBalance: StacksFungibleTokenAssetBalance;
unanchoredAssetBalance?: Money;
isPressable?: boolean;
onClick?: () => void;
onClick?(): void;
}
export function StacksFungibleTokenAssetItem({
assetBalance,
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/info-card/info-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export function InfoCardAssetValue({
interface InfoCardBtnProps {
icon: ReactNode;
label: string;
onClick: () => void;
onClick(): void;
}
export function InfoCardBtn({ icon, label, onClick }: InfoCardBtnProps) {
return (
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/loaders/bitcoin-account-loader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useCurrentNativeSegwitAccount } from '@app/store/accounts/blockchain/bi
import { useCurrentTaprootAccount } from '@app/store/accounts/blockchain/bitcoin/taproot-account.hooks';

interface CurrentBitcoinAccountLoaderProps {
children: (data: { nativeSegwit: BitcoinAccount; taproot: BitcoinAccount }) => React.ReactNode;
children(data: { nativeSegwit: BitcoinAccount; taproot: BitcoinAccount }): React.ReactNode;
}
export function CurrentBitcoinAccountLoader({ children }: CurrentBitcoinAccountLoaderProps) {
const nativeSegwit = useCurrentNativeSegwitAccount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ interface InputFieldProps extends FlexProps {
dataTestId?: string;
name: string;
value: string;
onPaste: (e: React.ClipboardEvent<HTMLInputElement>) => void;
onUpdateWord: (word: string) => void;
onPaste(e: React.ClipboardEvent<HTMLInputElement>): void;
onUpdateWord(word: string): void;
hasError?: boolean;
wordlist: string[];
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function Tabs({
}: {
tabs: Tabs[];
activeTab: number;
onTabClick: (index: number) => void;
onTabClick(index: number): void;
}) {
return (
<RTabs.Root
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useGetInscriptionsInfiniteQuery } from '@app/query/bitcoin/ordinals/ins
import { Inscription } from './inscription';

interface OrdinalsProps {
setIsLoadingMore: (isLoading: boolean) => void;
setIsLoadingMore(isLoading: boolean): void;
}
export function Ordinals({ setIsLoadingMore }: OrdinalsProps) {
const query = useGetInscriptionsInfiniteQuery();
Expand Down
29 changes: 10 additions & 19 deletions src/app/features/errors/error-boundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@ const changedArray = (a: unknown[] = [], b: unknown[] = []) =>

interface FallbackProps {
error: Error;
resetErrorBoundary: (...args: unknown[]) => void;
resetErrorBoundary(...args: unknown[]): void;
}

interface ErrorBoundaryPropsWithComponent {
onResetKeysChange?: (
prevResetKeys: unknown[] | undefined,
resetKeys: unknown[] | undefined
) => void;
onReset?: (...args: unknown[]) => void;
onError?: (error: Error, info: { componentStack: string }) => void;
onResetKeysChange?(prevResetKeys: unknown[] | undefined, resetKeys: unknown[] | undefined): void;
onReset?(...args: unknown[]): void;
onError?(error: Error, info: { componentStack: string }): void;
resetKeys?: unknown[];
fallback?: never;
FallbackComponent: ComponentType<FallbackProps>;
Expand All @@ -37,25 +34,19 @@ declare function FallbackRender(
): ReactElement<unknown, string | FunctionComponent | typeof Component> | null;

interface ErrorBoundaryPropsWithRender {
onResetKeysChange?: (
prevResetKeys: unknown[] | undefined,
resetKeys: unknown[] | undefined
) => void;
onReset?: (...args: unknown[]) => void;
onError?: (error: Error, info: { componentStack: string }) => void;
onResetKeysChange?(prevResetKeys: unknown[] | undefined, resetKeys: unknown[] | undefined): void;
onReset?(...args: unknown[]): void;
onError?(error: Error, info: { componentStack: string }): void;
resetKeys?: unknown[];
fallback?: never;
FallbackComponent?: never;
fallbackRender: typeof FallbackRender;
}

interface ErrorBoundaryPropsWithFallback {
onResetKeysChange?: (
prevResetKeys: unknown[] | undefined,
resetKeys: unknown[] | undefined
) => void;
onReset?: (...args: unknown[]) => void;
onError?: (error: Error, info: { componentStack: string }) => void;
onResetKeysChange?(prevResetKeys: unknown[] | undefined, resetKeys: unknown[] | undefined): void;
onReset?(...args: unknown[]): void;
onError?(error: Error, info: { componentStack: string }): void;
resetKeys?: unknown[];
fallback: ReactElement<unknown, string | FunctionComponent | typeof Component> | null;
FallbackComponent?: never;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { LeatherButton } from '@app/ui/components/button';

interface IncreaseFeeActionsProps {
isDisabled: boolean;
onCancel: () => void;
onCancel(): void;
}
export function IncreaseFeeActions(props: IncreaseFeeActionsProps) {
const { onCancel, isDisabled } = props;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Caption } from '@app/ui/components/typography/caption';

interface IncreaseFeeDrawerProps {
feeForm: React.JSX.Element;
onClose: () => void;
onClose(): void;
isShowing: boolean;
}
export function IncreaseFeeDrawer({ feeForm, onClose, isShowing }: IncreaseFeeDrawerProps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { LedgerRequestKeysContext, LedgerRequestKeysProvider } from './ledger-re
interface RequestKeysFlowProps {
context: LedgerRequestKeysContext;
isActionCancellableByUser: boolean;
onCancelConnectLedger?: () => void;
onCancelConnectLedger?(): void;
}
export function RequestKeysFlow({
context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ButtonProps, LeatherButton } from '@app/ui/components/button';

interface SettingsMenuItemProps extends ButtonProps {
color?: string;
onClick: (e: React.MouseEvent) => void;
onClick(e: React.MouseEvent): void;
children: ReactNode;
}
export function SettingsMenuItem({ color, onClick, children, ...props }: SettingsMenuItemProps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface ContractPreviewLayoutProps {
contractAddress: string;
contractName: string;
functionName?: string;
onClick?: () => void;
onClick?(): void;
}

export function ContractPreviewLayout({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useWalletType } from '@app/common/use-wallet-type';
import { SwitchAccountListItem } from './switch-account-list-item';

interface SwitchAccountListProps {
handleClose: () => void;
handleClose(): void;
currentAccountIndex: number;
addressesNum: number;
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/features/theme-drawer/theme-list-item-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CheckmarkIcon } from '@app/ui/components/icons/checkmark-icon';
interface ThemeListItemProps {
themeLabel: string;
isActive: boolean;
onThemeItemSelect: () => void;
onThemeItemSelect(): void;
}
export function ThemeListItemLayout({
themeLabel,
Expand Down
2 changes: 1 addition & 1 deletion src/app/features/theme-drawer/theme-list-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ThemeListItemLayout } from './theme-list-item-layout';

interface ThemeListItemProps {
theme: UserSelectedTheme;
onThemeSelected: (theme: UserSelectedTheme) => void;
onThemeSelected(theme: UserSelectedTheme): void;
isActive: boolean;
}
export function ThemeListItem({ theme, onThemeSelected, isActive }: ThemeListItemProps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function SignInContent({
onClick,
twentyFourWordMode,
}: {
onClick: () => void;
onClick(): void;
twentyFourWordMode: boolean;
}): React.JSX.Element {
return (
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/onboarding/sign-in/mnemonic-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { validationSchema } from '../../../components/secret-key/mnemonic-key/ut

interface MnemonicFormProps {
mnemonic: (string | null)[];
setMnemonic: (mnemonic: (string | null)[]) => void;
setMnemonic(mnemonic: (string | null)[]): void;
twentyFourWordMode: boolean;
}
export function MnemonicForm({ mnemonic, setMnemonic, twentyFourWordMode }: MnemonicFormProps) {
Expand Down
Loading

0 comments on commit 7b11213

Please sign in to comment.