@@ -10,18 +10,18 @@ import {
10
10
TableHeader ,
11
11
TableRow ,
12
12
} from "@/components/ui/table/table" ;
13
- import { ID_TO_APPKIT_NETWORK , NETWORK_TO_ID } from "@/lib/constants/chains" ;
13
+ import { NETWORK_TO_ID } from "@/lib/constants/chains" ;
14
14
import { handleBatchPayment } from "@/lib/helpers/batch-payment" ;
15
15
import {
16
16
calculateTotalsByCurrency ,
17
17
formatCurrencyTotals ,
18
18
} from "@/lib/helpers/currency" ;
19
+ import { useSwitchNetwork } from "@/lib/hooks/use-switch-network" ;
19
20
import type { Request } from "@/server/db/schema" ;
20
21
import { api } from "@/trpc/react" ;
21
22
import {
22
23
useAppKit ,
23
24
useAppKitAccount ,
24
- useAppKitNetwork ,
25
25
useAppKitProvider ,
26
26
} from "@reown/appkit/react" ;
27
27
import { ethers } from "ethers" ;
@@ -73,7 +73,7 @@ export const InvoicesReceived = ({
73
73
const { open } = useAppKit ( ) ;
74
74
const { isConnected, address } = useAppKitAccount ( ) ;
75
75
const { walletProvider } = useAppKitProvider ( "eip155" ) ;
76
- const { chainId , switchNetwork } = useAppKitNetwork ( ) ;
76
+ const { switchToChainId } = useSwitchNetwork ( ) ;
77
77
78
78
const { data : invoices } = api . invoice . getAllIssuedToMe . useQuery ( undefined , {
79
79
initialData : initialReceivedInvoices ,
@@ -134,27 +134,12 @@ export const InvoicesReceived = ({
134
134
return ;
135
135
}
136
136
137
- const targetChain =
138
- NETWORK_TO_ID [ lastSelectedNetwork as keyof typeof NETWORK_TO_ID ] ;
139
-
140
- if ( targetChain !== chainId ) {
141
- const targetAppkitNetwork =
142
- ID_TO_APPKIT_NETWORK [ targetChain as keyof typeof ID_TO_APPKIT_NETWORK ] ;
137
+ try {
138
+ const targetChainId =
139
+ NETWORK_TO_ID [ lastSelectedNetwork as keyof typeof NETWORK_TO_ID ] ;
143
140
144
- toast ( "Switching to network" , {
145
- description : `Switching to ${ targetAppkitNetwork . name } network` ,
146
- } ) ;
141
+ await switchToChainId ( targetChainId ) ;
147
142
148
- try {
149
- switchNetwork ( targetAppkitNetwork ) ;
150
- } catch ( _ ) {
151
- toast ( "Error switching network" ) ;
152
- setIsPayingInvoices ( false ) ;
153
- return ;
154
- }
155
- }
156
-
157
- try {
158
143
const ethersProvider = new ethers . providers . Web3Provider (
159
144
walletProvider as ethers . providers . ExternalProvider ,
160
145
) ;
0 commit comments