-
Notifications
You must be signed in to change notification settings - Fork 28
EOA detection #746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pedromcunha
merged 36 commits into
main
from
joseph/fe-7821-for-eoas-using-protocol-v2-set-explicitdepositfalse
Sep 11, 2025
Merged
EOA detection #746
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
fe69ed6
add eoa detection logic
0xTxbi 2b6dc39
add eoa flag to adapted wallet
0xTxbi 7b8f325
feat: changeset
0xTxbi fe76ef6
improved eoa detection logic
0xTxbi 6347c47
update getQuote
0xTxbi 36bd8e4
eoa detection hook
0xTxbi 8b84310
update widget component
0xTxbi 78b3cea
clean up
0xTxbi 84f5ce0
refactor
0xTxbi fbf1312
add debug logs
0xTxbi 640f714
fix double quote triggers
0xTxbi 229c878
update eoa detection hook
0xTxbi 11fdea5
fix malformed quote generation
0xTxbi 0017d91
improve debug logs
0xTxbi 28282f1
improved logging
0xTxbi 769ba15
clean up
0xTxbi c97fcc7
fix package usage
0xTxbi 9800263
Merge branch 'main' into joseph/fe-7821-for-eoas-using-protocol-v2-se…
0xTxbi e376ce2
fix code check
0xTxbi ef51c29
fix eoa detection hook
0xTxbi fc1f5f9
clean up
0xTxbi 0cff8aa
Merge branch 'main' into joseph/fe-7821-for-eoas-using-protocol-v2-se…
0xTxbi 2a07f14
address vm type switches
0xTxbi c8c03b7
refactor
0xTxbi 9fcb052
clean up logs
0xTxbi 3fc7503
improved wallet type detection and logging
0xTxbi 2fd876e
temp debug logs
0xTxbi 9f5c57b
clean up
0xTxbi ced3461
cleanup
0xTxbi 1252cb2
more logging
0xTxbi 11215b3
Merge branch 'main' into joseph/fe-7821-for-eoas-using-protocol-v2-se…
0xTxbi edd8700
clean up logs
0xTxbi f6f2241
clean up
0xTxbi ae704f2
Improve readability of eoa check
pedromcunha c3abdb0
Improve readability of eoa check
pedromcunha 6ea3e13
Resolve conflicts
pedromcunha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,5 @@ | ||
| --- | ||
| '@reservoir0x/relay-sdk': patch | ||
| --- | ||
|
|
||
| Add EOA detection |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,88 @@ | ||
| import { useMemo, useEffect, useState, useRef } from 'react' | ||
| import type { AdaptedWallet } from '@relayprotocol/relay-sdk' | ||
|
|
||
| /** | ||
| * Hook to detect if a wallet is an EOA and return the appropriate explicitDeposit flag | ||
| * Only runs detection when protocol version is 'preferV2' and wallet supports EOA detection | ||
| */ | ||
| const useEOADetection = ( | ||
| wallet?: AdaptedWallet, | ||
| protocolVersion?: string, | ||
| chainId?: number, | ||
| chainVmType?: string | ||
| ): boolean | undefined => { | ||
| const [detectionState, setDetectionState] = useState<{ | ||
| value: boolean | undefined | ||
| conditionKey: string | ||
| }>({ value: undefined, conditionKey: '' }) | ||
|
|
||
| const walletRef = useRef<AdaptedWallet | undefined>(wallet) | ||
| const walletId = useRef<number>(0) | ||
|
|
||
| if (walletRef.current !== wallet) { | ||
| walletRef.current = wallet | ||
| walletId.current += 1 | ||
| } | ||
|
|
||
| const conditionKey = `${wallet?.vmType}:${chainVmType}:${!!wallet?.isEOA}:${protocolVersion}:${chainId}:${walletId.current}` | ||
|
|
||
| const shouldDetect = useMemo(() => { | ||
| return ( | ||
| wallet !== undefined && | ||
| protocolVersion === 'preferV2' && | ||
| chainId !== undefined && | ||
| wallet?.vmType === 'evm' && | ||
| chainVmType === 'evm' | ||
| ) | ||
| }, [wallet?.vmType, protocolVersion, chainId, chainVmType]) | ||
|
|
||
| // Synchronously return undefined when conditions change | ||
| const explicitDeposit = useMemo(() => { | ||
| return detectionState.conditionKey !== conditionKey || !shouldDetect | ||
| ? undefined | ||
| : detectionState.value | ||
| }, [conditionKey, shouldDetect, detectionState]) | ||
|
|
||
| useEffect(() => { | ||
| setDetectionState({ value: undefined, conditionKey }) | ||
|
|
||
| if (!shouldDetect) { | ||
| return | ||
| } | ||
|
|
||
| const detectEOA = async () => { | ||
| try { | ||
| if (!wallet?.isEOA) { | ||
| setDetectionState((current) => | ||
| current.conditionKey === conditionKey | ||
| ? { value: false, conditionKey } | ||
| : current | ||
| ) | ||
| return | ||
| } | ||
|
|
||
| const eoaResult = await wallet.isEOA(chainId!) | ||
| const { isEOA, isEIP7702Delegated } = eoaResult | ||
| const explicitDepositValue = !isEOA || isEIP7702Delegated | ||
|
|
||
| setDetectionState((current) => | ||
| current.conditionKey === conditionKey | ||
| ? { value: explicitDepositValue, conditionKey } | ||
| : current | ||
| ) | ||
| } catch (error) { | ||
| setDetectionState((current) => | ||
| current.conditionKey === conditionKey | ||
| ? { value: undefined, conditionKey } | ||
| : current | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| detectEOA() | ||
| }, [conditionKey, shouldDetect, wallet, chainId]) | ||
|
|
||
| return explicitDeposit | ||
| } | ||
|
|
||
| export default useEOADetection | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.