Skip to content

Commit

Permalink
Refactor useTabs
Browse files Browse the repository at this point in the history
  • Loading branch information
hide-on-bush-x committed Aug 30, 2023
1 parent 05746a1 commit a726c10
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
1 change: 0 additions & 1 deletion src/refactor/masa/use-custom-sbt.ts
@@ -1,4 +1,3 @@
import type { Masa } from '@masa-finance/masa-sdk';
import { useQuery } from '@tanstack/react-query';

import { useAsyncFn } from 'react-use';
Expand Down
19 changes: 5 additions & 14 deletions src/refactor/ui/components/modals/gallery/useTabs.tsx
@@ -1,5 +1,4 @@
import { useEffect, useState } from 'react';
import { useAsyncFn } from 'react-use';
import { useMemo } from 'react';
import { useMasaClient } from '../../../../masa-client';
import { useCustomSBTs } from '../../../../masa/use-custom-sbt';
import {
Expand All @@ -13,10 +12,8 @@ export const useTabs = () => {
const { customSBTs, isLoading } = useCustomSBTs();
const { sdk: masa } = useMasaClient();

const [savedTabs, setSavedTabs] = useState<TabsInterface[]>();

const [, getTabs] = useAsyncFn(async () => {
if (!customSBTs || (customSBTs && customSBTs.length === 0)) return;
const savedTabs = useMemo((): TabsInterface[] => {
if (!masa || !customSBTs || (customSBTs && customSBTs.length === 0)) return [];

const customSBTsWithTokens = customSBTs.filter(
(contract: HydratedContracts) =>
Expand Down Expand Up @@ -47,14 +44,8 @@ export const useTabs = () => {
}
);

setSavedTabs(newTabs);
}, [customSBTs]);

useEffect(() => {
if (masa) {
void getTabs();
}
}, [masa, getTabs]);
return newTabs;
}, [masa, customSBTs]);

return { tabs: savedTabs, isLoading };
};

0 comments on commit a726c10

Please sign in to comment.