Skip to content

Commit

Permalink
chore: misc tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
rossbulat committed Jun 19, 2024
1 parent e21a644 commit 1502b98
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 30 deletions.
31 changes: 16 additions & 15 deletions src/routes/Chain/ChainState/StorageItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,46 +46,47 @@ export const StorageItems = () => {
nameA < nameB ? -1 : nameA > nameB ? 1 : 0
);

const result: PalletData = {
// Formatted storage and pallet data.
const storageData: PalletData = {
pallets,
activePallet,
items,
};

return { storageData: result, scraper };
return { storageData, scraper };
}, [chainUi.pallet, Metadata?.metadata]);

const { storageData, scraper: listScraper } = scrapedStorageList;
const { pallets, activePallet, items } = storageData;

// If no storage item selected, select the first one from the list or fall back to null.
// Get the active storage item. If no storage item selected, select the first one from the list or
// fall back to null.
const activeItem = chainUi.selected || items?.[0]?.name || null;

// Get the whole active storage item record from metadata for input formatting.
// Get the whole active storage item record from metadata for input arg formatting.
const scraperResult = useMemo(() => {
if (!activePallet || !activeItem) {
return null;
return { scrapedItem: null, scraper: null };
}

const scraper = new PalletScraper(Metadata, { maxDepth: '*' });
const result = scraper.getStorageItem(activePallet, activeItem);
const scrapedItem = scraper.getStorageItem(activePallet, activeItem);

return { scrapedItem: result, scraper };
}, [items, activeItem, activePallet]);
return { scrapedItem, scraper };
}, [activeItem, activePallet]);

// Get scrape result.
const scrapedItem = scraperResult?.scrapedItem || null;
const itemScraper = scraperResult?.scraper || null;
const { scrapedItem, scraper: itemScraper } = scraperResult;

// Handle storage item query submission.
// Handle storage item query submission. This function is called after input arg formatting is
// completed. No further formatting is required by this function. Exits early if active items or
// value are not set.
const onSubmit = (args: AnyJson) => {
const value = chainUi.selected;
if (!activePallet || !activeItem || !value || !value.length) {
if (!activePallet || !activeItem) {
return;
}

const chainState = ChainStateController.instances[instanceId];
chainState.subscribe(`${value}`, {
chainState.subscribe(`${activeItem}`, {
type: 'storage',
namespace: camelize(activePallet),
method: camelize(activeItem),
Expand Down
28 changes: 13 additions & 15 deletions src/routes/Chain/Extrinsics/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,21 @@ export const Extrinsics = () => {
const { getChainUi, setChainUiNamespace } = useChainUi();
const { getFromAddress, setFromAddress } = useChainState();

const chainUiSection = 'calls';
const chainUi = getChainUi(tabId, chainUiSection);
const Metadata = chainSpec.metadata;

// Get accounts for sender address input.
const accounts = chainSpec
? getAccounts(chainSpec.version.specName, chainSpec.ss58Prefix)
: [];

// Get the sender address.
const fromAddress = getFromAddress(tabId) || '';

const chainUiSection = 'calls';
const chainUi = getChainUi(tabId, chainUiSection);
const Metadata = chainSpec.metadata;

// Fetch storage data when metadata or the selected pallet changes.
const callData = useMemo((): PalletData => {
const scraper = new PalletScraper(Metadata, {
maxDepth: 7,
});
const scraper = new PalletScraper(Metadata, { maxDepth: 7 });
const pallets = scraper.getPalletList(['calls']);

// If no pallet selected, get first one from scraper or fall back to null.
Expand All @@ -56,14 +55,13 @@ export const Extrinsics = () => {
nameA < nameB ? -1 : nameA > nameB ? 1 : 0
);

const result: PalletData = {
// Return formatted call and pallet data.
return {
pallets,
activePallet,
items,
};

return result;
}, [chainUi.pallet, chainUi.selected, Metadata?.metadata]);
}, [chainUi.pallet, Metadata?.metadata]);

const { pallets, activePallet, items } = callData;

Expand All @@ -75,11 +73,11 @@ export const Extrinsics = () => {
if (!activePallet || !activeItem) {
return null;
}
// NOTE: Currently limiting scraper to 7 recursive levels to improve performance.
const scraper = new PalletScraper(Metadata, { maxDepth: 7 });
const result = scraper.getCallItem(activePallet, activeItem);

return { scrapedItem: result, scraper };
const scraper = new PalletScraper(Metadata, { maxDepth: '*' });
const scrapedItem = scraper.getCallItem(activePallet, activeItem);

return { scrapedItem, scraper };
}, [items, activeItem, activePallet]);

// Get scrape result.
Expand Down

0 comments on commit 1502b98

Please sign in to comment.