Skip to content

Commit

Permalink
Added request at home render, removed validation on empty collections…
Browse files Browse the repository at this point in the history
… for loading (#218)
  • Loading branch information
rocky-fleek authored Sep 17, 2021
1 parent a1b7d37 commit 7ad4c6e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 11 additions & 2 deletions source/Popup/Views/Home/index.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React, { useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import { useDispatch } from 'react-redux';
import { useDispatch, useSelector } from 'react-redux';
import {
Actions, Tokens, Activity, Apps, Layout, useRouter, NFTs,
} from '@components';
import { Tabs } from '@ui';
import { HANDLER_TYPES, sendMessage } from '@background/Keyring';
import getICPPrice from '@shared/services/ICPPrice';
import { setAccountInfo } from '@redux/wallet';
import { setAccountInfo, setCollections, setCollectionsLoading } from '@redux/wallet';
import { setICPPrice } from '@redux/icp';

const getTabs = (t) => [
Expand All @@ -33,6 +33,7 @@ const Home = () => {
const { t } = useTranslation();
const dispatch = useDispatch();
const { navigator, tabIndex } = useRouter();
const { walletNumber } = useSelector((state) => state.wallet);

const onChangeTab = (index) => {
navigator.navigate('home', index);
Expand All @@ -53,6 +54,14 @@ const Home = () => {
console.warn(err);
}

sendMessage({
type: HANDLER_TYPES.GET_NFTS,
params: { refresh: true },
}, (nftCollections) => {
dispatch(setCollections({ collections: nftCollections, walletNumber }));
dispatch(setCollectionsLoading(false));
});

sendMessage({ type: HANDLER_TYPES.GET_STATE, params: {} },
(state) => {
if (!state?.wallets?.length) {
Expand Down
6 changes: 3 additions & 3 deletions source/components/NFTs/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ const NFTs = () => {
const dispatch = useDispatch();

const { collections, collectionsLoading, walletNumber } = useSelector((state) => state.wallet);
const [loading, setLoading] = useState(true);
const [loading, setLoading] = useState(collectionsLoading);

useEffect(() => {
sendMessage({
type: HANDLER_TYPES.GET_NFTS,
params: { refresh: true },
params: {},
}, (nftCollections) => {
dispatch(setCollections({ collections: nftCollections, walletNumber }));
dispatch(setCollectionsLoading(false));
Expand All @@ -29,7 +29,7 @@ const NFTs = () => {
}, [collectionsLoading]);

return (
<LoadingWrapper loading={!collections.length && loading} className="big">
<LoadingWrapper loading={loading} className="big">
{
!collections?.length
? <EmptyState />
Expand Down

0 comments on commit 7ad4c6e

Please sign in to comment.