diff --git a/playground/nextjs-app-router/onchainkit/package.json b/playground/nextjs-app-router/onchainkit/package.json index 7b2240d0a8..6e02ce9867 100644 --- a/playground/nextjs-app-router/onchainkit/package.json +++ b/playground/nextjs-app-router/onchainkit/package.json @@ -152,22 +152,22 @@ "default": "./esm/identity/index.js" }, "./nft": { - "types": "./esm/ui/react/nft/index.d.ts", - "module": "./esm/ui/react/nft/index.js", - "import": "./esm/ui/react/nft/index.js", - "default": "./esm/ui/react/nft/index.js" + "types": "./esm/nft/index.d.ts", + "module": "./esm/nft/index.js", + "import": "./esm/nft/index.js", + "default": "./esm/nft/index.js" }, "./nft/view": { - "types": "./esm/ui/react/nft/view/index.d.ts", - "module": "./esm/ui/react/nft/view/index.js", - "import": "./esm/ui/react/nft/view/index.js", - "default": "./esm/ui/react/nft/view/index.js" + "types": "./esm/nft/components/view/index.d.ts", + "module": "./esm/nft/components/view/index.js", + "import": "./esm/nft/components/view/index.js", + "default": "./esm/nft/components/view/index.js" }, "./nft/mint": { - "types": "./esm/ui/react/nft/mint/index.d.ts", - "module": "./esm/ui/react/nft/mint/index.js", - "import": "./esm/ui/react/nft/mint/index.js", - "default": "./esm/ui/react/nft/mint/index.js" + "types": "./esm/nft/components/mint/index.d.ts", + "module": "./esm/nft/components/mint/index.js", + "import": "./esm/nft/components/mint/index.js", + "default": "./esm/nft/components/mint/index.js" }, "./send": { "types": "./esm/send/index.d.ts", diff --git a/src/core-react/internal/hooks/useExchangeRate.tsx b/src/core-react/internal/hooks/useExchangeRate.tsx deleted file mode 100644 index a5918e0e64..0000000000 --- a/src/core-react/internal/hooks/useExchangeRate.tsx +++ /dev/null @@ -1,56 +0,0 @@ -import { getSwapQuote } from '@/api'; -import { isApiError } from '@/core/utils/isApiResponseError'; -import type { Token } from '@/token'; -import { usdcToken } from '@/token/constants'; -import type { Dispatch, SetStateAction } from 'react'; - -type UseExchangeRateParams = { - token: Token; - selectedInputType: 'crypto' | 'fiat'; - setExchangeRate: Dispatch>; - setExchangeRateLoading: Dispatch>; -}; - -export async function useExchangeRate({ - token, - selectedInputType, - setExchangeRate, - setExchangeRateLoading, -}: UseExchangeRateParams) { - console.log('useing exchange rate hook'); - if (!token) { - return; - } - - if (token.address === usdcToken.address) { - setExchangeRate(1); - return; - } - - setExchangeRateLoading(true); - - const fromToken = selectedInputType === 'crypto' ? token : usdcToken; - const toToken = selectedInputType === 'crypto' ? usdcToken : token; - - try { - const response = await getSwapQuote({ - amount: '1', // hardcoded amount because we only need the exchange rate - from: fromToken, - to: toToken, - useAggregator: false, - }); - if (isApiError(response)) { - console.error('Error fetching exchange rate:', response.error); - return; - } - const rate = - selectedInputType === 'crypto' - ? 1 / Number(response.fromAmountUSD) - : Number(response.toAmount) / 10 ** response.to.decimals; - setExchangeRate(rate); - } catch (error) { - console.error('Uncaught error fetching exchange rate:', error); - } finally { - setExchangeRateLoading(false); - } -} diff --git a/src/internal/components/AmountInput/AmountInput.tsx b/src/internal/components/AmountInput/AmountInput.tsx index 501661b154..8f0ef5268c 100644 --- a/src/internal/components/AmountInput/AmountInput.tsx +++ b/src/internal/components/AmountInput/AmountInput.tsx @@ -1,10 +1,10 @@ -import { isValidAmount } from '@/core/utils/isValidAmount'; +import { CurrencyLabel } from '@/internal/components/AmountInput/CurrencyLabel'; import { TextInput } from '@/internal/components/TextInput'; -import { useCallback, useEffect, useRef } from 'react'; +import { useAmountInput } from '@/internal/hooks/useAmountInput'; +import { useInputResize } from '@/internal/hooks/useInputResize'; +import { isValidAmount } from '@/internal/utils/isValidAmount'; import { cn, text } from '@/styles/theme'; -import { useAmountInput } from '@/core-react/internal/hooks/useAmountInput'; -import { useInputResize } from '@/core-react/wallet/hooks/useInputResize'; -import { CurrencyLabel } from '@/internal/components/AmountInput/CurrencyLabel'; +import { useCallback, useEffect, useRef } from 'react'; type AmountInputProps = { asset: string; diff --git a/src/internal/components/AmountInput/AmountInputTypeSwitch.tsx b/src/internal/components/AmountInput/AmountInputTypeSwitch.tsx index ee0bb5ed10..db041cca7e 100644 --- a/src/internal/components/AmountInput/AmountInputTypeSwitch.tsx +++ b/src/internal/components/AmountInput/AmountInputTypeSwitch.tsx @@ -1,4 +1,4 @@ -import { formatFiatAmount } from '@/core/utils/formatFiatAmount'; +import { formatFiatAmount } from '@/internal/utils/formatFiatAmount'; import { useCallback, useMemo } from 'react'; import { useIcon } from '@/core-react/internal/hooks/useIcon'; import { Skeleton } from '@/internal/components/Skeleton'; diff --git a/src/wallet/hooks/useInputResize.test.ts b/src/internal/hooks/useInputResize.test.ts similarity index 100% rename from src/wallet/hooks/useInputResize.test.ts rename to src/internal/hooks/useInputResize.test.ts diff --git a/src/wallet/hooks/useInputResize.ts b/src/internal/hooks/useInputResize.ts similarity index 100% rename from src/wallet/hooks/useInputResize.ts rename to src/internal/hooks/useInputResize.ts diff --git a/src/wallet/components/WalletAdvancedSend/components/SendProvider.tsx b/src/wallet/components/WalletAdvancedSend/components/SendProvider.tsx index abac7ec81e..2f1ece057a 100644 --- a/src/wallet/components/WalletAdvancedSend/components/SendProvider.tsx +++ b/src/wallet/components/WalletAdvancedSend/components/SendProvider.tsx @@ -16,7 +16,7 @@ import { useLifecycleStatus } from '@/core-react/internal/hooks/useLifecycleStat import type { Token } from '@/token'; import { useWalletContext } from '@/wallet/components/WalletProvider'; import { useWalletAdvancedContext } from '@/wallet/components/WalletAdvancedProvider'; -import { useExchangeRate } from '@/core-react/internal/hooks/useExchangeRate'; +import { useExchangeRate } from '@/internal/hooks/useExchangeRate'; type SendContextType = { lifecycleStatus: LifecycleStatus; diff --git a/src/wallet/components/WalletAdvancedTransactionActions.test.tsx b/src/wallet/components/WalletAdvancedTransactionActions.test.tsx index e7e6d28caa..63320526e4 100644 --- a/src/wallet/components/WalletAdvancedTransactionActions.test.tsx +++ b/src/wallet/components/WalletAdvancedTransactionActions.test.tsx @@ -131,16 +131,20 @@ describe('WalletAdvancedTransactionActons', () => { expect(window.open).not.toHaveBeenCalled(); }); - it('opens the send page when the send button is clicked', () => { + it('sets showSend to true when the send button is clicked', () => { + const setShowSendMock = vi.fn(); + + mockUseWalletAdvancedContext.mockReturnValue({ + ...defaultMockUseWalletAdvancedContext, + setShowSend: setShowSendMock, + }); + render(); const sendButton = screen.getByRole('button', { name: 'Send' }); fireEvent.click(sendButton); - expect(window.open).toHaveBeenCalledWith( - 'https://wallet.coinbase.com', - '_blank', - ); + expect(setShowSendMock).toHaveBeenCalledWith(true); }); it('sets showSwap to true when the swap button is clicked', () => {