Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Commit

Permalink
Fix #597: USD value not load (#609)
Browse files Browse the repository at this point in the history
* Converts all the addresses to checksum values

* Fix for empty address
  • Loading branch information
Agupane authored Feb 21, 2020
1 parent ea6c1f4 commit 1f3f13e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
11 changes: 7 additions & 4 deletions src/routes/safe/store/actions/fetchSafe.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { SafeProps } from '~/routes/safe/store/models/safe'
import addSafe from '~/routes/safe/store/actions/addSafe'
import { getSafeName, getLocalSafe } from '~/logic/safe/utils'
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 removeSafeOwner from '~/routes/safe/store/actions/removeSafeOwner'
import addSafeOwner from '~/routes/safe/store/actions/addSafeOwner'
Expand All @@ -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 ethBalance = await getBalanceInEtherOf(safeAddress)

Expand All @@ -53,7 +54,8 @@ export const buildSafe = async (safeAddress: string, safeName: string) => {
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
const [gnosisSafe, localSafe] = await Promise.all([getGnosisSafeInstanceAt(safeAddress), getLocalSafe(safeAddress)])

Expand Down Expand Up @@ -90,8 +92,9 @@ export const checkAndUpdateSafe = (safeAddress: string) => async (dispatch: Redu
}

// eslint-disable-next-line consistent-return
export default (safeAddress: string) => async (dispatch: ReduxDispatch<GlobalState>) => {
export default (safeAdd: string) => async (dispatch: ReduxDispatch<GlobalState>) => {
try {
const safeAddress = getWeb3().utils.toChecksumAddress(safeAdd)
const safeName = (await getSafeName(safeAddress)) || 'LOADED SAFE'
const safeProps: SafeProps = await buildSafe(safeAddress, safeName)

Expand Down
6 changes: 4 additions & 2 deletions src/routes/safe/store/actions/loadDefaultSafe.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import type { Dispatch as ReduxDispatch } from 'redux'
import { type GlobalState } from '~/store/index'
import { getDefaultSafe } from '~/logic/safe/utils'
import setDefaultSafe from './setDefaultSafe'
import { getWeb3 } from '~/logic/wallets/getWeb3'

const loadDefaultSafe = () => async (dispatch: ReduxDispatch<GlobalState>) => {
try {
const defaultSafe: string = await getDefaultSafe()

dispatch(setDefaultSafe(defaultSafe))
const checksumed =
defaultSafe && defaultSafe.length > 0 ? getWeb3().utils.toChecksumAddress(defaultSafe) : defaultSafe
dispatch(setDefaultSafe(checksumed))
} catch (err) {
// eslint-disable-next-line
console.error('Error while getting default Safe from storage:', err)
Expand Down
6 changes: 5 additions & 1 deletion src/routes/safe/store/reducer/safe.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@ import { REPLACE_SAFE_OWNER } from '~/routes/safe/store/actions/replaceSafeOwner
import { EDIT_SAFE_OWNER } from '~/routes/safe/store/actions/editSafeOwner'
import { SET_DEFAULT_SAFE } from '~/routes/safe/store/actions/setDefaultSafe'
import { UPDATE_SAFE_THRESHOLD } from '~/routes/safe/store/actions/updateSafeThreshold'
import { getWeb3 } from '~/logic/wallets/getWeb3'

export const SAFE_REDUCER_ID = 'safes'

export type SafeReducerState = Map<string, *>

export const buildSafe = (storedSafe: SafeProps) => {
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 activeTokens = Set(storedSafe.activeTokens)
const blacklistedTokens = Set(storedSafe.blacklistedTokens)
Expand Down
11 changes: 7 additions & 4 deletions src/routes/safe/store/selectors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { type Transaction } from '~/routes/safe/store/models/transaction'
import { type Confirmation } from '~/routes/safe/store/models/confirmation'
import { SAFE_REDUCER_ID } from '~/routes/safe/store/reducer/safe'
import type { IncomingTransaction } from '~/routes/safe/store/models/incomingTransaction'
import { getWeb3 } from '~/logic/wallets/getWeb3'

export type RouterProps = {
match: Match,
Expand Down Expand Up @@ -60,8 +61,10 @@ const incomingTransactionsSelector = (state: GlobalState): IncomingTransactionsS

const oneTransactionSelector = (state: GlobalState, props: TransactionProps) => props.transaction

export const safeParamAddressSelector = (state: GlobalState, props: RouterProps) =>
props.match.params[SAFE_PARAM_ADDRESS] || ''
export const safeParamAddressSelector = (state: GlobalState, props: RouterProps) => {
const urlAdd = props.match.params[SAFE_PARAM_ADDRESS]
return urlAdd ? getWeb3().utils.toChecksumAddress(urlAdd) : ''
}

type TxSelectorType = Selector<GlobalState, RouterProps, List<Transaction>>

Expand Down Expand Up @@ -156,8 +159,8 @@ export const safeSelector: Selector<GlobalState, RouterProps, SafeSelectorProps>
if (!address) {
return undefined
}

const safe = safes.get(address)
const checksumed = getWeb3().utils.toChecksumAddress(address)
const safe = safes.get(checksumed)

return safe
},
Expand Down

0 comments on commit 1f3f13e

Please sign in to comment.