Fix #597: USD value not load (#609)

* Converts all the addresses to checksum values

* Fix for empty address
This commit is contained in:
Agustin Pane 2020-02-21 18:16:52 -03:00 committed by GitHub
parent ea6c1f4c59
commit 1f3f13eeb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 11 deletions

View File

@ -7,7 +7,7 @@ import type { SafeProps } from '~/routes/safe/store/models/safe'
import addSafe from '~/routes/safe/store/actions/addSafe' import addSafe from '~/routes/safe/store/actions/addSafe'
import { getSafeName, getLocalSafe } from '~/logic/safe/utils' import { getSafeName, getLocalSafe } from '~/logic/safe/utils'
import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts' import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts'
import { getBalanceInEtherOf } from '~/logic/wallets/getWeb3' import { getBalanceInEtherOf, getWeb3 } from '~/logic/wallets/getWeb3'
import { sameAddress } from '~/logic/wallets/ethAddresses' import { sameAddress } from '~/logic/wallets/ethAddresses'
import removeSafeOwner from '~/routes/safe/store/actions/removeSafeOwner' import removeSafeOwner from '~/routes/safe/store/actions/removeSafeOwner'
import addSafeOwner from '~/routes/safe/store/actions/addSafeOwner' import addSafeOwner from '~/routes/safe/store/actions/addSafeOwner'
@ -33,7 +33,8 @@ const buildOwnersFrom = (
}) })
}) })
export const buildSafe = async (safeAddress: string, safeName: string) => { export const buildSafe = async (safeAdd: string, safeName: string) => {
const safeAddress = getWeb3().utils.toChecksumAddress(safeAdd)
const gnosisSafe = await getGnosisSafeInstanceAt(safeAddress) const gnosisSafe = await getGnosisSafeInstanceAt(safeAddress)
const ethBalance = await getBalanceInEtherOf(safeAddress) const ethBalance = await getBalanceInEtherOf(safeAddress)
@ -53,7 +54,8 @@ export const buildSafe = async (safeAddress: string, safeName: string) => {
return safe return safe
} }
export const checkAndUpdateSafe = (safeAddress: string) => async (dispatch: ReduxDispatch<*>) => { export const checkAndUpdateSafe = (safeAdd: string) => async (dispatch: ReduxDispatch<*>) => {
const safeAddress = getWeb3().utils.toChecksumAddress(safeAdd)
// Check if the owner's safe did change and update them // Check if the owner's safe did change and update them
const [gnosisSafe, localSafe] = await Promise.all([getGnosisSafeInstanceAt(safeAddress), getLocalSafe(safeAddress)]) const [gnosisSafe, localSafe] = await Promise.all([getGnosisSafeInstanceAt(safeAddress), getLocalSafe(safeAddress)])
@ -90,8 +92,9 @@ export const checkAndUpdateSafe = (safeAddress: string) => async (dispatch: Redu
} }
// eslint-disable-next-line consistent-return // eslint-disable-next-line consistent-return
export default (safeAddress: string) => async (dispatch: ReduxDispatch<GlobalState>) => { export default (safeAdd: string) => async (dispatch: ReduxDispatch<GlobalState>) => {
try { try {
const safeAddress = getWeb3().utils.toChecksumAddress(safeAdd)
const safeName = (await getSafeName(safeAddress)) || 'LOADED SAFE' const safeName = (await getSafeName(safeAddress)) || 'LOADED SAFE'
const safeProps: SafeProps = await buildSafe(safeAddress, safeName) const safeProps: SafeProps = await buildSafe(safeAddress, safeName)

View File

@ -3,12 +3,14 @@ import type { Dispatch as ReduxDispatch } from 'redux'
import { type GlobalState } from '~/store/index' import { type GlobalState } from '~/store/index'
import { getDefaultSafe } from '~/logic/safe/utils' import { getDefaultSafe } from '~/logic/safe/utils'
import setDefaultSafe from './setDefaultSafe' import setDefaultSafe from './setDefaultSafe'
import { getWeb3 } from '~/logic/wallets/getWeb3'
const loadDefaultSafe = () => async (dispatch: ReduxDispatch<GlobalState>) => { const loadDefaultSafe = () => async (dispatch: ReduxDispatch<GlobalState>) => {
try { try {
const defaultSafe: string = await getDefaultSafe() const defaultSafe: string = await getDefaultSafe()
const checksumed =
dispatch(setDefaultSafe(defaultSafe)) defaultSafe && defaultSafe.length > 0 ? getWeb3().utils.toChecksumAddress(defaultSafe) : defaultSafe
dispatch(setDefaultSafe(checksumed))
} catch (err) { } catch (err) {
// eslint-disable-next-line // eslint-disable-next-line
console.error('Error while getting default Safe from storage:', err) console.error('Error while getting default Safe from storage:', err)

View File

@ -13,6 +13,7 @@ import { REPLACE_SAFE_OWNER } from '~/routes/safe/store/actions/replaceSafeOwner
import { EDIT_SAFE_OWNER } from '~/routes/safe/store/actions/editSafeOwner' import { EDIT_SAFE_OWNER } from '~/routes/safe/store/actions/editSafeOwner'
import { SET_DEFAULT_SAFE } from '~/routes/safe/store/actions/setDefaultSafe' import { SET_DEFAULT_SAFE } from '~/routes/safe/store/actions/setDefaultSafe'
import { UPDATE_SAFE_THRESHOLD } from '~/routes/safe/store/actions/updateSafeThreshold' import { UPDATE_SAFE_THRESHOLD } from '~/routes/safe/store/actions/updateSafeThreshold'
import { getWeb3 } from '~/logic/wallets/getWeb3'
export const SAFE_REDUCER_ID = 'safes' export const SAFE_REDUCER_ID = 'safes'
@ -20,7 +21,10 @@ export type SafeReducerState = Map<string, *>
export const buildSafe = (storedSafe: SafeProps) => { export const buildSafe = (storedSafe: SafeProps) => {
const names = storedSafe.owners.map((owner: OwnerProps) => owner.name) const names = storedSafe.owners.map((owner: OwnerProps) => owner.name)
const addresses = storedSafe.owners.map((owner: OwnerProps) => owner.address) const addresses = storedSafe.owners.map((owner: OwnerProps) => {
const checksumed = getWeb3().utils.toChecksumAddress(owner.address)
return checksumed
})
const owners = buildOwnersFrom(Array.from(names), Array.from(addresses)) const owners = buildOwnersFrom(Array.from(names), Array.from(addresses))
const activeTokens = Set(storedSafe.activeTokens) const activeTokens = Set(storedSafe.activeTokens)
const blacklistedTokens = Set(storedSafe.blacklistedTokens) const blacklistedTokens = Set(storedSafe.blacklistedTokens)

View File

@ -18,6 +18,7 @@ import { type Transaction } from '~/routes/safe/store/models/transaction'
import { type Confirmation } from '~/routes/safe/store/models/confirmation' import { type Confirmation } from '~/routes/safe/store/models/confirmation'
import { SAFE_REDUCER_ID } from '~/routes/safe/store/reducer/safe' import { SAFE_REDUCER_ID } from '~/routes/safe/store/reducer/safe'
import type { IncomingTransaction } from '~/routes/safe/store/models/incomingTransaction' import type { IncomingTransaction } from '~/routes/safe/store/models/incomingTransaction'
import { getWeb3 } from '~/logic/wallets/getWeb3'
export type RouterProps = { export type RouterProps = {
match: Match, match: Match,
@ -60,8 +61,10 @@ const incomingTransactionsSelector = (state: GlobalState): IncomingTransactionsS
const oneTransactionSelector = (state: GlobalState, props: TransactionProps) => props.transaction const oneTransactionSelector = (state: GlobalState, props: TransactionProps) => props.transaction
export const safeParamAddressSelector = (state: GlobalState, props: RouterProps) => export const safeParamAddressSelector = (state: GlobalState, props: RouterProps) => {
props.match.params[SAFE_PARAM_ADDRESS] || '' const urlAdd = props.match.params[SAFE_PARAM_ADDRESS]
return urlAdd ? getWeb3().utils.toChecksumAddress(urlAdd) : ''
}
type TxSelectorType = Selector<GlobalState, RouterProps, List<Transaction>> type TxSelectorType = Selector<GlobalState, RouterProps, List<Transaction>>
@ -156,8 +159,8 @@ export const safeSelector: Selector<GlobalState, RouterProps, SafeSelectorProps>
if (!address) { if (!address) {
return undefined return undefined
} }
const checksumed = getWeb3().utils.toChecksumAddress(address)
const safe = safes.get(address) const safe = safes.get(checksumed)
return safe return safe
}, },