Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions packages/widget/src/components/TokenList/useTokenSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export const useTokenSelect = (formType: FormType, onClick?: () => void) => {
const emitter = useWidgetEvents()
const { setFieldValue, getFieldValues } = useFieldActions()
const autoPopulateToAddress = useToAddressAutoPopulate()
const setChain = useChainOrderStore((state) => state.setChain)
const [setChain, setIsAllNetworks] = useChainOrderStore((state) => [
state.setChain,
state.setIsAllNetworks,
])

const tokenKey = FormKeyHelper.getTokenKey(formType)

Expand Down Expand Up @@ -67,12 +70,18 @@ export const useTokenSelect = (formType: FormType, onClick?: () => void) => {
}

// If no opposite token is selected, synchronize the opposite chain
// to match the currently selected chain (if allowed)
// to match the currently selected chain (if allowed).
// In default exchange mode, also collapse "All Networks" on the opposite
// side - same-chain swap is the most common action.
if (
!selectedOppositeTokenAddress &&
selectedChainId &&
isItemAllowed(selectedChainId, chainsConfig?.[oppositeFormType])
) {
const isDefaultExchange = !subvariant || subvariant === 'default'
if (isDefaultExchange) {
setIsAllNetworks(false, oppositeFormType)
}
setFieldValue(
FormKeyHelper.getChainKey(oppositeFormType),
selectedChainId,
Expand Down Expand Up @@ -115,6 +124,7 @@ export const useTokenSelect = (formType: FormType, onClick?: () => void) => {
getFieldValues,
onClick,
setChain,
setIsAllNetworks,
setFieldValue,
subvariant,
splitSubvariant,
Expand Down
Loading