Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add tx search ability to tx history #2104

Draft
wants to merge 74 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
92c55e7
feat: top nav bar
fionnachan Nov 11, 2024
9862a54
feat: move tx history
fionnachan Nov 11, 2024
b138480
dynamic height table
fionnachan Nov 12, 2024
d712e97
update mobile view
fionnachan Nov 13, 2024
15b4838
fix deleted imports
fionnachan Nov 13, 2024
38eb8cf
Merge remote-tracking branch 'origin/master' into new-layout-tx-history
fionnachan Nov 13, 2024
9e6599f
hide status info box when loading
fionnachan Nov 13, 2024
45ebcc0
Merge remote-tracking branch 'origin/master' into new-layout-tx-history
fionnachan Nov 14, 2024
d15fd5e
add transaction status dot to tab
fionnachan Nov 14, 2024
8f12203
move hook for reuse
fionnachan Nov 15, 2024
2ae703e
update
fionnachan Nov 15, 2024
7bf8023
auto open tx history tab after tx
fionnachan Nov 15, 2024
f474f5a
Merge remote-tracking branch 'origin/master' into new-layout-tx-history
fionnachan Nov 15, 2024
b58eb07
Merge remote-tracking branch 'origin/master' into new-layout-tx-history
fionnachan Nov 18, 2024
c8cb03d
update e2e
fionnachan Nov 18, 2024
5707d7d
update e2e
fionnachan Nov 18, 2024
96909cc
Merge remote-tracking branch 'origin/master' into new-layout-tx-history
fionnachan Nov 18, 2024
6f1fe21
fix e2es
fionnachan Nov 19, 2024
1b917f3
try
fionnachan Nov 19, 2024
0074ee4
comment
fionnachan Nov 19, 2024
85737a1
Merge remote-tracking branch 'origin/master' into new-layout-tx-history
fionnachan Nov 19, 2024
0f2fd12
Merge branch 'master' into new-layout-tx-history
fionnachan Nov 22, 2024
0281d6a
Merge remote-tracking branch 'origin/master' into new-layout-tx-history
fionnachan Nov 25, 2024
a6c49af
try to relaod the page
fionnachan Nov 25, 2024
638f0bd
Merge remote-tracking branch 'origin/master' into new-layout-tx-history
fionnachan Nov 25, 2024
bc8bb03
set local storage before revisiting
fionnachan Nov 25, 2024
015c182
try -_-
fionnachan Nov 25, 2024
c3b1b0c
remove buy panel thing
fionnachan Nov 26, 2024
f3e6eeb
remove unnecessary code
fionnachan Nov 26, 2024
6af89c7
address review comments
fionnachan Nov 26, 2024
19838c9
feat: add wallet address field
fionnachan Nov 15, 2024
2664637
ux update
fionnachan Nov 19, 2024
923515f
update
fionnachan Nov 21, 2024
f251bd4
add invalid address error
fionnachan Nov 22, 2024
44fd863
update error message screen
fionnachan Nov 22, 2024
ac33b12
remove file
fionnachan Nov 26, 2024
f7ab1ad
Merge remote-tracking branch 'origin/new-layout-tx-history' into tx-h…
fionnachan Nov 26, 2024
aa9970d
fix merge conflicts
fionnachan Nov 26, 2024
9be68c4
use enum as type
fionnachan Nov 26, 2024
0d90fa1
update name
fionnachan Nov 26, 2024
6658707
Merge branch 'new-layout-tx-history' into tx-history-search-field
fionnachan Nov 26, 2024
468c546
fix merge conflict dropped code
fionnachan Nov 26, 2024
c95f81b
address review comments
fionnachan Nov 26, 2024
5e36d69
feat: search by tx hash
fionnachan Nov 26, 2024
ac5acd0
wip
fionnachan Nov 27, 2024
009d66f
wip
fionnachan Nov 28, 2024
88bbce2
Merge remote-tracking branch 'origin/master' into tx-history-search-f…
fionnachan Nov 29, 2024
c664f08
Merge branch 'tx-history-search-field' into search-by-tx-hash
fionnachan Nov 29, 2024
dcd6069
Merge remote-tracking branch 'origin/master' into search-by-tx-hash
fionnachan Nov 29, 2024
e0e6d99
make search by tx id work
fionnachan Nov 29, 2024
46e5187
hide address search results when tx id search is active
fionnachan Nov 29, 2024
94c5a38
clean up
fionnachan Nov 29, 2024
8483068
fix type
fionnachan Nov 29, 2024
f3545d9
Merge remote-tracking branch 'origin/master' into search-by-tx-hash
fionnachan Dec 9, 2024
8f3c36d
Merge remote-tracking branch 'origin/master' into search-by-tx-hash
fionnachan Dec 10, 2024
7b090df
wip
fionnachan Dec 10, 2024
ee4f4eb
Merge remote-tracking branch 'origin/master' into search-by-tx-hash
fionnachan Dec 10, 2024
d088385
wip
fionnachan Dec 10, 2024
6da24bf
Merge remote-tracking branch 'origin/master' into search-by-tx-hash
fionnachan Dec 17, 2024
f39e8e9
update
fionnachan Dec 18, 2024
21761e5
Merge remote-tracking branch 'origin/master' into search-by-tx-hash
fionnachan Dec 18, 2024
5239c68
wip
fionnachan Dec 18, 2024
f3b3a5a
Merge remote-tracking branch 'origin/master' into search-by-tx-hash
fionnachan Dec 19, 2024
f2504b8
Merge remote-tracking branch 'origin/master' into search-by-tx-hash
fionnachan Dec 19, 2024
1b06aff
add more code
fionnachan Dec 19, 2024
52f7bed
update fn wip
fionnachan Dec 20, 2024
67f4b32
Merge remote-tracking branch 'origin/master' into search-by-tx-hash
fionnachan Dec 23, 2024
06c982e
Merge remote-tracking branch 'origin/master' into search-by-tx-hash
fionnachan Dec 23, 2024
a5d7e21
update
fionnachan Dec 23, 2024
5bea6a6
wip for token deposit event log
fionnachan Dec 24, 2024
b566e34
Merge remote-tracking branch 'origin/master' into search-by-tx-hash
fionnachan Dec 24, 2024
2c5b4cb
update
fionnachan Dec 24, 2024
6af7e9f
clean up get token deposits from event log a bit
fionnachan Dec 27, 2024
cf8b139
Merge remote-tracking branch 'origin/master' into search-by-tx-hash
fionnachan Dec 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { create } from 'zustand'

