Skip to content

Commit

Permalink
fix: disabled XCM transfer with Phala and Khala (#725)
Browse files Browse the repository at this point in the history
* wip: generate staging url

* feat: added disabling XCM logic

* feat: updated productionOrigin variable

* refactor: clean up

* feat: disabled Phala and Khala XCM transfer
  • Loading branch information
impelcrypto authored Mar 31, 2023
1 parent f297abc commit e16c4a5
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/hooks/xcm/useTransferRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type TransferMode = 'local' | 'xcm';
export const astarNetworks = ['astar', 'shiden', 'shibuya'];
export const astarNativeTokens = ['sdn', 'astr', 'sby'];
const disabledXcmChain = endpointKey.SHIDEN;
const disabledXcmParachains: string[] = [Chain.PHALA, Chain.KHALA];

export interface NetworkFromTo {
from: string;
Expand Down Expand Up @@ -348,15 +349,32 @@ export function useTransferRouter() {
}
};

const checkIsDisabledToken = (originChain: string): boolean => {
if (!originChain) return false;
return !!disabledXcmParachains.find((it) => it === originChain);
};

const isDisableXcmEnvironment = computed<boolean>(() => {
const isProductionPage = window.location.origin === productionOrigin;
const isDisabledXcmChain = disabledXcmChain === currentNetworkIdx.value;
return isDisabledXcmChain && isProductionPage;
// return isDisabledXcmChain && isProductionPage;

const originChain = token.value ? token.value.originChain : '';
return checkIsDisabledToken(originChain);
});

const checkIsDisabledXcmChain = (from: string, to: string): boolean => {
if (!from || !to) return false;
const chains = disabledXcmParachains.map((it) => it.toLowerCase());
const isDisabled = chains.find((it) => it === from.toLowerCase() || it === to.toLowerCase());
// return !!isDisabled ||isDisableXcmEnvironment.value;

return !!isDisabled;
};

// Memo: redirect to the assets page if users access to the XCM transfer page by inputting URL directly
const handleDisableXcmTransfer = (): void => {
if (isDisableXcmEnvironment.value && mode.value === 'xcm') {
if (checkIsDisabledXcmChain(from.value, to.value) && mode.value === 'xcm') {
router.push(Path.Assets);
}
};
Expand Down

0 comments on commit e16c4a5

Please sign in to comment.