-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: show chain select in companion app (#501)
* pull in chain select and add failing test * update ser-kit * shim process.env * make chainSelect semi-controllable * adjust spec
- Loading branch information
1 parent
0d80572
commit 4d1e29a
Showing
15 changed files
with
135 additions
and
47 deletions.
There are no files selected for viewing
This file contains 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,40 @@ | ||
import { invariant } from '@epic-web/invariant' | ||
import { CHAIN_NAME } from '@zodiac/chains' | ||
import { Select } from '@zodiac/ui' | ||
import type { ChainId } from 'ser-kit' | ||
|
||
export interface Props { | ||
value: ChainId | null | undefined | ||
onChange(chainId: ChainId): void | ||
} | ||
|
||
interface Option { | ||
value: ChainId | ||
label: string | ||
} | ||
|
||
const options = Object.entries(CHAIN_NAME).map(([chainId, name]) => ({ | ||
value: parseInt(chainId) as ChainId, | ||
label: name, | ||
})) | ||
|
||
export const ChainSelect = ({ value, onChange }: Props) => ( | ||
<Select | ||
label="Chain" | ||
isMulti={false} | ||
options={options} | ||
defaultValue={options.find((op) => op.value === value)} | ||
onChange={(option) => { | ||
invariant(option != null, 'Empty value selected as chain') | ||
|
||
onChange(option.value) | ||
}} | ||
formatOptionLabel={ChainOptionLabel as any} | ||
/> | ||
) | ||
|
||
const ChainOptionLabel = ({ value, label }: Option) => ( | ||
<div className="flex items-center gap-4 py-2"> | ||
<div className="pl-1">{label || `#${value}`}</div> | ||
</div> | ||
) |
This file contains 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 @@ | ||
export { ChainSelect } from './ChainSelect' |
This file contains 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 |
---|---|---|
@@ -1,21 +1,49 @@ | ||
import { render } from '@/test-utils' | ||
import { screen } from '@testing-library/react' | ||
import { createMockExecutionRoute } from '@zodiac/test-utils' | ||
import { CHAIN_NAME } from '@zodiac/chains' | ||
import { | ||
createMockExecutionRoute, | ||
randomPrefixedAddress, | ||
} from '@zodiac/test-utils' | ||
import type { ChainId } from 'ser-kit' | ||
import { describe, expect, it } from 'vitest' | ||
import EditRoute, { loader } from './edit-route' | ||
|
||
describe('Edit route', () => { | ||
it('shows the name of a route', async () => { | ||
const route = createMockExecutionRoute({ label: 'Test route' }) | ||
describe('Label', () => { | ||
it('shows the name of a route', async () => { | ||
const route = createMockExecutionRoute({ label: 'Test route' }) | ||
|
||
await render<typeof import('./edit-route')>( | ||
'/edit-route', | ||
{ path: '/edit-route', Component: EditRoute, loader }, | ||
{ searchParams: { route: btoa(JSON.stringify(route)) } }, | ||
) | ||
await render<typeof import('./edit-route')>( | ||
'/edit-route', | ||
{ path: '/edit-route', Component: EditRoute, loader }, | ||
{ searchParams: { route: btoa(JSON.stringify(route)) } }, | ||
) | ||
|
||
expect(screen.getByRole('textbox', { name: 'Label' })).toHaveValue( | ||
'Test route', | ||
) | ||
}) | ||
}) | ||
|
||
describe('Chain', () => { | ||
it.each(Object.entries(CHAIN_NAME))( | ||
'shows chainId "%s" as "%s"', | ||
async (chainId, name) => { | ||
const route = createMockExecutionRoute({ | ||
avatar: randomPrefixedAddress({ | ||
chainId: parseInt(chainId) as ChainId, | ||
}), | ||
}) | ||
|
||
await render<typeof import('./edit-route')>( | ||
'/edit-route', | ||
{ path: '/edit-route', Component: EditRoute, loader }, | ||
{ searchParams: { route: btoa(JSON.stringify(route)) } }, | ||
) | ||
|
||
expect(screen.getByRole('textbox', { name: 'Label' })).toHaveValue( | ||
'Test route', | ||
expect(screen.getByText(name)).toBeInTheDocument() | ||
}, | ||
) | ||
}) | ||
}) |
This file contains 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 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 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 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 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 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 |
---|---|---|
@@ -1 +1,10 @@ | ||
import '@testing-library/jest-dom/vitest' | ||
import { cleanup } from '@testing-library/react' | ||
import { sleepTillIdle } from '@zodiac/test-utils' | ||
import { afterEach } from 'vitest' | ||
|
||
afterEach(async () => { | ||
await sleepTillIdle() | ||
|
||
cleanup() | ||
}) |
This file contains 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 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 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 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.