diff --git a/src/routes/safe/component/AddTransaction/createTransactions.js b/src/routes/safe/component/AddTransaction/createTransactions.js index c29be7d0..f13db071 100644 --- a/src/routes/safe/component/AddTransaction/createTransactions.js +++ b/src/routes/safe/component/AddTransaction/createTransactions.js @@ -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, })) } diff --git a/src/routes/safe/component/Transactions/processTransactions.js b/src/routes/safe/component/Transactions/processTransactions.js index cffea581..b84ebb53 100644 --- a/src/routes/safe/component/Transactions/processTransactions.js +++ b/src/routes/safe/component/Transactions/processTransactions.js @@ -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, 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 diff --git a/src/routes/safe/container/selector.js b/src/routes/safe/container/selector.js index 4e3fbf83..e3451292 100644 --- a/src/routes/safe/container/selector.js +++ b/src/routes/safe/container/selector.js @@ -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 = 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 }, ) diff --git a/src/routes/safeList/store/selectors/index.js b/src/routes/safeList/store/selectors/index.js index 93989643..40ed28b4 100644 --- a/src/routes/safeList/store/selectors/index.js +++ b/src/routes/safeList/store/selectors/index.js @@ -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 => state.safes const safesListSelector: Selector> = createSelector( @@ -17,10 +18,5 @@ export const safesByOwnerSelector: Selector> = creat safesListSelector, (userAddress: string, safes: List): List => 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), ) diff --git a/src/wallets/ethAddresses.js b/src/wallets/ethAddresses.js new file mode 100644 index 00000000..ed301735 --- /dev/null +++ b/src/wallets/ethAddresses.js @@ -0,0 +1,3 @@ +// @flow +export const sameAddress = (firstAddress: string, secondAddress: string): boolean => + firstAddress.toLowerCase() === secondAddress.toLowerCase()