-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
92 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { MultiProtocolProvider } from '@hyperlane-xyz/sdk'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { useToastError } from '../../../components/toast/useToastError'; | ||
import { logger } from '../../../utils/logger'; | ||
import { useMultiProvider } from '../../chains/hooks'; | ||
import { DeployerWallets } from '../../deployerWallet/types'; | ||
import { useDeployerWallets } from '../../deployerWallet/wallets'; | ||
import { WarpDeploymentConfig } from '../types'; | ||
|
||
export function useWarpDeployment( | ||
deploymentConfig?: WarpDeploymentConfig, | ||
onSuccess?: () => void, | ||
onFailure?: (error: Error) => void, | ||
) { | ||
const multiProvider = useMultiProvider(); | ||
const { wallets } = useDeployerWallets(); | ||
|
||
const { error, mutate, isIdle, isPending } = useMutation({ | ||
mutationKey: ['warpDeploy', deploymentConfig, wallets], | ||
mutationFn: () => { | ||
if (!deploymentConfig) return Promise.resolve(null); | ||
return executeDeploy(deploymentConfig, multiProvider, wallets); | ||
}, | ||
retry: false, | ||
onError: onFailure, | ||
onSuccess, | ||
}); | ||
|
||
useToastError(error, 'Error deploying warp route.'); | ||
|
||
return { | ||
deploy: mutate, | ||
isIdle, | ||
isPending, | ||
}; | ||
} | ||
|
||
export async function executeDeploy( | ||
config: WarpDeploymentConfig, | ||
multiProvider: MultiProtocolProvider, | ||
wallets: DeployerWallets, | ||
) { | ||
//TODO | ||
logger.info('Deploying warp route', multiProvider, config, wallets); | ||
} |
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,14 @@ | ||
import { useEffect } from 'react'; | ||
import { useThrottle } from './useThrottle'; | ||
|
||
export function useMutationOnMount<T>( | ||
isIdle: boolean, | ||
run: () => Promise<T> | null | undefined | void, | ||
restartDelay = 10_000, | ||
) { | ||
const throttledRun = useThrottle(run, restartDelay); | ||
|
||
useEffect(() => { | ||
if (isIdle) throttledRun(); | ||
}, [isIdle, throttledRun]); | ||
} |
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