Skip to content

Commit

Permalink
feat: compare addresses util
Browse files Browse the repository at this point in the history
  • Loading branch information
nicosantangelo committed May 27, 2021
1 parent 7b074d0 commit 8160dea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/modules/transaction/selectors.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isSameAddress } from '../wallet/utils'
import { Transaction, TransactionStatus } from './types'
import { TransactionState } from './reducer'
import { isPending } from './utils'
Expand All @@ -23,28 +24,28 @@ 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 = (
state: any,
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 = (
state: any,
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 = (
Expand All @@ -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)
4 changes: 4 additions & 0 deletions src/modules/wallet/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,7 @@ export async function buildWallet(): Promise<Wallet> {
chainId
}
}

export function isSameAddress(address1: string, address2: string) {
return address1.toLowerCase() === address2.toLowerCase()
}

0 comments on commit 8160dea

Please sign in to comment.