Skip to content

Commit 4c290f3

Browse files
committed
added transaction searching and filtering
1 parent f5bc90f commit 4c290f3

File tree

10 files changed

+325
-88
lines changed

10 files changed

+325
-88
lines changed

packages/hooks/src/hooks/Indexer/useGetTransactionHistorySummary.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,19 @@ import { HooksOptions } from '../../types'
66

77
import { useIndexerClients } from './useIndexerClient'
88

9-
export interface GetTransactionHistorySummaryArgs {
10-
accountAddress: string
11-
chainIds: number[]
12-
}
9+
export type GetTransactionHistorySummaryArgs =
10+
| { accountAddress: string; accountAddresses?: never; chainIds: number[] }
11+
| { accountAddress?: never; accountAddresses: string[]; chainIds: number[] }
1312

1413
const getTransactionHistorySummary = async (
1514
indexerClients: Map<number, SequenceIndexer>,
16-
{ accountAddress }: GetTransactionHistorySummaryArgs
15+
{ accountAddress, accountAddresses }: GetTransactionHistorySummaryArgs
1716
): Promise<Transaction[]> => {
1817
const histories = await Promise.all(
1918
Array.from(indexerClients.values()).map(indexerClient =>
2019
indexerClient.getTransactionHistory({
2120
filter: {
22-
accountAddress
21+
accountAddresses: accountAddresses || [accountAddress]
2322
},
2423
includeMetadata: true
2524
})
@@ -55,7 +54,7 @@ export const useGetTransactionHistorySummary = (
5554
refetchOnMount: true,
5655
enabled:
5756
getTransactionHistorySummaryArgs.chainIds.length > 0 &&
58-
!!getTransactionHistorySummaryArgs.accountAddress &&
57+
!!(getTransactionHistorySummaryArgs.accountAddress || (getTransactionHistorySummaryArgs.accountAddresses?.length ?? 0)) &&
5958
!options?.disabled
6059
})
6160
}

packages/wallet-widget/src/components/ListCard/ListCardNav.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,21 @@ export const ListCardNav = ({
1818
return (
1919
<div
2020
className={cn(
21-
'flex flex-row justify-between items-center p-4 bg-background-secondary cursor-pointer hover:opacity-80 w-full',
21+
'flex flex-row justify-between items-center bg-background-secondary cursor-pointer hover:opacity-80 w-full p-4',
2222
shape === 'rounded' ? 'rounded-lg' : 'rounded-none'
2323
)}
2424
style={{ height: '52px', ...style }}
2525
onClick={onClick}
2626
>
27-
<div className="flex flex-row gap-2 items-center">{children}</div>
27+
<div className="flex flex-row gap-2 items-center w-full">{children}</div>
2828

29-
<div className="flex flex-row gap-1 items-center">
30-
{rightChildren}
31-
{type === 'chevron' && <ChevronRightIcon color="white" />}
32-
</div>
29+
{rightChildren ||
30+
(type === 'chevron' && (
31+
<div className="flex flex-row gap-1 items-center">
32+
{rightChildren}
33+
{type === 'chevron' && <ChevronRightIcon color="white" />}
34+
</div>
35+
))}
3336
</div>
3437
)
3538
}

packages/wallet-widget/src/components/SearchLists/CollectiblesList.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ export const CollectiblesList = ({
4343
const isPending = isPendingTokenBalances
4444

4545
const fuseOptions = {
46+
threshold: 0.1,
47+
ignoreLocation: true,
4648
keys: [
4749
{
4850
name: 'name',
@@ -56,8 +58,7 @@ export const CollectiblesList = ({
5658
return token.contractInfo?.name || ''
5759
}
5860
}
59-
],
60-
ignoreLocation: true
61+
]
6162
}
6263

6364
const fuse = useMemo(() => {
@@ -89,6 +90,10 @@ export const CollectiblesList = ({
8990
setIsFilterOpen(true)
9091
}
9192

93+
const onShowCollectibles = () => {
94+
setIsFilterOpen(false)
95+
}
96+
9297
return (
9398
<div className="flex flex-col gap-4 items-center justify-center">
9499
<div className="flex flex-row justify-between items-center w-full gap-2">
@@ -127,7 +132,7 @@ export const CollectiblesList = ({
127132
label="Collectible Filters"
128133
buttonLabel="Show Collectibles"
129134
type="collectibles"
130-
handleButtonPress={() => {}}
135+
handleButtonPress={onShowCollectibles}
131136
/>
132137
)}
133138
</AnimatePresence>

packages/wallet-widget/src/components/SearchLists/TokenList.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ export const TokenList = ({
8585
const isPending = isPendingTokenBalances || isPendingCoinPrices || isPendingConversionRate
8686

8787
const fuseOptions = {
88+
threshold: 0.1,
89+
ignoreLocation: true,
8890
keys: [
8991
{
9092
name: 'name',
@@ -96,8 +98,7 @@ export const TokenList = ({
9698
return token.contractInfo?.name || 'Unknown'
9799
}
98100
}
99-
],
100-
ignoreLocation: true
101+
]
101102
}
102103

103104
const fuse = useMemo(() => {
@@ -129,6 +130,10 @@ export const TokenList = ({
129130
setIsFilterOpen(true)
130131
}
131132

133+
const onShowTokens = () => {
134+
setIsFilterOpen(false)
135+
}
136+
132137
return (
133138
<div className="flex flex-col gap-4 items-center justify-center">
134139
<div className="flex flex-row justify-between items-center w-full gap-2">
@@ -166,7 +171,7 @@ export const TokenList = ({
166171
label="Token Filters"
167172
buttonLabel="Show Tokens"
168173
type="tokens"
169-
handleButtonPress={() => {}}
174+
handleButtonPress={onShowTokens}
170175
/>
171176
)}
172177
</AnimatePresence>

packages/wallet-widget/src/components/SearchLists/TokenList/CoinRow.tsx

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,44 +22,47 @@ export const CoinRow = ({ balance, onTokenClick }: BalanceItemProps) => {
2222
const tokenName = isNativeToken ? nativeTokenInfo.name : balance?.contractInfo?.name || 'Unknown'
2323
const symbol = isNativeToken ? nativeTokenInfo.symbol : balance?.contractInfo?.symbol
2424

25-
const getQuantity = () => {
25+
const quantity = useMemo(() => {
2626
const decimals = isNativeToken ? nativeTokenInfo.decimals : balance?.contractInfo?.decimals
2727
const bal = formatUnits(BigInt(balance.balance), decimals || 0)
2828
const displayBalance = formatDisplay(bal)
2929
const symbol = isNativeToken ? nativeTokenInfo.symbol : balance?.contractInfo?.symbol
3030

3131
return `${displayBalance} ${symbol}`
32-
}
32+
}, [balance])
3333

34-
const getValue = () => {
34+
const value = useMemo(() => {
3535
const decimals = isNativeToken ? nativeTokenInfo.decimals : balance?.contractInfo?.decimals
3636
const bal = formatUnits(BigInt(balance.balance), decimals || 0)
3737
return `${fiatCurrency.sign}${(balance.price.value * Number(bal)).toFixed(2)}`
38-
}
38+
}, [balance, fiatCurrency])
3939

4040
const onClick = () => {
4141
onTokenClick(balance)
4242
}
4343

44-
const balanceAndValue = useMemo(() => {
45-
return (
46-
<div className="flex flex-col items-end">
47-
<Text variant="normal" color="primary" fontWeight="bold" ellipsis>
48-
{getQuantity()}
49-
</Text>
50-
<Text variant="normal" color="muted" fontWeight="bold" ellipsis>
51-
{getValue()}
52-
</Text>
53-
</div>
54-
)
55-
}, [balance])
56-
5744
return (
58-
<ListCardNav rightChildren={balanceAndValue} type="custom" onClick={onClick} style={{ height: '60px' }}>
59-
<TokenImage src={logoURI} symbol={symbol} size="md" withNetwork={balance.chainId} style={{ zIndex: '0' }} />
60-
<Text className="overflow-hidden whitespace-nowrap" variant="normal" color="primary" fontWeight="bold" ellipsis>
61-
{tokenName}
62-
</Text>
45+
<ListCardNav type="custom" onClick={onClick} style={{ height: '60px' }}>
46+
<div className="flex flex-row justify-between w-full gap-2">
47+
<TokenImage src={logoURI} symbol={symbol} size="md" withNetwork={balance.chainId} />
48+
<div className="flex flex-row gap-2 items-center" style={{ flex: '1 1 0', width: 0 }}>
49+
<Text className="overflow-hidden" variant="normal" color="primary" fontWeight="bold" ellipsis>
50+
{tokenName}
51+
</Text>
52+
</div>
53+
<div className="flex flex-row justify-end items-center" style={{ flex: '1 1 0', width: 0 }}>
54+
<div className="flex flex-col items-end w-full">
55+
<div className="flex flex-row justify-end w-full">
56+
<Text className="overflow-hidden" variant="normal" color="primary" fontWeight="bold" ellipsis>
57+
{quantity}
58+
</Text>
59+
</div>
60+
<Text variant="normal" color="muted" fontWeight="bold">
61+
{value}
62+
</Text>
63+
</div>
64+
</div>
65+
</div>
6366
</ListCardNav>
6467
)
6568
}

packages/wallet-widget/src/components/SelectWalletRow.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export const SelectWalletRow = ({
1616
onClose: () => void
1717
}) => {
1818
const onSelectWallet = () => {
19-
console.log(wallet.address)
2019
setActiveWallet(wallet.address)
2120
onClose()
2221
}

packages/wallet-widget/src/components/SlideupDrawer.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ export const SlideupDrawer = ({
3434
left: 0,
3535
width: '100%',
3636
height: '100%',
37-
backgroundColor: 'black'
37+
backgroundColor: 'black',
38+
zIndex: 30
3839
}}
3940
onClick={onClose}
4041
/>
@@ -51,7 +52,8 @@ export const SlideupDrawer = ({
5152
left: 0,
5253
width: '100%',
5354
display: 'flex',
54-
flexDirection: 'column'
55+
flexDirection: 'column',
56+
zIndex: 30
5557
}}
5658
onClick={e => e.stopPropagation()}
5759
>

packages/wallet-widget/src/components/TransactionHistoryList/TransactionHistoryItem.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { TokenPrice } from '@0xsequence/api'
22
import { compareAddress, formatDisplay, getNativeTokenInfoByChainId } from '@0xsequence/connect'
3-
import { ArrowRightIcon, Text, Image, TransactionIcon, Skeleton, NetworkImage } from '@0xsequence/design-system'
3+
import { ArrowRightIcon, Text, TransactionIcon, Skeleton, NetworkImage, TokenImage } from '@0xsequence/design-system'
44
import { useGetCoinPrices, useGetExchangeRate } from '@0xsequence/hooks'
55
import { Transaction, TxnTransfer, TxnTransferType } from '@0xsequence/indexer'
66
import dayjs from 'dayjs'
7-
import React from 'react'
87
import { formatUnits, zeroAddress } from 'viem'
98
import { useConfig } from 'wagmi'
109

@@ -103,7 +102,15 @@ export const TransactionHistoryItem = ({ transaction }: TransactionHistoryItemPr
103102
textColor = 'positive'
104103
}
105104

106-
return <Text variant="normal" fontWeight="bold" color={textColor}>{`${sign}${amount} ${symbol}`}</Text>
105+
return (
106+
<Text
107+
className="overflow-hidden"
108+
variant="normal"
109+
fontWeight="bold"
110+
color={textColor}
111+
ellipsis
112+
>{`${sign}${amount} ${symbol}`}</Text>
113+
)
107114
}
108115

109116
interface GetTransfer {
@@ -144,7 +151,11 @@ export const TransactionHistoryItem = ({ transaction }: TransactionHistoryItemPr
144151
decimals = isNativeToken ? nativeTokenInfo.decimals : transfer.contractInfo?.decimals
145152
}
146153
const amountValue = formatUnits(BigInt(amount), decimals || 18)
147-
const symbol = isNativeToken ? nativeTokenInfo.symbol : transfer.contractInfo?.symbol || ''
154+
const symbol = isNativeToken
155+
? nativeTokenInfo.symbol
156+
: isCollectible
157+
? transfer.contractInfo?.name || ''
158+
: transfer.contractInfo?.symbol || ''
148159
const tokenLogoUri = isNativeToken ? nativeTokenInfo.logoURI : transfer.contractInfo?.logoURI
149160

150161
const fiatConversionRate = coinPrices.find((coinPrice: TokenPrice) =>
@@ -153,8 +164,8 @@ export const TransactionHistoryItem = ({ transaction }: TransactionHistoryItemPr
153164

154165
return (
155166
<div className="flex flex-row justify-between" key={index}>
156-
<div className="flex flex-row gap-2 justify-center items-center">
157-
{tokenLogoUri && <Image className="w-5" src={tokenLogoUri} alt="token logo" />}
167+
<div className="flex flex-row gap-2 justify-start items-center w-full">
168+
{(tokenLogoUri || symbol) && <TokenImage src={tokenLogoUri} symbol={symbol} size="sm" />}
158169
{getTransferAmountLabel(decimals === 0 ? amount : formatDisplay(amountValue), symbol, transfer.transferType)}
159170
</div>
160171
{isPending && <Skeleton style={{ width: '35px', height: '20px' }} />}

0 commit comments

Comments
 (0)