ghost-portal/packages/react-hooks/src/utils/getFeeAssetLocation.ts
Arjun Porwal bdfcedae72
AssetHub: Fee payment with any sufficient asset (#11229)
* feat: created useAssetIds and useAssetInfo hook

* feat: created pay with asset component

* feat: add paywith asset component with Transfer modal

* fix: signer options as prop

* fix: payment info

* feat: created PayWithAsset provider and integrated with transfer form

* chore: rename variable

* fix: PayWithAsset provider wrapping

* feat: integrate PayWithAsset context and enhance asset info fetching

* fix: some build errors

* refactor: update imports and simplify getFeeAssetLocation function

* refactor: simplify component structure and update PayWithAsset import paths

* fix: all build errors

* fix: avoid redundant type

* feat: added translation

* feat: enhance fee payment info & fee asset handling

* fix: translations ordering

* fix: remove redundant types and hooks

* chore: added statemine chain

* refactor: generalize fee acceptance check for non-native assets

* fix: remove constants and generalize palletIndex
2025-02-06 21:20:08 +05:30

26 lines
884 B
TypeScript

// Copyright 2017-2025 @polkadot/react-hooks authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { ApiPromise } from '@polkadot/api';
import type { AnyNumber } from '@polkadot/types-codec/types';
import type { AssetInfoComplete } from '../types.js';
export const getFeeAssetLocation = (api: ApiPromise, feeAsset: AssetInfoComplete | null): AnyNumber | object | undefined => {
if (!feeAsset?.id) {
return undefined;
}
const metadata = api.registry.metadata;
const palletIndex = metadata.pallets.filter((a) => a.name.toString() === 'Assets')[0].index.toString();
// FIX ME: Might have to fix it later as it may not be applicable for all chains
const palletInstance = { PalletInstance: palletIndex };
const generalIndex = { GeneralIndex: feeAsset.id };
return {
interior: { X2: [palletInstance, generalIndex] },
parents: 0
};
};