Skip to content

Commit

Permalink
update fetchPalletInstance to evaluate pool assets, foreign assets an…
Browse files Browse the repository at this point in the history
…d assets pallet validity prior to returning early for parachains that do not support the assets pallet
  • Loading branch information
marshacb committed Nov 13, 2023
1 parent 9d562e7 commit 302d0c8
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/createXcmTypes/util/fetchPalletInstanceId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,27 @@ import { BaseError, BaseErrorsEnum } from '../../errors';
* @param isLiquidToken Boolean to determine whether or not to fetch the PoolAssets id.
*/
export const fetchPalletInstanceId = (api: ApiPromise, isLiquidToken: boolean, isForeignAsset: boolean): string => {
if (!api.query.assets) {
return '';
}

if (isLiquidToken && isForeignAsset) {
throw new BaseError(
"Can't find the appropriate pallet when both liquid tokens and foreign assets",
BaseErrorsEnum.InternalError
);
}
const palletName = isLiquidToken ? 'PoolAssets' : isForeignAsset ? 'ForeignAssets' : 'Assets';

const palletName =
isLiquidToken && api.query.poolAssets
? 'PoolAssets'
: isForeignAsset && api.query.foreignAssets
? 'ForeignAssets'
: api.query.assets
? 'Assets'
: '';

// return early if assets pallet is not found and palletName is not PoolAssets or ForeignAssets
if (!api.query.assets && palletName.length === 0) {
return palletName;
}

const pallet = api.registry.metadata.pallets.filter((pallet) => pallet.name.toString() === palletName);

if (pallet.length === 0) {
Expand Down

0 comments on commit 302d0c8

Please sign in to comment.