-
Notifications
You must be signed in to change notification settings - Fork 4
feat(token-input): add Sepolia support with AAVE faucet tokens #462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f31ea12
feat: add Sepolia to TokenInput demo network selector
gabitoesmiapodo c7c43b1
feat(token-select): add Sepolia support with AAVE faucet tokens and g…
gabitoesmiapodo c5d24f7
fix(token-select): address code review findings for Sepolia support
gabitoesmiapodo 4325072
feat(token-input): default to multi token mode in demo
gabitoesmiapodo 44fb397
fix(token-select): fix CloseButton layout and children render position
gabitoesmiapodo 06104b6
fix(token-input): bind native balance client to selected token chain
gabitoesmiapodo 9baf5fa
fix(token-select): map LI.FI native address to configured sentinel
gabitoesmiapodo 0bc38ab
fix(token-input): drive USD "N/A" label from active chain, not token …
gabitoesmiapodo fb2660f
refactor: simplify token input and balance code
gabitoesmiapodo 3cad9a9
fix(token-input): guard native balance query when wallet is disconnected
gabitoesmiapodo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
src/components/sharedComponents/TokenInput/useTokenInput.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| import { QueryClient, QueryClientProvider } from '@tanstack/react-query' | ||
| import { act, renderHook, waitFor } from '@testing-library/react' | ||
| import { createElement, type ReactNode } from 'react' | ||
| import { zeroAddress } from 'viem' | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
| import type { Token } from '@/src/types/token' | ||
| import { useTokenInput } from './useTokenInput' | ||
|
|
||
| const walletAddress = '0x71C7656EC7ab88b098defB751B7401B5f6d8976F' as const | ||
|
|
||
| const mockUseAccount = vi.fn() | ||
| const mockUsePublicClient = vi.fn() | ||
| const mockGetBalance = vi.fn() | ||
|
|
||
| vi.mock('wagmi', () => ({ | ||
| useAccount: () => mockUseAccount(), | ||
| usePublicClient: (args: { chainId?: number } = {}) => { | ||
| mockUsePublicClient(args) | ||
| return { getBalance: mockGetBalance } | ||
| }, | ||
| })) | ||
|
|
||
| vi.mock('@/src/hooks/useErc20Balance', () => ({ | ||
| useErc20Balance: () => ({ balance: undefined, balanceError: null, isLoadingBalance: false }), | ||
| })) | ||
|
|
||
| vi.mock('@/src/env', () => ({ | ||
| env: { PUBLIC_NATIVE_TOKEN_ADDRESS: zeroAddress.toLowerCase() }, | ||
| })) | ||
|
|
||
| const mainnetUsdc: Token = { | ||
| address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', | ||
| chainId: 1, | ||
| decimals: 6, | ||
| name: 'USD Coin', | ||
| symbol: 'USDC', | ||
| } | ||
|
|
||
| const sepoliaEth: Token = { | ||
| address: zeroAddress, | ||
| chainId: 11155111, | ||
| decimals: 18, | ||
| name: 'Sepolia Ether', | ||
| symbol: 'ETH', | ||
| } | ||
|
|
||
| const wrapper = ({ children }: { children: ReactNode }) => | ||
| createElement( | ||
| QueryClientProvider, | ||
| { client: new QueryClient({ defaultOptions: { queries: { retry: false } } }) }, | ||
| children, | ||
| ) | ||
|
|
||
| describe('useTokenInput', () => { | ||
| beforeEach(() => { | ||
| mockUseAccount.mockReturnValue({ address: walletAddress }) | ||
| mockUsePublicClient.mockClear() | ||
| mockGetBalance.mockReset() | ||
| }) | ||
|
|
||
| it('rebinds the native public client to the selected token chain when the user switches chains', async () => { | ||
| mockGetBalance.mockResolvedValue(42n) | ||
|
|
||
| const { result } = renderHook(() => useTokenInput(mainnetUsdc), { wrapper }) | ||
|
|
||
| act(() => { | ||
| result.current.setTokenSelected(sepoliaEth) | ||
| }) | ||
|
|
||
| await waitFor(() => | ||
| expect(mockUsePublicClient).toHaveBeenLastCalledWith({ chainId: sepoliaEth.chainId }), | ||
| ) | ||
| await waitFor(() => expect(result.current.balance).toBe(42n)) | ||
| }) | ||
|
|
||
| it('binds the native public client to the selected token chain when no initial token is given', async () => { | ||
| mockGetBalance.mockResolvedValue(7n) | ||
|
|
||
| const { result } = renderHook(() => useTokenInput(), { wrapper }) | ||
|
|
||
| act(() => { | ||
| result.current.setTokenSelected(sepoliaEth) | ||
| }) | ||
|
|
||
| await waitFor(() => | ||
| expect(mockUsePublicClient).toHaveBeenLastCalledWith({ chainId: sepoliaEth.chainId }), | ||
| ) | ||
| await waitFor(() => expect(result.current.balance).toBe(7n)) | ||
| }) | ||
|
|
||
| it('does not fetch native balance when wallet is disconnected', () => { | ||
| mockUseAccount.mockReturnValue({ address: undefined }) | ||
|
|
||
| const { result } = renderHook(() => useTokenInput(sepoliaEth), { wrapper }) | ||
|
|
||
| expect(result.current.balance).toBeUndefined() | ||
| expect(result.current.balanceError).toBeNull() | ||
| expect(result.current.isLoadingBalance).toBe(false) | ||
| expect(mockGetBalance).not.toHaveBeenCalled() | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/components/sharedComponents/TokenSelect/List/BalanceLoading.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { Flex, type FlexProps, Skeleton } from '@chakra-ui/react' | ||
| import type { FC } from 'react' | ||
|
|
||
| /** | ||
| * Skeleton placeholder for token balance and USD value, shown while data is loading. | ||
| */ | ||
| const BalanceLoading: FC<FlexProps> = ({ ...restProps }) => ( | ||
| <Flex | ||
| alignItems="flex-end" | ||
| display="flex" | ||
| flexDirection="column" | ||
| rowGap={1} | ||
| {...restProps} | ||
| > | ||
| <Skeleton | ||
| height="19px" | ||
| width="50px" | ||
| /> | ||
| <Skeleton | ||
| height="14px" | ||
| width="50px" | ||
| /> | ||
| </Flex> | ||
| ) | ||
|
|
||
| export default BalanceLoading |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.