Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion apps/watcher/src/app/actions/@form/withdraw/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,38 @@ interface Form extends TokenAmountCompatibleFormSchema {
tokenId: string;
}

const WITHDRAW_ASSETS_PAGE_SIZE = 100;

const fetchAddressAssets = async (): Promise<ApiAddressAssetsResponse> => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reduce Redundant API Path by Passing the URL as an Argument

const fetchAddressAssets = async (url: string): Promise<ApiAddressAssetsResponse> => 

const items: ApiAddressAssetsResponse['items'] = [];
let total = 0;

do {
const page: ApiAddressAssetsResponse = await fetcher([
'/address/assets',
{
offset: items.length,
limit: WITHDRAW_ASSETS_PAGE_SIZE,
},
]);

total = page.total;
items.push(...page.items);

if (!page.items.length) break;
} while (items.length < total);

return {
total,
items,
};
};

const WithdrawForm = () => {
const toast = useToast();

const { data, isLoading: isTokensListLoading } =
useSWR<ApiAddressAssetsResponse>('/address/assets', fetcher, {});
useSWR<ApiAddressAssetsResponse>('/address/assets', fetchAddressAssets);

const { token: ergToken, isLoading: isErgTokenLoading } = useToken('erg');
const { apiKey } = useApiKey();
Expand Down