From b87cbda011587f3659252dda81d9e15709df5ab2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Sant=C3=A1ngelo?= Date: Thu, 27 May 2021 17:16:25 -0300 Subject: [PATCH] feat: compare addresses util --- src/modules/authorization/utils.ts | 7 ++++--- src/modules/transaction/sagas.ts | 5 +++-- src/modules/transaction/selectors.ts | 11 ++++++----- src/modules/wallet/utils.ts | 7 +++++++ 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/modules/authorization/utils.ts b/src/modules/authorization/utils.ts index ffc87c2f..ac2bd839 100644 --- a/src/modules/authorization/utils.ts +++ b/src/modules/authorization/utils.ts @@ -1,4 +1,5 @@ import { toBN } from 'web3x-es/utils' +import { isSameAddress } from '../wallet/utils' import { Authorization, AuthorizationType } from './types' export function getTokenAmountToApprove(): ReturnType { @@ -19,9 +20,9 @@ export function hasAuthorization( export function areEqual(left: Authorization, right: Authorization) { return ( left.type === right.type && - left.authorizedAddress === right.authorizedAddress && - left.contractAddress === right.contractAddress && - left.chainId === right.chainId + left.chainId === right.chainId && + isSameAddress(left.authorizedAddress, right.authorizedAddress) && + isSameAddress(left.contractAddress, right.contractAddress) ) } diff --git a/src/modules/transaction/sagas.ts b/src/modules/transaction/sagas.ts index 27b3ad56..37b6aacd 100644 --- a/src/modules/transaction/sagas.ts +++ b/src/modules/transaction/sagas.ts @@ -45,6 +45,7 @@ import { import { isPending, buildActionRef } from './utils' import { getTransaction as getTransactionFromChain } from './txUtils' import { getAddress } from '../wallet/selectors' +import { isSameAddress } from '../wallet/utils' import { getConnectedProvider } from '../../lib/eth' export function* transactionSaga(): IterableIterator { @@ -239,13 +240,13 @@ function* handleReplaceTransactionRequest( // look for a replacement tx, if so break the loop replacedBy = transactions.find( - tx => tx.nonce === nonce && tx.from.toString() === account + tx => tx.nonce === nonce && isSameAddress(tx.from, account) ) if (replacedBy) break // if no replacement is found, keep track of the highest nonce for the account highestNonce = transactions - .filter(tx => tx.from.toString() === account) + .filter(tx => isSameAddress(tx.from, account)) .reduce((max, tx) => Math.max(max, tx.nonce), highestNonce) } diff --git a/src/modules/transaction/selectors.ts b/src/modules/transaction/selectors.ts index 5a272bbd..162743e1 100644 --- a/src/modules/transaction/selectors.ts +++ b/src/modules/transaction/selectors.ts @@ -1,3 +1,4 @@ +import { isSameAddress } from '../wallet/utils' import { Transaction, TransactionStatus } from './types' import { TransactionState } from './reducer' import { isPending } from './utils' @@ -23,12 +24,12 @@ export const getTransactionsByStatus = ( status: TransactionStatus ): Transaction[] => getData(state) - .filter(tx => tx.from === address && tx.status === status) + .filter(tx => isSameAddress(tx.from, address) && tx.status === status) .sort(sortByTimestamp) export const getTransactions = (state: any, address: string): Transaction[] => getData(state) - .filter(tx => tx.from === address) + .filter(tx => isSameAddress(tx.from, address)) .sort(sortByTimestamp) export const getPendingTransactions = ( @@ -36,7 +37,7 @@ export const getPendingTransactions = ( address: string ): Transaction[] => getData(state) - .filter(tx => tx.from === address && isPending(tx.status)) + .filter(tx => isSameAddress(tx.from, address) && isPending(tx.status)) .sort(sortByTimestamp) export const getTransactionHistory = ( @@ -44,7 +45,7 @@ export const getTransactionHistory = ( address: string ): Transaction[] => getData(state) - .filter(tx => tx.from === address && !isPending(tx.status)) + .filter(tx => isSameAddress(tx.from, address) && !isPending(tx.status)) .sort(sortByTimestamp) export const getTransactionsByType = ( @@ -53,5 +54,5 @@ export const getTransactionsByType = ( type: string ): Transaction[] => getData(state) - .filter(tx => tx.from === address && tx.actionType === type) + .filter(tx => isSameAddress(tx.from, address) && tx.actionType === type) .sort(sortByTimestamp) diff --git a/src/modules/wallet/utils.ts b/src/modules/wallet/utils.ts index 58bf09f3..d8c34f07 100644 --- a/src/modules/wallet/utils.ts +++ b/src/modules/wallet/utils.ts @@ -71,3 +71,10 @@ export async function buildWallet(): Promise { chainId } } + +export function isSameAddress( + address1: Address | string, + address2: Address | string +) { + return address1.toString().toLowerCase() === address2.toString().toLowerCase() +}