import { MergedTransaction } from '../../state/app/state'
import { TransactionHistorySearchBar } from './TransactionHistorySearchBar'
import { TransactionHistorySearchResults } from './TransactionHistorySearchResults'
import { TransactionHistoryTxHashSearchResult } from './TransactionHistoryTxHashSearch/TransactionHistoryTxHashSearchResult'
import { TransactionHistoryAddressSearchResults } from './TransactionHistoryAddressSearchResults'
import { TransactionsTableDetails } from './TransactionsTableDetails'

type TxDetailsStore = {
tx: MergedTransaction | null
Expand Down Expand Up @@ -35,7 +37,11 @@ export const TransactionHistory = () => {
<div className="m-auto w-full max-w-[100vw] border-y border-white/30 bg-[#191919] py-4 pl-4 md:max-w-[1000px] md:rounded md:border-x md:pr-4">
<TransactionHistorySearchBar />

<TransactionHistorySearchResults />
<TransactionHistoryTxHashSearchResult />

<TransactionHistoryAddressSearchResults />

<TransactionsTableDetails />
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import dayjs from 'dayjs'
import { useEffect, useMemo } from 'react'
import { Tab } from '@headlessui/react'

import { MergedTransaction } from '../../state/app/state'
import {
ContentWrapper,
TransactionHistoryTable
} from './TransactionHistoryTable'
import { TransactionStatusInfo } from './TransactionStatusInfo'
import {
isTxClaimable,
isTxCompleted,
isTxExpired,
isTxFailed,
isTxPending
} from './helpers'
import { TabButton } from '../common/Tab'
import { TransactionsTableDetails } from './TransactionsTableDetails'
import { useTransactionHistory } from '../../hooks/useTransactionHistory'
import { useTransactionHistoryAddressStore } from './TransactionHistorySearchBar'

function useTransactionHistoryUpdater() {
const { sanitizedAddress } = useTransactionHistoryAddressStore()

const transactionHistoryProps = useTransactionHistory(sanitizedAddress, {
runFetcher: true
})

const { transactions, updatePendingTransaction } = transactionHistoryProps

const pendingTransactions = useMemo(() => {
return transactions.filter(isTxPending)
}, [transactions])

useEffect(() => {
const interval = setInterval(() => {
pendingTransactions.forEach(updatePendingTransaction)
}, 10_000)

return () => clearInterval(interval)
}, [pendingTransactions, updatePendingTransaction])

return transactionHistoryProps
}

const tabClasses =
'text-white px-3 mr-2 border-b-2 ui-selected:border-white ui-not-selected:border-transparent ui-not-selected:text-white/80 arb-hover'

export function TransactionHistoryAddressSearchResults() {
const { sanitizedTxHash } = useTransactionHistoryAddressStore()
const props = useTransactionHistoryUpdater()
const { transactions } = props
const { searchError } = useTransactionHistoryAddressStore()

const oldestTxTimeAgoString = useMemo(() => {
return dayjs(transactions[transactions.length - 1]?.createdAt).toNow(true)
}, [transactions])

const groupedTransactions = useMemo(
() =>
transactions.reduce(
(acc, tx) => {
if (isTxCompleted(tx) || isTxExpired(tx)) {
acc.settled.push(tx)
}
if (isTxPending(tx)) {
acc.pending.push(tx)
}
if (isTxClaimable(tx)) {
acc.claimable.push(tx)
}
if (isTxFailed(tx)) {
acc.failed.push(tx)
}
return acc
},
{
settled: [] as MergedTransaction[],
pending: [] as MergedTransaction[],
claimable: [] as MergedTransaction[],
failed: [] as MergedTransaction[]
}
),
[transactions]
)

const pendingTransactions = [
...groupedTransactions.failed,
...groupedTransactions.pending,
...groupedTransactions.claimable
]

const settledTransactions = groupedTransactions.settled

if (typeof sanitizedTxHash !== 'undefined') {
// show search by tx id results instead
return null
}

if (searchError) {
return (
<ContentWrapper>
<p>{searchError}</p>
</ContentWrapper>
)
}

return (
<>
<div className="pr-4 md:pr-0">
<TransactionStatusInfo />
</div>
<Tab.Group as="div" className="h-full overflow-hidden rounded md:pr-0">
<Tab.List className="mb-4 flex border-b border-white/30">
<TabButton
aria-label="show pending transactions"
className={tabClasses}
>
<span className="text-sm md:text-base">Pending transactions</span>
</TabButton>
<TabButton
aria-label="show settled transactions"
className={tabClasses}
>
<span className="text-sm md:text-base">Settled transactions</span>
</TabButton>
</Tab.List>

<Tab.Panels className="h-full w-full overflow-hidden">
<Tab.Panel className="h-full w-full">
<TransactionHistoryTable
{...props}
transactions={pendingTransactions}
selectedTabIndex={0}
oldestTxTimeAgoString={oldestTxTimeAgoString}
/>
</Tab.Panel>
<Tab.Panel className="h-full w-full">
<TransactionHistoryTable
{...props}
transactions={settledTransactions}
selectedTabIndex={1}
oldestTxTimeAgoString={oldestTxTimeAgoString}
/>
</Tab.Panel>
</Tab.Panels>
</Tab.Group>
<TransactionsTableDetails />
</>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,60 +6,89 @@ import { MagnifyingGlassIcon } from '@heroicons/react/24/outline'
import { twMerge } from 'tailwind-merge'

import { Button } from '../common/Button'
import { isValidTxHash } from './helpers'

export enum TransactionHistorySearchError {
INVALID_ADDRESS = 'That doesn’t seem to be a valid address, please try again.'
}

type TransactionHistoryAddressStore = {
address: string
addressOrTxHash: string
sanitizedAddress: Address | undefined
sanitizedTxHash: string | undefined
searchError: TransactionHistorySearchError | undefined
setAddress: (address: string) => void
setAddressOrTxHash: (addressOrTxHash: string) => void
setSanitizedAddress: (address: string) => void
setSanitizedTxHash: (txHash: string | undefined) => void
setSearchError: (error: TransactionHistorySearchError | undefined) => void
}

export const useTransactionHistoryAddressStore =
create<TransactionHistoryAddressStore>(set => ({
address: '',
addressOrTxHash: '',
sanitizedAddress: undefined,
setAddress: (address: string) => set({ address }),
setAddressOrTxHash: (addressOrTxHash: string) => set({ addressOrTxHash }),
setSanitizedAddress: (address: string) => {
if (isAddress(address)) {
set({ sanitizedAddress: address })
}
},
sanitizedTxHash: undefined,
setSanitizedTxHash: (txHash: string | undefined) => {
if (isValidTxHash(txHash)) {
set({
sanitizedTxHash: txHash
})
}

if (typeof txHash === 'undefined') {
set({
sanitizedTxHash: undefined
})
}
},
searchError: undefined,
setSearchError: (error: TransactionHistorySearchError | undefined) =>
set({ searchError: error })
}))

export function TransactionHistorySearchBar() {
const { address, setAddress, setSanitizedAddress, setSearchError } =
useTransactionHistoryAddressStore()
const {
addressOrTxHash,
setAddressOrTxHash,
setSanitizedAddress,
setSanitizedTxHash,
setSearchError
} = useTransactionHistoryAddressStore()
const { address: connectedAddress } = useAccount()

useEffect(() => {
if (address === '' && connectedAddress) {
if (addressOrTxHash === '' && connectedAddress) {
setSanitizedAddress(connectedAddress)
setSanitizedTxHash(undefined)
setSearchError(undefined)
}
}, [address, connectedAddress, setSanitizedAddress, setSearchError])
}, [addressOrTxHash, connectedAddress, setSanitizedAddress, setSearchError])

const searchTxForAddress = useCallback(() => {
if (address === '') {
if (addressOrTxHash === '') {
return
}

if (isValidTxHash(addressOrTxHash)) {
setSanitizedTxHash(addressOrTxHash)
setSearchError(undefined)
return
}

if (!isAddress(address)) {
if (!isAddress(addressOrTxHash)) {
setSearchError(TransactionHistorySearchError.INVALID_ADDRESS)
return
}

setSanitizedAddress(address)
setSanitizedAddress(addressOrTxHash)
setSearchError(undefined)
}, [address, setSanitizedAddress, setSearchError])
}, [addressOrTxHash, setSanitizedAddress, setSanitizedTxHash, setSearchError])

return (
<div className="mb-4 flex flex-row items-stretch pr-4 md:pr-0">
Expand All @@ -72,10 +101,10 @@ export function TransactionHistorySearchBar() {
<MagnifyingGlassIcon className="ml-3 mr-1 h-3 w-3" />
<input
type="text"
value={address}
onChange={event => setAddress(event.target.value)}
value={addressOrTxHash}
onChange={event => setAddressOrTxHash(event.target.value)}
inputMode="search"
placeholder="Search by address"
placeholder="Search by address or transaction hash"
aria-label="Transaction history wallet address input"
className="h-full w-full bg-transparent py-1 pl-1 pr-3 text-sm font-light placeholder:text-white/60"
// stop password managers from autofilling
Expand All @@ -91,7 +120,7 @@ export function TransactionHistorySearchBar() {
'disabled:border-y-0 disabled:border-r-0 disabled:border-l-gray-dark'
)}
onClick={searchTxForAddress}
disabled={!address}
disabled={!addressOrTxHash}
>
Search
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { TransactionsTableRow } from './TransactionsTableRow'
import { EmptyTransactionHistory } from './EmptyTransactionHistory'
import { MergedTransaction } from '../../state/app/state'
import { useNativeCurrency } from '../../hooks/useNativeCurrency'
import { TABLE_HEADER_HEIGHT, TABLE_ROW_HEIGHT } from './constants'

export const BatchTransferNativeTokenTooltip = ({
children,
Expand Down Expand Up @@ -65,7 +66,7 @@ export const ContentWrapper = forwardRef<

ContentWrapper.displayName = 'ContentWrapper'

const TableHeader = ({
export const TableHeader = ({
children,
className
}: PropsWithChildren<{ className?: string }>) => (
Expand Down Expand Up @@ -148,8 +149,6 @@ export const TransactionHistoryTable = (
oldestTxTimeAgoString
} = props

const TABLE_HEADER_HEIGHT = 52
const TABLE_ROW_HEIGHT = 60
const isTxHistoryEmpty = transactions.length === 0
const isPendingTab = selectedTabIndex === 0

Expand Down
Loading
Loading