11"use client" ;
22import styled from "@emotion/styled" ;
33import { CheckIcon , CrossCircledIcon } from "@radix-ui/react-icons" ;
4+ import { useQuery } from "@tanstack/react-query" ;
45import { useSyncExternalStore } from "react" ;
6+ import { ethereum } from "../../../../../chains/chain-definitions/ethereum.js" ;
57import { getCachedChain } from "../../../../../chains/utils.js" ;
68import type { ThirdwebClient } from "../../../../../client/client.js" ;
7- import { getTransactionStore } from "../../../../../transaction/transaction-store.js" ;
9+ import {
10+ type StoredTransaction ,
11+ getPastTransactions ,
12+ getTransactionStore ,
13+ } from "../../../../../transaction/transaction-store.js" ;
814import { shortenHex } from "../../../../../utils/address.js" ;
9- import type { Hex } from "../../../../../utils/encoding/hex.js" ;
1015import { formatExplorerTxUrl } from "../../../../../utils/url.js" ;
1116import { useCustomTheme } from "../../../../core/design-system/CustomThemeProvider.js" ;
1217import { iconSize , spacing } from "../../../../core/design-system/index.js" ;
@@ -38,8 +43,20 @@ export function WalletTransactionHistory(props: {
3843 transactionStore . subscribe ,
3944 transactionStore . getValue ,
4045 ) ;
41- const transactions = [ ...reverseChronologicalTransactions ] . reverse ( ) ;
42-
46+ const historicalTxQuery = useQuery ( {
47+ queryKey : [ "transactions" , props . address , activeChain ] ,
48+ queryFn : ( ) =>
49+ getPastTransactions ( {
50+ walletAddress : props . address ,
51+ chain : activeChain || ethereum ,
52+ client : props . client ,
53+ } ) ,
54+ enabled : ! ! activeChain ,
55+ } ) ;
56+ const transactions = [
57+ ...[ ...reverseChronologicalTransactions ] . reverse ( ) ,
58+ ...( historicalTxQuery . data || [ ] ) ,
59+ ] ;
4360 return (
4461 < Container
4562 scrollY
@@ -52,7 +69,22 @@ export function WalletTransactionHistory(props: {
5269 } }
5370 >
5471 < Container flex = "column" gap = "xs" expand >
55- { transactions . length === 0 ? (
72+ { historicalTxQuery . isLoading && (
73+ < Container
74+ flex = "column"
75+ gap = "md"
76+ center = "both"
77+ color = "secondaryText"
78+ style = { {
79+ flex : "1" ,
80+ minHeight : "250px" ,
81+ } }
82+ >
83+ < Spinner color = { "secondaryText" } size = { "md" } />
84+ < Text > Loading recent transactions...</ Text >
85+ </ Container >
86+ ) }
87+ { ! historicalTxQuery . isLoading && transactions . length === 0 ? (
5688 < Container
5789 flex = "column"
5890 gap = "md"
@@ -79,8 +111,7 @@ export function WalletTransactionHistory(props: {
79111 key = { tx . transactionHash }
80112 explorerUrl = { chainExplorers . explorers [ 0 ] ?. url }
81113 client = { props . client }
82- hash = { tx . transactionHash }
83- chainId = { tx . chainId }
114+ tx = { tx }
84115 />
85116 ) ;
86117 } ) }
@@ -92,21 +123,24 @@ export function WalletTransactionHistory(props: {
92123}
93124
94125function TransactionButton ( props : {
95- hash : string ;
126+ tx : StoredTransaction ;
96127 client : ThirdwebClient ;
97- chainId : number ;
98128 explorerUrl ?: string ;
99129} ) {
100130 const {
101- data : receipt ,
131+ data : fetchedReceipt ,
102132 isLoading,
103133 error,
104134 } = useWaitForReceipt ( {
105- transactionHash : props . hash as Hex ,
106- chain : getCachedChain ( props . chainId ) ,
135+ transactionHash : props . tx . transactionHash ,
136+ chain : getCachedChain ( props . tx . chainId ) ,
107137 client : props . client ,
138+ queryOptions : {
139+ enabled : props . tx . receipt === undefined ,
140+ } ,
108141 } ) ;
109- const chainIconQuery = useChainIconUrl ( getCachedChain ( props . chainId ) ) ;
142+ const chainIconQuery = useChainIconUrl ( getCachedChain ( props . tx . chainId ) ) ;
143+ const receipt = props . tx . receipt ?? fetchedReceipt ;
110144
111145 const content = (
112146 < TxButton
@@ -148,8 +182,8 @@ function TransactionButton(props: {
148182 >
149183 < Text size = "sm" color = "primaryText" >
150184 { receipt ?. to
151- ? `Interacted with ${ shortenHex ( receipt . to , 4 ) } `
152- : `Hash: ${ shortenHex ( props . hash , 4 ) } ` }
185+ ? `Interacted with ${ shortenHex ( receipt ? .to , 4 ) } `
186+ : `Hash: ${ shortenHex ( props . tx . transactionHash , 4 ) } ` }
153187 </ Text >
154188 </ Container >
155189
@@ -165,7 +199,7 @@ function TransactionButton(props: {
165199 } }
166200 >
167201 < ChainName
168- chain = { getCachedChain ( props . chainId ) }
202+ chain = { getCachedChain ( props . tx . chainId ) }
169203 size = "xs"
170204 client = { props . client }
171205 />
@@ -193,7 +227,7 @@ function TransactionButton(props: {
193227 if ( props . explorerUrl ) {
194228 return (
195229 < a
196- href = { formatExplorerTxUrl ( props . explorerUrl , props . hash ) }
230+ href = { formatExplorerTxUrl ( props . explorerUrl , props . tx . transactionHash ) }
197231 target = "_blank"
198232 rel = "noreferrer"
199233 >
0 commit comments