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

Commit

Permalink
fix: logic for Show more button in the wallets list (#3277)
Browse files Browse the repository at this point in the history
  • Loading branch information
romanlikhovich authored Jan 30, 2021
1 parent 234008a commit 9a96924
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ cypress/screenshots/**/*.png
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# IDE
.idea/
8 changes: 4 additions & 4 deletions src/domains/dashboard/components/Wallets/hooks.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe("useWalletDisplay hook", () => {
});

expect(result.current.listWallets).toHaveLength(2);
expect(result.current.listHasMore).toBe(true);
expect(result.current.listHasMore).toBe(false);
});

it("should limit list type wallets", async () => {
Expand Down Expand Up @@ -73,15 +73,15 @@ describe("useWalletDisplay hook", () => {
useWalletDisplay({
wallets,
selectedNetworkIds: ["ark.devnet", "ark.mainnet"],
viewMore: false,
viewMore: true,
listPagerLimit: 1,
}),
{
wrapper,
},
);

expect(result.current.listWallets).toHaveLength(2);
expect(result.current.listWallets).toHaveLength(3);
});

it("should filter wallets by selectedNetworkIds", async () => {
Expand All @@ -96,7 +96,7 @@ describe("useWalletDisplay hook", () => {
it("should return listHasMore boolean", async () => {
const wrapper = ({ children }: any) => <EnvironmentProvider env={env}> {children} </EnvironmentProvider>;
const { result } = renderHook(
() => useWalletDisplay({ wallets, selectedNetworkIds: ["ark.devnet"], listPagerLimit: 1, viewMore: true }),
() => useWalletDisplay({ wallets, selectedNetworkIds: ["ark.devnet"], listPagerLimit: 1, viewMore: false }),
{
wrapper,
},
Expand Down
18 changes: 4 additions & 14 deletions src/domains/dashboard/components/Wallets/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,14 @@ export const useWalletDisplay = ({

const { listWallets, gridWallets, listHasMore } = useMemo(() => {
const listWallets = wallets
.filter((wallet: any, index: number) => {
if (!viewMore && index > listPagerLimit) {
return false;
}

if (!selectedNetworkIds?.includes(wallet.network().id())) {
return false;
}

.filter((wallet: any) => {
if (displayType === "favorites") {
return wallet.isStarred();
}

if (displayType === "ledger") {
return wallet.isLedger();
}

return wallet && !wallet.isBlank;
return wallet && !wallet.isBlank && selectedNetworkIds?.includes(wallet.network().id());
})
.map((wallet) => ({ wallet }));

Expand Down Expand Up @@ -87,9 +77,9 @@ export const useWalletDisplay = ({
};

return {
listWallets,
listWallets: viewMore ? listWallets : listWallets.slice(0, listPagerLimit),
gridWallets: loadGridWallets(),
listHasMore: wallets.length > 0 && wallets.length > listWallets.length,
listHasMore: wallets.length > 0 && listWallets.length > listPagerLimit && !viewMore,
};
}, [wallets, selectedNetworkIds, displayType, viewMore, sliderOptions.slidesPerView, listPagerLimit]);

Expand Down

0 comments on commit 9a96924

Please sign in to comment.