Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
refactor: fix hook and disable button when loading
Browse files Browse the repository at this point in the history
  • Loading branch information
dated committed Sep 2, 2020
1 parent e1137c0 commit 545885d
Show file tree
Hide file tree
Showing 6 changed files with 586 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/app/i18n/common/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const translations: { [key: string]: any } = {
LEDGER: "Ledger",
LINK: "Link",
LOAD: "Load",
LOADING: "Loading ...",
MARKETSQUARE: "MarketSquare",
MOST_POPULAR: "Most popular",
MULTISIGNATURE: "Multisignature",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ export const Transactions = ({
data-testid="transactions__fetch-more-button"
variant="plain"
className="w-full mt-10 mb-5"
disabled={isLoading}
onClick={() => fetchMoreAction && fetchMoreAction()}
>
{t("COMMON.VIEW_MORE")}
{isLoading ? t("COMMON.LOADING") : t("COMMON.VIEW_MORE")}
</Button>
)}
</div>
Expand Down
21 changes: 11 additions & 10 deletions src/domains/dashboard/pages/Dashboard/Dashboard.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Profile } from "@arkecosystem/platform-sdk-profiles";
import { translations as commonTranslations } from "app/i18n/common/i18n";
import { createMemoryHistory } from "history";
import nock from "nock";
import React from "react";
Expand Down Expand Up @@ -230,21 +231,21 @@ describe("Dashboard", () => {
},
);

await waitFor(() => expect(getAllByTestId("TransactionRow")).toHaveLength(4));
await waitFor(() => expect(getByTestId("transactions__fetch-more-button")).toBeInTheDocument());
await waitFor(() => {
expect(getByTestId("transactions__fetch-more-button")).toHaveTextContent("View More");
expect(getAllByTestId("TransactionRow")).toHaveLength(4);
});

act(() => {
fireEvent.click(getByTestId("transactions__fetch-more-button"));
});

await waitFor(
() => {
expect(getAllByTestId("TransactionRow")).toHaveLength(4);
},
{
timeout: 5000,
},
);
expect(getByTestId("transactions__fetch-more-button")).toHaveTextContent(commonTranslations.LOADING);

await waitFor(() => {
expect(getByTestId("transactions__fetch-more-button")).toHaveTextContent(commonTranslations.VIEW_MORE);
expect(getAllByTestId("TransactionRow")).toHaveLength(8);
});

expect(asFragment()).toMatchSnapshot();
});
Expand Down
3 changes: 3 additions & 0 deletions src/domains/dashboard/pages/Dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export const Dashboard = ({ networks, portfolioPercentages, balances }: Dashboar
activeProfile.transactionAggregate().flush();
}

setIsLoadingTransactions(true);

const response = await activeProfile.transactionAggregate().transactions({ limit: 10 });
const transactions = response.items();

Expand All @@ -48,6 +50,7 @@ export const Dashboard = ({ networks, portfolioPercentages, balances }: Dashboar

useEffect(() => {
fetchTransactions(true);
// eslint-disable-next-line
}, []);

// Wallet controls data
Expand Down

0 comments on commit 545885d

Please sign in to comment.