-
Notifications
You must be signed in to change notification settings - Fork 191
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
1 parent
0652b49
commit 1eb71c3
Showing
40 changed files
with
1,742 additions
and
1,524 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import type { ChainId } from '@shapeshiftoss/caip' | ||
import { skipToken, useQuery } from '@tanstack/react-query' | ||
import { useMemo } from 'react' | ||
import { reactQueries } from 'react-queries' | ||
import { selectEvmFees } from 'react-queries/selectors' | ||
import { useWallet } from 'hooks/useWallet/useWallet' | ||
import { | ||
assertGetEvmChainAdapter, | ||
getFeesWithWallet, | ||
type GetFeesWithWalletArgs, | ||
isGetFeesWithWalletArgs, | ||
} from 'lib/utils/evm' | ||
import { | ||
selectFeeAssetByChainId, | ||
selectMarketDataByAssetIdUserCurrency, | ||
} from 'state/slices/selectors' | ||
import { useAppSelector } from 'state/store' | ||
|
||
type UseEvmFeesProps = Omit< | ||
GetFeesWithWalletArgs, | ||
'wallet' | 'adapter' | 'accountNumber' | 'data' | ||
> & { | ||
accountNumber: number | undefined | ||
data: string | undefined | ||
chainId: ChainId | ||
enabled?: boolean | ||
staleTime?: number | ||
refetchInterval: number | false | undefined | ||
refetchIntervalInBackground: boolean | ||
} | ||
|
||
export const useEvmFees = (props: UseEvmFeesProps) => { | ||
const wallet = useWallet().state.wallet | ||
|
||
const { enabled, staleTime, refetchInterval, refetchIntervalInBackground, input } = useMemo( | ||
() => { | ||
const { | ||
enabled = true, | ||
staleTime, | ||
refetchInterval, | ||
refetchIntervalInBackground, | ||
...input | ||
} = props | ||
|
||
return { | ||
enabled, | ||
staleTime, | ||
refetchInterval, | ||
refetchIntervalInBackground, | ||
input, | ||
} | ||
}, | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
Object.values(props), | ||
) | ||
|
||
const adapter = useMemo(() => assertGetEvmChainAdapter(input.chainId), [input.chainId]) | ||
|
||
const feeAsset = useAppSelector(state => selectFeeAssetByChainId(state, input.chainId)) | ||
const feeAssetMarketData = useAppSelector(state => | ||
selectMarketDataByAssetIdUserCurrency(state, feeAsset?.assetId ?? ''), | ||
) | ||
|
||
const getFeesWithWalletInput = useMemo( | ||
() => ({ ...input, adapter, wallet }), | ||
[adapter, input, wallet], | ||
) | ||
|
||
const query = useQuery({ | ||
queryKey: reactQueries.common.evmFees(input).queryKey, | ||
queryFn: | ||
isGetFeesWithWalletArgs(getFeesWithWalletInput) && enabled | ||
? () => getFeesWithWallet(getFeesWithWalletInput) | ||
: skipToken, | ||
select: feeAsset ? fees => selectEvmFees(fees, feeAsset, feeAssetMarketData) : undefined, | ||
staleTime, | ||
refetchInterval, | ||
refetchIntervalInBackground, | ||
}) | ||
|
||
return query | ||
} |
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
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
Oops, something went wrong.