Skip to content

Commit

Permalink
refactor: check if current chain is vm chain
Browse files Browse the repository at this point in the history
  • Loading branch information
npty committed Jan 17, 2025
1 parent 71a634e commit 6875987
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { getNativeToken } from "~/lib/utils/getNativeToken";
import ChainPicker from "~/ui/compounds/ChainPicker";
import { NextButton, TokenNameAlert } from "~/ui/compounds/MultiStepForm";
import { useStep3ChainSelectionState } from "./DeployAndRegister.state";
import { NEXT_PUBLIC_WHITELISTED_DEST_CHAINS_FOR_VM } from "~/config/env";
import { filterEligibleChains } from "~/lib/utils/chains";

export const Step3: FC = () => {
Expand Down Expand Up @@ -139,8 +138,7 @@ export const Step3: FC = () => {
]
);

const whitelistedChains = NEXT_PUBLIC_WHITELISTED_DEST_CHAINS_FOR_VM.split(',').map(chain => chain.trim());
const eligibleChains = filterEligibleChains(state.chains, chainId, whitelistedChains);
const eligibleChains = filterEligibleChains(state.chains, chainId);

const formSubmitRef = useRef<ComponentRef<"button">>(null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { NextButton } from "~/ui/compounds/MultiStepForm";
import { useDeployAndRegisterRemoteInterchainTokenMutation } from "../../hooks";
import { useInterchainTokenDeploymentStateContainer } from "../../InterchainTokenDeployment.state";
import { useStep2ChainSelectionState } from "./DeployAndRegister.state";
import { NEXT_PUBLIC_WHITELISTED_DEST_CHAINS_FOR_VM } from "~/config/env"
import { filterEligibleChains } from "~/lib/utils/chains";

export const Step2: FC = () => {
Expand Down Expand Up @@ -142,8 +141,7 @@ export const Step2: FC = () => {
]
);

const whitelistedChains = NEXT_PUBLIC_WHITELISTED_DEST_CHAINS_FOR_VM.split(',').map(chain => chain.trim());
const eligibleChains = filterEligibleChains(state.chains, chainId, whitelistedChains);
const eligibleChains = filterEligibleChains(state.chains, chainId);

const formSubmitRef = useRef<ComponentRef<"button">>(null);

Expand Down
9 changes: 7 additions & 2 deletions apps/maestro/src/lib/utils/chains.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { ITSChainConfig } from "@axelarjs/api";
import { NEXT_PUBLIC_WHITELISTED_DEST_CHAINS_FOR_VM } from "~/config/env";

export const filterEligibleChains = (
chains: ITSChainConfig[],
currentChainId: number,
whitelistedChains: string[]
): ITSChainConfig[] => {
// Early return if no chains to filter
if (!chains.length) return [];

const currentChain = chains.find((chain) => chain.chain_id === currentChainId);
const isCurrentChainVM = currentChain?.chain_type === 'vm';

const whitelistedChains = NEXT_PUBLIC_WHITELISTED_DEST_CHAINS_FOR_VM.split(',').map(chain => chain.trim());

// Normalize whitelist check
const isAllChainsWhitelisted = whitelistedChains[0] === 'all';

Expand All @@ -16,7 +21,7 @@ export const filterEligibleChains = (
if (chain.chain_id === currentChainId) return false;

// For EVM chains, check whitelist
if (chain.chain_type === 'evm') {
if (isCurrentChainVM && chain.chain_type === 'evm') {
return isAllChainsWhitelisted || whitelistedChains.includes(chain.id);
}

Expand Down

0 comments on commit 6875987

Please sign in to comment.