-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
1,032 additions
and
533 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
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { useEffect, useState } from 'react' | ||
|
||
import { useQueryParam } from './useQueryParam' | ||
|
||
interface BaseOptions<T> { | ||
paramName: string | ||
serialize: (value: T) => string | null | ||
deserialize: (value: string) => T | null | ||
} | ||
type WithFallback<T> = BaseOptions<T> & { | ||
fallback: T | ||
} | ||
|
||
type WithoutFallback<T> = BaseOptions<T> & { | ||
fallback: undefined | ||
} | ||
|
||
export function useSerializableQueryParam<T>( | ||
options: WithFallback<T>, | ||
): [NonNullable<T>, (newValue: NonNullable<T>) => void] | ||
export function useSerializableQueryParam<T>( | ||
options: WithoutFallback<T>, | ||
): [T | null, (newValue: T | null) => void] | ||
export function useSerializableQueryParam<T>({ | ||
paramName, | ||
fallback, | ||
serialize, | ||
deserialize, | ||
}: WithFallback<T> | WithFallback<T>) { | ||
const [currentParam, setCurrentParam] = useQueryParam(paramName) | ||
|
||
const actualFallback = fallback ?? null | ||
|
||
const param = currentParam | ||
? deserialize(currentParam) ?? actualFallback | ||
: actualFallback | ||
|
||
const [deserializedParam, setDeserializedParam] = useState(param) | ||
|
||
useEffect(() => { | ||
setCurrentParam(deserializedParam ? serialize(deserializedParam) : null) | ||
}, [deserializedParam, setCurrentParam, serialize]) | ||
|
||
return [deserializedParam, setDeserializedParam] as const | ||
} |
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,33 @@ | ||
import { | ||
isProtocolVersion, | ||
ProtocolVersion, | ||
} from '../constants/protocol-version' | ||
import { useSerializableQueryParam } from './useSerializableQueryParam' | ||
|
||
function serialize(version: ProtocolVersion): string | null { | ||
if (isProtocolVersion(version)) { | ||
return version | ||
} | ||
|
||
return null | ||
} | ||
|
||
function deserialize(version: string): ProtocolVersion | null { | ||
if (isProtocolVersion(version)) { | ||
return version | ||
} | ||
|
||
return null | ||
} | ||
|
||
export function useVersionQueryParam( | ||
paramName: string, | ||
fallback: ProtocolVersion, | ||
) { | ||
return useSerializableQueryParam({ | ||
paramName, | ||
fallback, | ||
serialize, | ||
deserialize, | ||
}) | ||
} |
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,43 @@ | ||
import { ChainId } from '@lz/libs' | ||
|
||
import { Dropdown, DropdownOption } from './Dropdown' | ||
import { toDropdownOption } from './protocol/utils' | ||
|
||
export function ChainDropdown(props: { | ||
chains: ChainId[] | ||
selectedChainId?: ChainId | ||
setSelectedChainId: (chain: ChainId) => void | ||
}) { | ||
function onDropdownSelect(option: DropdownOption): void { | ||
const chain = props.chains.find( | ||
(chain) => ChainId.getName(chain) === option.value, | ||
) | ||
|
||
if (!chain) { | ||
return | ||
} | ||
|
||
props.setSelectedChainId(chain) | ||
} | ||
|
||
const dropdownOptions = props.chains.map(toDropdownOption) | ||
|
||
const hasAnyChains = props.chains.length > 0 | ||
|
||
const nullableDefault = | ||
props.selectedChainId && hasAnyChains | ||
? { defaultValue: toDropdownOption(props.selectedChainId) } | ||
: {} | ||
|
||
if (!hasAnyChains) { | ||
return null | ||
} | ||
|
||
return ( | ||
<Dropdown | ||
options={dropdownOptions} | ||
onChange={onDropdownSelect} | ||
{...nullableDefault} | ||
/> | ||
) | ||
} |
29 changes: 0 additions & 29 deletions
29
packages/frontend/src/view/components/DefaultExecutorConfigsTable.tsx
This file was deleted.
Oops, something went wrong.
26 changes: 0 additions & 26 deletions
26
packages/frontend/src/view/components/DefaultExecutorsTable.tsx.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.