-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update transaction handling to use AA hook
- Loading branch information
Showing
7 changed files
with
128 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use client' | ||
import { useEffect } from 'react' | ||
import { arbitrum, base } from '@account-kit/infra' | ||
import { useChain } from '@account-kit/react' | ||
import { humanNetworktoSDKNetwork, subgraphNetworkToId } from '@summerfi/app-utils' | ||
import { useParams } from 'next/navigation' | ||
|
||
import { NetworkIds } from '@/constants/networks-list' | ||
import { useClientChainId } from '@/hooks/use-client-chain-id' | ||
|
||
export const networkIdsToAccountKitChainsMap = { | ||
[NetworkIds.BASEMAINNET]: base, | ||
[NetworkIds.ARBITRUMMAINNET]: arbitrum, | ||
} | ||
|
||
// Update account kit network based on app network derived from currently displayed strategy | ||
// To avoid forced EOA popups to change network, trigger it only when EOA wallet network and app network are already aligned | ||
export const useUpdateAANetwork = () => { | ||
const { clientChainId } = useClientChainId() | ||
const params = useParams() | ||
const { network } = params | ||
|
||
const { setChain } = useChain() | ||
|
||
const sdkNetwork = humanNetworktoSDKNetwork(network as string) | ||
const appChainId = subgraphNetworkToId(sdkNetwork) as | ||
| NetworkIds.BASEMAINNET | ||
| NetworkIds.ARBITRUMMAINNET | ||
|
||
const appChain = networkIdsToAccountKitChainsMap[appChainId] | ||
|
||
useEffect(() => { | ||
if (clientChainId === appChainId) { | ||
setChain({ chain: appChain }) | ||
// eslint-disable-next-line no-console | ||
console.info(`Updated app network to: ${appChain.id}`) | ||
} | ||
}, [appChain, setChain, clientChainId, appChainId]) | ||
|
||
return { clientChainId, appChainId, appChain } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters