diff --git a/.changeset/hot-pugs-listen.md b/.changeset/hot-pugs-listen.md new file mode 100644 index 000000000..6187cc88f --- /dev/null +++ b/.changeset/hot-pugs-listen.md @@ -0,0 +1,5 @@ +--- +'@reservoir0x/relay-kit-ui': patch +--- + +Add log to AGW check error diff --git a/packages/ui/src/components/widgets/SwapWidgetRenderer.tsx b/packages/ui/src/components/widgets/SwapWidgetRenderer.tsx index dafe69dbf..b22836a84 100644 --- a/packages/ui/src/components/widgets/SwapWidgetRenderer.tsx +++ b/packages/ui/src/components/widgets/SwapWidgetRenderer.tsx @@ -844,7 +844,8 @@ const SwapWidgetRenderer: FC = ({ const recipientWalletSupportsChain = useIsWalletCompatible( toChain?.id, recipient, - linkedWallets + linkedWallets, + onAnalyticEvent ) const isFromNative = fromToken?.address === fromChain?.currency?.address diff --git a/packages/ui/src/constants/events.ts b/packages/ui/src/constants/events.ts index 4bb5d03ad..84f20f59a 100644 --- a/packages/ui/src/constants/events.ts +++ b/packages/ui/src/constants/events.ts @@ -49,6 +49,7 @@ export const EventNames = { ONRAMP_ERROR: 'ONRAMP_ERROR', ONRAMP_PASSTHROUGH_SUCCESS: 'ONRAMP_PASSTHROUGH_SUCCESS', GAS_TOP_UP_TOGGLE: 'GAS_TOP_UP_TOGGLE', + AGW_CHECK_ERROR: 'AGW_CHECK_ERROR', //Common USER_REJECTED_WALLET: 'USER_REJECTED_WALLET', CONNECT_WALLET_CLICKED: 'CONNECT_WALLET_CLICKED', diff --git a/packages/ui/src/hooks/useIsAGW.ts b/packages/ui/src/hooks/useIsAGW.ts index b419abb98..d49d4e91f 100644 --- a/packages/ui/src/hooks/useIsAGW.ts +++ b/packages/ui/src/hooks/useIsAGW.ts @@ -1,10 +1,16 @@ import { useReadContract } from 'wagmi' import { AGWRegistryABI } from '../constants/agwRegistryAbi.js' import { isAddress } from 'viem' +import { EventNames } from '../constants/events.js' +import { useEffect } from 'react' const AGW_REGISTRY_ADDRESS = '0xd5E3efDA6bB5aB545cc2358796E96D9033496Dda' -export default function useIsAGW(address?: string, enabled?: boolean) { +export default function useIsAGW( + address?: string, + enabled?: boolean, + onAnalyticEvent?: (event: string, data: Record) => void +) { const response = useReadContract({ abi: AGWRegistryABI, functionName: 'isAGW', @@ -20,5 +26,14 @@ export default function useIsAGW(address?: string, enabled?: boolean) { } }) + useEffect(() => { + if (address && response.isError) { + onAnalyticEvent?.(EventNames.AGW_CHECK_ERROR, { + error: response.error, + address + }) + } + }, [response.isError, response.error]) + return response.isError ? false : (response.data as boolean) } diff --git a/packages/ui/src/hooks/useIsWalletCompatible.ts b/packages/ui/src/hooks/useIsWalletCompatible.ts index e894c242d..0d8ee583f 100644 --- a/packages/ui/src/hooks/useIsWalletCompatible.ts +++ b/packages/ui/src/hooks/useIsWalletCompatible.ts @@ -12,7 +12,8 @@ import useCexAddresses from './useCexAddresses.js' export default ( chainId?: number, address?: string, - wallets?: LinkedWallet[] + wallets?: LinkedWallet[], + onAnalyticEvent?: (event: string, data: Record) => void ) => { const normalizedAddress = address && isAddress(address) ? address.toLowerCase() : address @@ -22,7 +23,7 @@ export default ( ? wallet.address.toLowerCase() : wallet.address) === normalizedAddress ) - const isRecipientAGW = useIsAGW(address, !linkedWallet) + const isRecipientAGW = useIsAGW(address, !linkedWallet, onAnalyticEvent) const { data: cexAddresses } = useCexAddresses() const isRecipientCEX = cexAddresses?.addresses.includes( normalizedAddress ?? ''