From 2b133606993ce8289417d88510359479aebbc07d Mon Sep 17 00:00:00 2001 From: Leonardo Zizzamia Date: Thu, 13 Jun 2024 16:19:32 -0700 Subject: [PATCH] chore: polish (#552) --- .changeset/fuzzy-eggs-cross.md | 3 +- src/internal/text/TextBody.tsx | 4 +- src/internal/text/TextCaption.tsx | 4 +- src/internal/text/TextHeadline.tsx | 4 +- src/internal/text/TextLabel1.tsx | 4 +- src/internal/text/TextLabel2.tsx | 4 +- src/internal/text/TextLegal.tsx | 2 +- src/swap/components/Swap.tsx | 3 +- src/swap/components/SwapAmountInput.test.tsx | 2 +- src/swap/components/SwapAmountInput.tsx | 9 +- src/swap/components/SwapButton.tsx | 2 +- src/swap/core/isSwapError.test.ts | 33 +++++ src/swap/core/isSwapError.ts | 7 ++ src/swap/utils.test.ts | 121 ------------------- src/swap/utils.ts | 27 ----- src/utils/formatTokenAmount.test.ts | 38 ++++++ src/utils/formatTokenAmount.ts | 5 + src/utils/getRoundedAmount.test.ts | 17 +++ src/utils/getRoundedAmount.ts | 4 + src/utils/isValidAmount.test.ts | 31 +++++ src/utils/isValidAmount.ts | 8 ++ src/version.ts | 2 +- 22 files changed, 166 insertions(+), 168 deletions(-) create mode 100644 src/swap/core/isSwapError.test.ts create mode 100644 src/swap/core/isSwapError.ts delete mode 100644 src/swap/utils.test.ts delete mode 100644 src/swap/utils.ts create mode 100644 src/utils/formatTokenAmount.test.ts create mode 100644 src/utils/formatTokenAmount.ts create mode 100644 src/utils/getRoundedAmount.test.ts create mode 100644 src/utils/getRoundedAmount.ts create mode 100644 src/utils/isValidAmount.test.ts create mode 100644 src/utils/isValidAmount.ts diff --git a/.changeset/fuzzy-eggs-cross.md b/.changeset/fuzzy-eggs-cross.md index ce72b3d156..121cfcbac4 100644 --- a/.changeset/fuzzy-eggs-cross.md +++ b/.changeset/fuzzy-eggs-cross.md @@ -2,4 +2,5 @@ "@coinbase/onchainkit": patch --- -- **feat**: introduce Inter font-family and internal text components. By @kyhyco #506 +- **feat**: refactored and clean up internals. By @zizzamia #552 +- **feat**: introduce `Inter` font-family and internal text components. By @kyhyco #506 diff --git a/src/internal/text/TextBody.tsx b/src/internal/text/TextBody.tsx index 2339a3ddda..ed4869fb62 100644 --- a/src/internal/text/TextBody.tsx +++ b/src/internal/text/TextBody.tsx @@ -1,4 +1,4 @@ -import { ReactNode } from 'react'; +import type { ReactNode } from 'react'; type TextBodyReact = { children: ReactNode; @@ -6,7 +6,7 @@ type TextBodyReact = { export function TextBody({ children }: TextBodyReact) { return ( - + {children} ); diff --git a/src/internal/text/TextCaption.tsx b/src/internal/text/TextCaption.tsx index ace89ad40c..a9186ecd6b 100644 --- a/src/internal/text/TextCaption.tsx +++ b/src/internal/text/TextCaption.tsx @@ -1,4 +1,4 @@ -import { ReactNode } from 'react'; +import type { ReactNode } from 'react'; type TextCaptionReact = { children: ReactNode; @@ -7,6 +7,6 @@ type TextCaptionReact = { /* istanbul ignore next */ export function TextCaption({ children }: TextCaptionReact) { return ( - {children} + {children} ); } diff --git a/src/internal/text/TextHeadline.tsx b/src/internal/text/TextHeadline.tsx index c1a184578a..2d8191081c 100644 --- a/src/internal/text/TextHeadline.tsx +++ b/src/internal/text/TextHeadline.tsx @@ -1,4 +1,4 @@ -import { ReactNode } from 'react'; +import type { ReactNode } from 'react'; type TextHeadlineReact = { children: ReactNode; @@ -6,7 +6,7 @@ type TextHeadlineReact = { export function TextHeadline({ children }: TextHeadlineReact) { return ( - + {children} ); diff --git a/src/internal/text/TextLabel1.tsx b/src/internal/text/TextLabel1.tsx index 1f6e292e81..b9cf67f4dd 100644 --- a/src/internal/text/TextLabel1.tsx +++ b/src/internal/text/TextLabel1.tsx @@ -1,4 +1,4 @@ -import { ReactNode } from 'react'; +import type { ReactNode } from 'react'; type TextLabel1React = { children: ReactNode; @@ -7,7 +7,7 @@ type TextLabel1React = { /* istanbul ignore next */ export function TextLabel1({ children }: TextLabel1React) { return ( - + {children} ); diff --git a/src/internal/text/TextLabel2.tsx b/src/internal/text/TextLabel2.tsx index a52032edde..a3800a2d02 100644 --- a/src/internal/text/TextLabel2.tsx +++ b/src/internal/text/TextLabel2.tsx @@ -1,4 +1,4 @@ -import { ReactNode } from 'react'; +import type { ReactNode } from 'react'; type TextLabel2React = { children: ReactNode; @@ -7,7 +7,7 @@ type TextLabel2React = { /* istanbul ignore next */ export function TextLabel2({ children }: TextLabel2React) { return ( - + {children} ); diff --git a/src/internal/text/TextLegal.tsx b/src/internal/text/TextLegal.tsx index ee8d1126a7..08381a9d3b 100644 --- a/src/internal/text/TextLegal.tsx +++ b/src/internal/text/TextLegal.tsx @@ -1,4 +1,4 @@ -import { ReactNode } from 'react'; +import type { ReactNode } from 'react'; type TextLegalReact = { children: ReactNode; diff --git a/src/swap/components/Swap.tsx b/src/swap/components/Swap.tsx index dc33976b45..3a4119cc1d 100644 --- a/src/swap/components/Swap.tsx +++ b/src/swap/components/Swap.tsx @@ -2,7 +2,8 @@ import { useCallback, useMemo, useState } from 'react'; import { cn } from '../../utils/cn'; import { SwapContext } from '../context'; import { getSwapQuote } from '../core/getSwapQuote'; -import { formatTokenAmount, isSwapError } from '../utils'; +import { formatTokenAmount } from '../../utils/formatTokenAmount'; +import { isSwapError } from '../core/isSwapError'; import type { SwapError, SwapReact } from '../types'; import type { Token } from '../../token'; diff --git a/src/swap/components/SwapAmountInput.test.tsx b/src/swap/components/SwapAmountInput.test.tsx index 81975a66c1..72279cfd2e 100644 --- a/src/swap/components/SwapAmountInput.test.tsx +++ b/src/swap/components/SwapAmountInput.test.tsx @@ -6,7 +6,7 @@ import { render, screen, fireEvent } from '@testing-library/react'; import '@testing-library/jest-dom'; import { SwapAmountInput } from './SwapAmountInput'; import { SwapContext } from '../context'; -import { type Token } from '../../token'; +import type { Token } from '../../token'; import type { SwapContextType } from '../types'; import type { Address } from 'viem'; diff --git a/src/swap/components/SwapAmountInput.tsx b/src/swap/components/SwapAmountInput.tsx index 02b032692f..88ebba2bc1 100644 --- a/src/swap/components/SwapAmountInput.tsx +++ b/src/swap/components/SwapAmountInput.tsx @@ -1,6 +1,7 @@ import { useCallback, useContext, useEffect, useMemo } from 'react'; -import { getRoundedAmount, isValidAmount } from '../utils'; +import { isValidAmount } from '../../utils/isValidAmount'; +import { getRoundedAmount } from '../../utils/getRoundedAmount'; import { TokenChip } from '../../token'; import { cn } from '../../utils/cn'; import { SwapContext } from '../context'; @@ -83,7 +84,7 @@ export function SwapAmountInput({ label, token, type }: SwapAmountInputReact) {
{roundedBalance && ( - + )}
@@ -92,8 +93,8 @@ export function SwapAmountInput({ label, token, type }: SwapAmountInputReact) {