Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/hot-pugs-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@reservoir0x/relay-kit-ui': patch
---

Add log to AGW check error
3 changes: 2 additions & 1 deletion packages/ui/src/components/widgets/SwapWidgetRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,8 @@ const SwapWidgetRenderer: FC<SwapWidgetRendererProps> = ({
const recipientWalletSupportsChain = useIsWalletCompatible(
toChain?.id,
recipient,
linkedWallets
linkedWallets,
onAnalyticEvent
)

const isFromNative = fromToken?.address === fromChain?.currency?.address
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/constants/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
17 changes: 16 additions & 1 deletion packages/ui/src/hooks/useIsAGW.ts
Original file line number Diff line number Diff line change
@@ -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<string, any>) => void
) {
const response = useReadContract({
abi: AGWRegistryABI,
functionName: 'isAGW',
Expand All @@ -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)
}
5 changes: 3 additions & 2 deletions packages/ui/src/hooks/useIsWalletCompatible.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import useCexAddresses from './useCexAddresses.js'
export default (
chainId?: number,
address?: string,
wallets?: LinkedWallet[]
wallets?: LinkedWallet[],
onAnalyticEvent?: (event: string, data: Record<string, any>) => void
) => {
const normalizedAddress =
address && isAddress(address) ? address.toLowerCase() : address
Expand All @@ -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 ?? ''
Expand Down