Skip to content

Commit 19696ad

Browse files
authored
Merge pull request #718 from reservoirprotocol/pedro/fe-7546-log-if-agw-rpc-failed
Log if agw rpc failed
2 parents 8cf71a8 + a66f322 commit 19696ad

File tree

5 files changed

+27
-4
lines changed

5 files changed

+27
-4
lines changed

.changeset/hot-pugs-listen.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@reservoir0x/relay-kit-ui': patch
3+
---
4+
5+
Add log to AGW check error

packages/ui/src/components/widgets/SwapWidgetRenderer.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,8 @@ const SwapWidgetRenderer: FC<SwapWidgetRendererProps> = ({
867867
const recipientWalletSupportsChain = useIsWalletCompatible(
868868
toChain?.id,
869869
recipient,
870-
linkedWallets
870+
linkedWallets,
871+
onAnalyticEvent
871872
)
872873

873874
const isFromNative = fromToken?.address === fromChain?.currency?.address

packages/ui/src/constants/events.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export const EventNames = {
4949
ONRAMP_ERROR: 'ONRAMP_ERROR',
5050
ONRAMP_PASSTHROUGH_SUCCESS: 'ONRAMP_PASSTHROUGH_SUCCESS',
5151
GAS_TOP_UP_TOGGLE: 'GAS_TOP_UP_TOGGLE',
52+
AGW_CHECK_ERROR: 'AGW_CHECK_ERROR',
5253
//Common
5354
USER_REJECTED_WALLET: 'USER_REJECTED_WALLET',
5455
CONNECT_WALLET_CLICKED: 'CONNECT_WALLET_CLICKED',

packages/ui/src/hooks/useIsAGW.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import { useReadContract } from 'wagmi'
22
import { AGWRegistryABI } from '../constants/agwRegistryAbi.js'
33
import { isAddress } from 'viem'
4+
import { EventNames } from '../constants/events.js'
5+
import { useEffect } from 'react'
46

57
const AGW_REGISTRY_ADDRESS = '0xd5E3efDA6bB5aB545cc2358796E96D9033496Dda'
68

7-
export default function useIsAGW(address?: string, enabled?: boolean) {
9+
export default function useIsAGW(
10+
address?: string,
11+
enabled?: boolean,
12+
onAnalyticEvent?: (event: string, data: Record<string, any>) => void
13+
) {
814
const response = useReadContract({
915
abi: AGWRegistryABI,
1016
functionName: 'isAGW',
@@ -20,5 +26,14 @@ export default function useIsAGW(address?: string, enabled?: boolean) {
2026
}
2127
})
2228

29+
useEffect(() => {
30+
if (address && response.isError) {
31+
onAnalyticEvent?.(EventNames.AGW_CHECK_ERROR, {
32+
error: response.error,
33+
address
34+
})
35+
}
36+
}, [response.isError, response.error])
37+
2338
return response.isError ? false : (response.data as boolean)
2439
}

packages/ui/src/hooks/useIsWalletCompatible.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import useCexAddresses from './useCexAddresses.js'
1212
export default (
1313
chainId?: number,
1414
address?: string,
15-
wallets?: LinkedWallet[]
15+
wallets?: LinkedWallet[],
16+
onAnalyticEvent?: (event: string, data: Record<string, any>) => void
1617
) => {
1718
const normalizedAddress =
1819
address && isAddress(address) ? address.toLowerCase() : address
@@ -22,7 +23,7 @@ export default (
2223
? wallet.address.toLowerCase()
2324
: wallet.address) === normalizedAddress
2425
)
25-
const isRecipientAGW = useIsAGW(address, !linkedWallet)
26+
const isRecipientAGW = useIsAGW(address, !linkedWallet, onAnalyticEvent)
2627
const { data: cexAddresses } = useCexAddresses()
2728
const isRecipientCEX = cexAddresses?.addresses.includes(
2829
normalizedAddress ?? ''

0 commit comments

Comments
 (0)