Skip to content

Commit

Permalink
Fix refresh bug on nfts by changing walletNumber to principalId (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
rocky-fleek authored Nov 16, 2021
1 parent 5356bbd commit bfa1f12
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@material-ui/core": "^4.11.3",
"@material-ui/icons": "^4.11.2",
"@psychedelic/dab-js": "0.3.0",
"@psychedelic/plug-controller": "0.11.2",
"@psychedelic/plug-controller": "0.11.3",
"@psychedelic/plug-inpage-provider": "1.5.0",
"@reduxjs/toolkit": "^1.6.0",
"advanced-css-reset": "^1.2.2",
Expand Down
4 changes: 2 additions & 2 deletions source/Popup/Views/Home/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const Home = () => {
const dispatch = useDispatch();
const { navigator, tabIndex } = useRouter();
const {
walletNumber, assetsLoading, collectionsLoading, transactionsLoading,
principalId, assetsLoading, collectionsLoading, transactionsLoading,
} = useSelector((state) => state.wallet);

const onChangeTab = (index) => {
Expand Down Expand Up @@ -66,7 +66,7 @@ const Home = () => {
params: { refresh: true },
}, (nftCollections) => {
if (nftCollections?.length) {
dispatch(setCollections({ collections: nftCollections, walletNumber }));
dispatch(setCollections({ collections: nftCollections, principalId }));
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions source/Popup/Views/SendNFT/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const SendNFT = () => {
const [error, setError] = useState(false);
const dispatch = useDispatch();
const { selectedNft: nft } = useSelector((state) => state.nfts);
const { collections, walletNumber } = useSelector((state) => state.wallet);
const { collections, principalId } = useSelector((state) => state.wallet);
const classes = useStyles();
const transferNFT = () => {
setLoading(true);
Expand All @@ -46,7 +46,7 @@ const SendNFT = () => {
if (success) {
dispatch(setCollections({
collections: collections.filter((token) => token.id !== nft?.id),
walletNumber,
principalId,
}));
dispatch(removeNFT(nft));
dispatch(setSelectedNft(null));
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 @@ -13,7 +13,7 @@ const NFTs = () => {
const dispatch = useDispatch();

const {
collections, collectionsLoading, walletNumber, optimisticNFTUpdate,
collections, collectionsLoading, principalId, optimisticNFTUpdate,
} = useSelector((state) => state.wallet);

useEffect(() => {
Expand All @@ -24,11 +24,11 @@ const NFTs = () => {
params: { refresh: false },
}, (nftCollections) => {
if (nftCollections?.length && !optimisticNFTUpdate) {
dispatch(setCollections({ collections: nftCollections, walletNumber }));
dispatch(setCollections({ collections: nftCollections, principalId }));
}
dispatch(setCollectionsLoading(false));
});
}, [walletNumber]);
}, [principalId]);
const nfts = collections?.flatMap((c) => c.tokens);
return (
<LoadingWrapper loading={!nfts.length && collectionsLoading} className="big">
Expand Down
4 changes: 2 additions & 2 deletions source/components/Profile/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const Profile = ({ disableProfile }) => {
const dispatch = useDispatch();
const { navigator } = disableProfile ? {} : useRouter();

const { walletNumber } = useSelector((state) => state.wallet);
const { walletNumber, principalId } = useSelector((state) => state.wallet);
const icpPrice = useICPPrice();

const [open, setOpen] = useState(false);
Expand Down Expand Up @@ -86,7 +86,7 @@ const Profile = ({ disableProfile }) => {
};

const handleChangeAccount = (wallet) => () => {
dispatch(setCollections({ collections: [], walletNumber }));
dispatch(setCollections({ collections: [], principalId }));
sendMessage({ type: HANDLER_TYPES.SET_CURRENT_PRINCIPAL, params: wallet },
(state) => {
if (state?.wallets?.length) {
Expand Down
4 changes: 2 additions & 2 deletions source/redux/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ export const walletSlice = createSlice({
}
},
setCollections: (state, action) => {
const { collections, walletNumber } = action.payload;
if (state.walletNumber === walletNumber && collections) {
const { collections, principalId } = action.payload;
if (state.principalId === principalId && collections) {
state.collections = collections?.sort(sortCollections);
}
state.optimisticNFTUpdate = false;
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1609,10 +1609,10 @@
cross-fetch "^3.1.4"
crypto-js "^4.1.1"

"@psychedelic/[email protected].2":
version "0.11.2"
resolved "https://npm.pkg.github.com/download/@psychedelic/plug-controller/0.11.2/ed5038b50ba5edd6c72e2fe5c42e680824b2902e39ea48b2a31b8f44ca888d1d#683e2aad93b0d4203846efbfea86e5aa41d1023f"
integrity sha512-9z9XG+rD+qDrC+o4mBbIx3CbyoQyIOhh1PN/imrdlhuRs21VEt3JLPYkQdFHrM7LgGDYuJeWxwN/ccBCPI18Aw==
"@psychedelic/[email protected].3":
version "0.11.3"
resolved "https://npm.pkg.github.com/download/@psychedelic/plug-controller/0.11.3/b4281801e669e37a9c119e6d77e9dc1749f3bee18259bd34a4ecd1ecd5c295bc#5f1678f646d23abf9270c5bcee00c3bb26217d20"
integrity sha512-5Hb1QF4OYozdKOlqSzYmpR7mbOAVADZXXYFQocVy/oaUwG6erivkmhfVwk0LVdGzGDeeAI8EzcOdBj0WRybsqg==
dependencies:
"@dfinity/agent" "^0.10.1"
"@dfinity/candid" "^0.10.1"
Expand Down

0 comments on commit bfa1f12

Please sign in to comment.