(Fix) Null balances (#971)

* Fixs balances will null value

* Fixs collectibles not loading

* Uses useLocation hooks

* Add types

* fix types for useLocation

Co-authored-by: Mikhail Mikheev <mmvsha73@gmail.com>
This commit is contained in:
Agustin Pane 2020-06-04 17:54:39 -03:00 committed by GitHub
parent 63193d2429
commit e5c6d8040d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 8 deletions

View File

@ -26,7 +26,7 @@ export const fetchCurrencyValues = (safeAddress) => async (dispatch) => {
const { currencyRate, selectedCurrency }: any = value const { currencyRate, selectedCurrency }: any = value
batch(() => { batch(() => {
dispatch(setSelectedCurrency(safeAddr, selectedCurrency || AVAILABLE_CURRENCIES.USD)) dispatch(setSelectedCurrency(safeAddr, selectedCurrency || AVAILABLE_CURRENCIES.USD))
dispatch(setCurrencyRate(safeAddr, currencyRate)) dispatch(setCurrencyRate(safeAddr, currencyRate || 1))
}) })
}) })
} catch (err) { } catch (err) {

View File

@ -1,5 +1,6 @@
import { useMemo } from 'react' import { useMemo } from 'react'
import { batch, useDispatch, useSelector } from 'react-redux' import { batch, useDispatch, useSelector } from 'react-redux'
import { useLocation } from 'react-router-dom'
import fetchCollectibles from 'src/logic/collectibles/store/actions/fetchCollectibles' import fetchCollectibles from 'src/logic/collectibles/store/actions/fetchCollectibles'
import { fetchCurrencyValues } from 'src/logic/currencyValues/store/actions/fetchCurrencyValues' import { fetchCurrencyValues } from 'src/logic/currencyValues/store/actions/fetchCurrencyValues'
@ -8,13 +9,14 @@ import fetchSafeTokens from 'src/logic/tokens/store/actions/fetchSafeTokens'
import { fetchTokens } from 'src/logic/tokens/store/actions/fetchTokens' import { fetchTokens } from 'src/logic/tokens/store/actions/fetchTokens'
import { COINS_LOCATION_REGEX, COLLECTIBLES_LOCATION_REGEX } from 'src/routes/safe/components/Balances' import { COINS_LOCATION_REGEX, COLLECTIBLES_LOCATION_REGEX } from 'src/routes/safe/components/Balances'
import { safeParamAddressFromStateSelector } from 'src/routes/safe/store/selectors' import { safeParamAddressFromStateSelector } from 'src/routes/safe/store/selectors'
import { history } from 'src/store'
export const useFetchTokens = () => { export const useFetchTokens = (): void => {
const dispatch = useDispatch() const dispatch = useDispatch()
const address = useSelector(safeParamAddressFromStateSelector) const address: string | null = useSelector(safeParamAddressFromStateSelector)
const location = useLocation()
useMemo(() => { useMemo(() => {
if (COINS_LOCATION_REGEX.test(history.location.pathname)) { if (COINS_LOCATION_REGEX.test(location.pathname)) {
batch(() => { batch(() => {
// fetch tokens there to get symbols for tokens in TXs list // fetch tokens there to get symbols for tokens in TXs list
dispatch(fetchTokens()) dispatch(fetchTokens())
@ -23,12 +25,12 @@ export const useFetchTokens = () => {
}) })
} }
if (COLLECTIBLES_LOCATION_REGEX.test(history.location.pathname)) { if (COLLECTIBLES_LOCATION_REGEX.test(location.pathname)) {
batch(() => { batch(() => {
dispatch(fetchCollectibles()).then(() => { dispatch(fetchCollectibles()).then(() => {
dispatch(activateAssetsByBalance(address)) dispatch(activateAssetsByBalance(address))
}) })
}) })
} }
}, [address, dispatch]) }, [address, dispatch, location])
} }

View File

@ -32,7 +32,7 @@ const cancellationTransactionsSelector = (state) => state[CANCELLATION_TRANSACTI
const incomingTransactionsSelector = (state) => state[INCOMING_TRANSACTIONS_REDUCER_ID] const incomingTransactionsSelector = (state) => state[INCOMING_TRANSACTIONS_REDUCER_ID]
export const safeParamAddressFromStateSelector = (state) => { export const safeParamAddressFromStateSelector = (state): string | null => {
const match = matchPath(state.router.location.pathname, { path: `${SAFELIST_ADDRESS}/:safeAddress` }) const match = matchPath(state.router.location.pathname, { path: `${SAFELIST_ADDRESS}/:safeAddress` })
if (match) { if (match) {

View File

@ -2145,6 +2145,11 @@
"@types/minimatch" "*" "@types/minimatch" "*"
"@types/node" "*" "@types/node" "*"
"@types/history@*":
version "4.7.6"
resolved "https://registry.yarnpkg.com/@types/history/-/history-4.7.6.tgz#ed8fc802c45b8e8f54419c2d054e55c9ea344356"
integrity sha512-GRTZLeLJ8ia00ZH8mxMO8t0aC9M1N9bN461Z2eaRurJo6Fpa+utgCwLzI4jQHcrdzuzp5WPN9jRwpsCQ1VhJ5w==
"@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0": "@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0":
version "2.0.2" version "2.0.2"
resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.2.tgz#79d7a78bad4219f4c03d6557a1c72d9ca6ba62d5" resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.2.tgz#79d7a78bad4219f4c03d6557a1c72d9ca6ba62d5"
@ -2220,6 +2225,23 @@
dependencies: dependencies:
"@types/react" "*" "@types/react" "*"
"@types/react-router-dom@^5.1.5":
version "5.1.5"
resolved "https://registry.yarnpkg.com/@types/react-router-dom/-/react-router-dom-5.1.5.tgz#7c334a2ea785dbad2b2dcdd83d2cf3d9973da090"
integrity sha512-ArBM4B1g3BWLGbaGvwBGO75GNFbLDUthrDojV2vHLih/Tq8M+tgvY1DSwkuNrPSwdp/GUL93WSEpTZs8nVyJLw==
dependencies:
"@types/history" "*"
"@types/react" "*"
"@types/react-router" "*"
"@types/react-router@*":
version "5.1.7"
resolved "https://registry.yarnpkg.com/@types/react-router/-/react-router-5.1.7.tgz#e9d12ed7dcfc79187e4d36667745b69a5aa11556"
integrity sha512-2ouP76VQafKjtuc0ShpwUebhHwJo0G6rhahW9Pb8au3tQTjYXd2jta4wv6U2tGLR/I42yuG00+UXjNYY0dTzbg==
dependencies:
"@types/history" "*"
"@types/react" "*"
"@types/react-transition-group@^4.2.0": "@types/react-transition-group@^4.2.0":
version "4.4.0" version "4.4.0"
resolved "https://registry.yarnpkg.com/@types/react-transition-group/-/react-transition-group-4.4.0.tgz#882839db465df1320e4753e6e9f70ca7e9b4d46d" resolved "https://registry.yarnpkg.com/@types/react-transition-group/-/react-transition-group-4.4.0.tgz#882839db465df1320e4753e6e9f70ca7e9b4d46d"