WA-238 sameAddress helper for avoid case sensitive problems with eth addresses

This commit is contained in:
apanizo 2018-05-27 14:12:29 +02:00
parent 194e51d207
commit f917bb2abd
5 changed files with 16 additions and 13 deletions

View File

@ -7,6 +7,7 @@ import { makeTransaction, type Transaction, type TransactionProps } from '~/rout
import { getGnosisSafeContract } from '~/wallets/safeContracts'
import { getWeb3 } from '~/wallets/getWeb3'
import { type Safe } from '~/routes/safe/store/model/safe'
import { sameAddress } from '~/wallets/ethAddresses'
export const TX_NAME_PARAM = 'txName'
export const TX_DESTINATION_PARAM = 'txDestination'
@ -21,14 +22,14 @@ export const buildConfirmationsFrom =
throw new Error('This safe has no owners')
}
if (!owners.find((owner: Owner) => owner.get('address').toLowerCase() === creator.toLowerCase())) {
if (!owners.find((owner: Owner) => sameAddress(owner.get('address'), creator))) {
throw new Error('The creator of the tx is not an owner')
}
return owners.map((owner: Owner) => makeConfirmation({
owner,
status: owner.get('address') === creator,
hash: owner.get('address') === creator ? confirmationHash : undefined,
status: sameAddress(owner.get('address'), creator),
hash: sameAddress(owner.get('address'), creator) ? confirmationHash : undefined,
}))
}

View File

@ -6,6 +6,7 @@ import { type Confirmation, makeConfirmation } from '~/routes/safe/store/model/c
import { makeTransaction, type Transaction, type TransactionProps } from '~/routes/safe/store/model/transaction'
import { getGnosisSafeContract } from '~/wallets/safeContracts'
import { getWeb3 } from '~/wallets/getWeb3'
import { sameAddress } from '~/wallets/ethAddresses'
import { EXECUTED_CONFIRMATION_HASH } from '~/routes/safe/component/AddTransaction/createTransactions'
export const updateTransaction = (
@ -72,8 +73,9 @@ const execConfirmation = async (
const updateConfirmations = (confirmations: List<Confirmation>, userAddress: string, txHash: string) =>
confirmations.map((confirmation: Confirmation) => {
const owner: Owner = confirmation.get('owner')
const status: boolean = owner.get('address') === userAddress ? true : confirmation.get('status')
const hash: string = owner.get('address') === userAddress ? txHash : confirmation.get('hash')
const samePerson = sameAddress(owner.get('address'), userAddress)
const status: boolean = samePerson ? true : confirmation.get('status')
const hash: string = samePerson ? txHash : confirmation.get('hash')
return makeConfirmation({ owner, status, hash })
})
@ -91,7 +93,7 @@ export const processTransaction = async (
const confirmations = tx.get('confirmations')
const userHasAlreadyConfirmed = confirmations.filter((confirmation: Confirmation) => {
const ownerAddress = confirmation.get('owner').get('address')
const samePerson = ownerAddress === userAddress
const samePerson = sameAddress(ownerAddress, userAddress)
return samePerson && confirmation.get('status')
}).count() > 0

View File

@ -6,6 +6,7 @@ import { providerNameSelector, userAccountSelector } from '~/wallets/store/selec
import { type Safe } from '~/routes/safe/store/model/safe'
import { type Owner } from '~/routes/safe/store/model/owner'
import { type GlobalState } from '~/store/index'
import { sameAddress } from '~/wallets/ethAddresses'
export type SelectorProps = {
safe: SafeSelectorProps,
@ -30,7 +31,7 @@ export const grantedSelector: Selector<GlobalState, RouterProps, boolean> = crea
return false
}
return owners.find((owner: Owner) => owner.get('address').toLocaleLowerCase() === userAccount.toLocaleLowerCase()) !== undefined
return owners.find((owner: Owner) => sameAddress(owner.get('address'), userAccount)) !== undefined
},
)

View File

@ -5,6 +5,7 @@ import { type GlobalState } from '~/store/index'
import { type Safe } from '~/routes/safe/store/model/safe'
import { userAccountSelector } from '~/wallets/store/selectors/index'
import { type Owner } from '~/routes/safe/store/model/owner'
import { sameAddress } from '~/wallets/ethAddresses'
export const safesMapSelector = (state: GlobalState): Map<string, Safe> => state.safes
const safesListSelector: Selector<GlobalState, {}, List<Safe>> = createSelector(
@ -17,10 +18,5 @@ export const safesByOwnerSelector: Selector<GlobalState, {}, List<Safe>> = creat
safesListSelector,
(userAddress: string, safes: List<Safe>): List<Safe> =>
safes.filter((safe: Safe) =>
safe.owners.filter((owner: Owner) => {
const ownerLower = owner.get('address').toLowerCase()
const userLower = userAddress.toLowerCase()
return ownerLower === userLower
}).count() > 0),
safe.owners.filter((owner: Owner) => sameAddress(owner.get('address'), userAddress)).count() > 0),
)

View File

@ -0,0 +1,3 @@
// @flow
export const sameAddress = (firstAddress: string, secondAddress: string): boolean =>
firstAddress.toLowerCase() === secondAddress.toLowerCase()