-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor EVMChainsDropdown to support all chains
- Loading branch information
Showing
20 changed files
with
239 additions
and
114 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
2 changes: 1 addition & 1 deletion
2
apps/maestro/src/features/InterchainTokenList/UnregisteredInterchainTokenCard.tsx
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
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
57 changes: 57 additions & 0 deletions
57
apps/maestro/src/ui/components/ChainsDropdown/ChainsDropdown.state.tsx
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,57 @@ | ||
import { createContainer, useSessionStorageState } from "@axelarjs/utils/react"; | ||
import { type FC } from "react"; | ||
|
||
export const INITIAL_STATE = { | ||
selectedChainId: null as number | null, | ||
selectedChainType: null as "evm" | "vm" | null, | ||
}; | ||
|
||
function useChainsDropdownState(initialState = INITIAL_STATE) { | ||
const [state, setState] = useSessionStorageState( | ||
"@maestro/chains-dropdown", | ||
initialState | ||
); | ||
|
||
const actions = { | ||
selectChainId: (chainId: number | null, chainType?: "evm" | "vm" | null) => { | ||
setState((state) => { | ||
state.selectedChainId = chainId; | ||
if (chainType !== undefined) { | ||
state.selectedChainType = chainType; | ||
} | ||
}); | ||
}, | ||
setChainType: (chainType: "evm" | "vm" | null) => { | ||
setState((state) => { | ||
state.selectedChainType = chainType; | ||
}); | ||
}, | ||
}; | ||
|
||
return [state, actions] as const; | ||
} | ||
|
||
export const { | ||
Provider: ChainsDropdownProvider, | ||
useContainer: useChainsDropdownContainer, | ||
} = createContainer(useChainsDropdownState); | ||
|
||
export function withChainsDropdownProvider<TProps>(Component: FC<TProps>) { | ||
const Inner = (props: TProps) => ( | ||
<ChainsDropdownProvider> | ||
<Component {...(props as TProps & JSX.IntrinsicAttributes)} /> | ||
</ChainsDropdownProvider> | ||
); | ||
Inner.displayName = `withChainsDropdownProvider(${ | ||
Component.displayName ?? Component.name ?? "Component" | ||
})`; | ||
return Inner; | ||
} | ||
|
||
// For backwards compatibility (if needed) | ||
export const { | ||
Provider: EVMChainsDropdownProvider, | ||
useContainer: useEVMChainsDropdownContainer, | ||
} = createContainer(useChainsDropdownState); | ||
|
||
export const withEVMChainsDropdownProvider = withChainsDropdownProvider; |
Oops, something went wrong.