Skip to content
Draft
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
79 changes: 76 additions & 3 deletions examples/testapp/src/pages/auto-sub-account/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
numberToHex,
parseEther,
parseUnits,
toHex,
} from 'viem';
import { privateKeyToAccount } from 'viem/accounts';
import { baseSepolia } from 'viem/chains';
Expand All @@ -47,6 +48,12 @@ export default function AutoSubAccount() {
const [walletConnectCapabilities, setWalletConnectCapabilities] = useState({
siwe: false,
addSubAccount: false,
userInfo: false,
});
const [userInfoConfig, setUserInfoConfig] = useState({
email: true,
name: true,
phoneNumber: false,
});
const { subAccountsConfig, setSubAccountsConfig, config, setConfig } = useConfig();
const { provider } = useEIP1193Provider();
Expand Down Expand Up @@ -194,13 +201,17 @@ export default function AutoSubAccount() {
let params: unknown[] = [];

// Build params based on selected capabilities
if (walletConnectCapabilities.siwe || walletConnectCapabilities.addSubAccount) {
if (
walletConnectCapabilities.siwe ||
walletConnectCapabilities.addSubAccount ||
walletConnectCapabilities.userInfo
) {
const capabilities: Record<string, unknown> = {};

// Add SIWE capability if selected
if (walletConnectCapabilities.siwe) {
capabilities.signInWithEthereum = {
chainId: 84532,
chainId: toHex(84532),
nonce: Math.random().toString(36).substring(2, 15),
};
}
Expand All @@ -221,9 +232,23 @@ export default function AutoSubAccount() {
};
}

// Add userInfo capability if selected
if (walletConnectCapabilities.userInfo) {
const collect: string[] = [];
if (userInfoConfig.email) collect.push('email');
if (userInfoConfig.name) collect.push('name');
if (userInfoConfig.phoneNumber) collect.push('phoneNumber');

if (collect.length > 0) {
capabilities.userInfo = {
collect,
};
}
}

params = [
{
...(walletConnectCapabilities.siwe && { version: '1' }),
version: '1.0.0',
capabilities,
},
];
Expand Down Expand Up @@ -445,6 +470,54 @@ export default function AutoSubAccount() {
>
Add Sub Account
</Checkbox>
<Checkbox
isChecked={walletConnectCapabilities.userInfo}
onChange={(e) =>
setWalletConnectCapabilities((prev) => ({
...prev,
userInfo: e.target.checked,
}))
}
>
User Info
</Checkbox>

{walletConnectCapabilities.userInfo && (
<VStack align="start" pl={2} spacing={2}>
<Text fontSize="sm" color="gray.600" _dark={{ color: 'gray.300' }}>
Select data to request (best-effort at connect time)
</Text>
<HStack wrap="wrap">
<Checkbox
isChecked={userInfoConfig.email}
onChange={(e) =>
setUserInfoConfig((prev) => ({ ...prev, email: e.target.checked }))
}
>
email
</Checkbox>
<Checkbox
isChecked={userInfoConfig.name}
onChange={(e) =>
setUserInfoConfig((prev) => ({ ...prev, name: e.target.checked }))
}
>
name
</Checkbox>
<Checkbox
isChecked={userInfoConfig.phoneNumber}
onChange={(e) =>
setUserInfoConfig((prev) => ({
...prev,
phoneNumber: e.target.checked,
}))
}
>
phoneNumber
</Checkbox>
</HStack>
</VStack>
)}
</Stack>
</FormControl>
{accounts.length > 0 && (
Expand Down