From bfa1f12f1791ffa0761f30987eb13c11b556c1c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Rocchi?= <84542297+rocky-fleek@users.noreply.github.com> Date: Tue, 16 Nov 2021 15:44:14 -0300 Subject: [PATCH] Fix refresh bug on nfts by changing walletNumber to principalId (#288) --- package.json | 2 +- source/Popup/Views/Home/index.jsx | 4 ++-- source/Popup/Views/SendNFT/index.jsx | 4 ++-- source/components/NFTs/index.jsx | 6 +++--- source/components/Profile/index.jsx | 4 ++-- source/redux/wallet.js | 4 ++-- yarn.lock | 8 ++++---- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 4ca0cf6f..07a26223 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/source/Popup/Views/Home/index.jsx b/source/Popup/Views/Home/index.jsx index b3801d9e..777ecc11 100644 --- a/source/Popup/Views/Home/index.jsx +++ b/source/Popup/Views/Home/index.jsx @@ -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) => { @@ -66,7 +66,7 @@ const Home = () => { params: { refresh: true }, }, (nftCollections) => { if (nftCollections?.length) { - dispatch(setCollections({ collections: nftCollections, walletNumber })); + dispatch(setCollections({ collections: nftCollections, principalId })); } }); } diff --git a/source/Popup/Views/SendNFT/index.jsx b/source/Popup/Views/SendNFT/index.jsx index e3a6c816..67fb0966 100644 --- a/source/Popup/Views/SendNFT/index.jsx +++ b/source/Popup/Views/SendNFT/index.jsx @@ -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); @@ -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)); diff --git a/source/components/NFTs/index.jsx b/source/components/NFTs/index.jsx index 801b2689..24dbe6b7 100644 --- a/source/components/NFTs/index.jsx +++ b/source/components/NFTs/index.jsx @@ -13,7 +13,7 @@ const NFTs = () => { const dispatch = useDispatch(); const { - collections, collectionsLoading, walletNumber, optimisticNFTUpdate, + collections, collectionsLoading, principalId, optimisticNFTUpdate, } = useSelector((state) => state.wallet); useEffect(() => { @@ -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 ( diff --git a/source/components/Profile/index.jsx b/source/components/Profile/index.jsx index e766e51c..0ccd84fa 100644 --- a/source/components/Profile/index.jsx +++ b/source/components/Profile/index.jsx @@ -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); @@ -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) { diff --git a/source/redux/wallet.js b/source/redux/wallet.js index 83c6921b..f3e75ccd 100644 --- a/source/redux/wallet.js +++ b/source/redux/wallet.js @@ -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; diff --git a/yarn.lock b/yarn.lock index 28464753..6a5bfbb1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1609,10 +1609,10 @@ cross-fetch "^3.1.4" crypto-js "^4.1.1" -"@psychedelic/plug-controller@0.11.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/plug-controller@0.11.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"