Skip to content

Commit

Permalink
chore: erc3770 chain specific addresses (#3848)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaisailovic authored Feb 14, 2025
1 parent ca9cc60 commit 9aef2c0
Show file tree
Hide file tree
Showing 7 changed files with 2,426 additions and 254 deletions.
22 changes: 22 additions & 0 deletions apps/laboratory/src/components/AppKitInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Text
} from '@chakra-ui/react'

import { convertCaip10ToErc3770 } from '@reown/appkit-experimental/erc3770'
import { useAppKitAccount, useAppKitNetwork } from '@reown/appkit/react'

import { EmbeddedWalletInfo } from './EmbeddedWalletInfo'
Expand All @@ -23,6 +24,18 @@ export function AppKitInfo({ clientId }: AppKitInfoProps) {
const { caipAddress, address } = useAppKitAccount()
const { chainId } = useAppKitNetwork()

const isEIP155 = caipAddress?.startsWith('eip155:')
const erc3770Address = React.useMemo(() => {
if (!isEIP155 || !caipAddress) {
return null
}
try {
return convertCaip10ToErc3770(caipAddress)
} catch (e) {
return null
}
}, [caipAddress, isEIP155])

return (
<Card marginTop={10} marginBottom={10}>
<CardHeader>
Expand All @@ -38,6 +51,15 @@ export function AppKitInfo({ clientId }: AppKitInfoProps) {
<Text data-testid="w3m-caip-address">{caipAddress}</Text>
</Box>

{erc3770Address && (
<Box>
<Heading size="xs" textTransform="uppercase" pb="2">
Chain Specific Address (ERC-3770)
</Heading>
<Text data-testid="w3m-erc3770-address">{erc3770Address}</Text>
</Box>
)}

<Box>
<Heading size="xs" textTransform="uppercase" pb="2">
Address
Expand Down
9 changes: 9 additions & 0 deletions packages/experimental/exports/erc3770/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ConverterUtil } from '../../src/erc3770/utils/ConverterUtil.js'

export function convertCaip10ToErc3770(caipAddress: string): string {
return ConverterUtil.convertCaip10ToErc3770(caipAddress)
}

export function createErc3770Address(address: string, chainId: string): string {
return ConverterUtil.createErc3770Address(address, chainId)
}
9 changes: 9 additions & 0 deletions packages/experimental/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,20 @@
"types": "./dist/types/exports/smart-session/index.d.ts",
"import": "./dist/esm/exports/smart-session/index.js",
"default": "./dist/esm/exports/smart-session/index.js"
},
"./erc3770": {
"types": "./dist/types/exports/erc3770/index.d.ts",
"import": "./dist/esm/exports/erc3770/index.js",
"default": "./dist/esm/exports/erc3770/index.js"
}
},
"typesVersions": {
"*": {
"smart-session": [
"./dist/types/exports/smart-session/index.d.ts"
],
"erc3770": [
"./dist/types/exports/erc3770/index.d.ts"
]
}
},
Expand All @@ -42,6 +50,7 @@
"@reown/appkit-ui": "workspace:*",
"lit": "3.1.0",
"valtio": "1.13.2",
"viem": "2.23.0",
"zod": "3.22.4"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit 9aef2c0

Please sign in to comment.