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
31 changes: 0 additions & 31 deletions examples/testapp/src/pages/auto-sub-account/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
VStack,
} from '@chakra-ui/react';
import { getCryptoKeyAccount } from '@coinbase/wallet-sdk';
import { SpendPermissionConfig } from '@coinbase/wallet-sdk/dist/core/provider/interface';
import React, { useEffect, useState } from 'react';
import { createPublicClient, http, numberToHex, parseEther } from 'viem';
import { privateKeyToAccount } from 'viem/accounts';
Expand Down Expand Up @@ -215,24 +214,6 @@ export default function AutoSubAccount() {
}
};

const handleSetDefaultSpendPermissions = (value: string) => {
const defaultSpendPermissions = {
[baseSepolia.id]: [
{
token: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
allowance: '0x2386F26FC10000',
period: 86400,
} as SpendPermissionConfig,
],
};

if (value === 'true') {
setSubAccountsConfig((prev) => ({ ...prev, defaultSpendPermissions }));
} else {
setSubAccountsConfig((prev) => ({ ...prev, defaultSpendPermissions: {} }));
}
};

const handleEthSend = async (amount: string) => {
if (!provider || !accounts.length) return;

Expand Down Expand Up @@ -326,18 +307,6 @@ export default function AutoSubAccount() {
</Stack>
</RadioGroup>
</FormControl>
<FormControl>
<FormLabel>Default Spend Permissions</FormLabel>
<RadioGroup
value={subAccountsConfig?.defaultSpendPermissions?.[baseSepolia.id] ? 'true' : 'false'}
onChange={handleSetDefaultSpendPermissions}
>
<Stack direction="row">
<Radio value="true">Enabled</Radio>
<Radio value="false">Disabled</Radio>
</Stack>
</RadioGroup>
</FormControl>
<FormControl>
<FormLabel>Attribution</FormLabel>
<RadioGroup value={getAttributionMode()} onChange={handleAttributionModeChange}>
Expand Down
5 changes: 0 additions & 5 deletions packages/wallet-sdk/src/core/provider/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,6 @@ export type SubAccountOptions = {
* @returns The owner account that will be used to sign the subaccount transactions.
*/
toOwnerAccount?: ToOwnerAccountFn;
/**
* Spend permissions requested on app connect if a matching existing one does not exist.
* Only supports native chain tokens currently.
*/
defaultSpendPermissions?: Record<number, SpendPermissionConfig[]>;
};

export interface ConstructorOptions {
Expand Down
1 change: 0 additions & 1 deletion packages/wallet-sdk/src/createCoinbaseWalletSDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export function createCoinbaseWalletSDK(params: CreateCoinbaseWalletSDKOptions)
store.subAccountsConfig.set({
toOwnerAccount: params.subAccounts?.toOwnerAccount,
enableAutoSubAccounts: params.subAccounts?.enableAutoSubAccounts,
defaultSpendPermissions: params.subAccounts?.defaultSpendPermissions,
});

// set the options in the store
Expand Down
16 changes: 12 additions & 4 deletions packages/wallet-sdk/src/sign/scw/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,15 @@ describe('assertGetCapabilitiesParams', () => {
expect(() => assertGetCapabilitiesParams(['0x123'])).toThrow(); // Too short
expect(() => assertGetCapabilitiesParams(['0x123abc'])).toThrow(); // Too short
expect(() => assertGetCapabilitiesParams(['xyz123'])).toThrow(); // No 0x prefix
expect(() => assertGetCapabilitiesParams(['0x12345678901234567890123456789012345678gg'])).toThrow(); // Invalid hex characters
expect(() => assertGetCapabilitiesParams(['0x123456789012345678901234567890123456789'])).toThrow(); // Too short (39 chars)
expect(() => assertGetCapabilitiesParams(['0x12345678901234567890123456789012345678901'])).toThrow(); // Too long (41 chars)
expect(() =>
assertGetCapabilitiesParams(['0x12345678901234567890123456789012345678gg'])
).toThrow(); // Invalid hex characters
expect(() =>
assertGetCapabilitiesParams(['0x123456789012345678901234567890123456789'])
).toThrow(); // Too short (39 chars)
expect(() =>
assertGetCapabilitiesParams(['0x12345678901234567890123456789012345678901'])
).toThrow(); // Too long (41 chars)
});

it('should not throw for valid single parameter (valid Ethereum address)', () => {
Expand All @@ -148,7 +154,9 @@ describe('assertGetCapabilitiesParams', () => {
it('should not throw for valid parameters with filter array', () => {
expect(() => assertGetCapabilitiesParams([VALID_ADDRESS_1, []])).not.toThrow();
expect(() => assertGetCapabilitiesParams([VALID_ADDRESS_1, ['0x1']])).not.toThrow();
expect(() => assertGetCapabilitiesParams([VALID_ADDRESS_1, ['0x1', '0x2', '0x3']])).not.toThrow();
expect(() =>
assertGetCapabilitiesParams([VALID_ADDRESS_1, ['0x1', '0x2', '0x3']])
).not.toThrow();
expect(() => assertGetCapabilitiesParams([VALID_ADDRESS_1, ['0xabcdef', '0x0']])).not.toThrow();
expect(() => assertGetCapabilitiesParams([VALID_ADDRESS_2, ['0x1', '0xa']])).not.toThrow();
});
Expand Down
7 changes: 2 additions & 5 deletions packages/wallet-sdk/src/sign/scw/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,6 @@ export async function initSubAccountConfig() {
};
}

if (config.defaultSpendPermissions) {
capabilities.spendPermissions = config.defaultSpendPermissions;
}

// Store the owner account and capabilities in the non-persisted config
store.subAccountsConfig.set({
capabilities,
Expand Down Expand Up @@ -591,7 +587,8 @@ export async function getCachedWalletConnectResponse(): Promise<WalletConnectRes
address: account,
capabilities: {
subAccounts: subAccount ? [subAccount] : undefined,
spendPermissions: spendPermissions.length > 0 ? { permissions: spendPermissions } : undefined,
spendPermissions:
spendPermissions.length > 0 ? { permissions: spendPermissions } : undefined,
},
})
);
Expand Down