diff --git a/.changeset/cool-walls-dream.md b/.changeset/cool-walls-dream.md new file mode 100644 index 000000000..07f9e6a7d --- /dev/null +++ b/.changeset/cool-walls-dream.md @@ -0,0 +1,5 @@ +--- +'@coinbase/onchainkit': patch +--- + +ok diff --git a/CHANGELOG.md b/CHANGELOG.md index 60620dd45..d733910bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,9 @@ ### Patch Changes - - **feat**: added support for `EIP-5792` (https://eips.ethereum.org/EIPS/eip-5792) in `OnchainKitProvider`. By @0xAlec #1181 - - **fix**: adjusted hover styling for the `Fund` and `Disconnect` wallet components in mobile view. By @cpcramer #1211 - - **feat** added `walletCapabilities` for atomic batching (`useWriteContracts` vs `useWriteContract`) in `Transaction` component. By @0xAlec #1214 +- **feat**: added support for `EIP-5792` (https://eips.ethereum.org/EIPS/eip-5792) in `OnchainKitProvider`. By@0xAlec #1181 +- **fix**: adjusted hover styling for the `Fund` and `Disconnect` wallet components in mobile view. By@cpcramer #1211 +- **feat** added `walletCapabilities` for atomic batching (`useWriteContracts` vs `useWriteContract`) in`Transaction` component. By @0xAlec #1214 ## 0.31.3 diff --git a/src/isBase.test.ts b/src/isBase.test.ts index bb046efe3..9a071cd3f 100644 --- a/src/isBase.test.ts +++ b/src/isBase.test.ts @@ -21,4 +21,18 @@ describe('isBase', () => { const result = isBase({ chainId }); expect(result).toEqual(true); }); + + it('should return true when isMainnetOnly is true and chainId is mainnet', () => { + const chainId = base.id; + const isMainnetOnly = true; + const result = isBase({ chainId, isMainnetOnly }); + expect(result).toEqual(true); + }); + + it('should return false when isMainnetOnly is true and chainId is not mainnet', () => { + const chainId = baseSepolia.id; + const isMainnetOnly = true; + const result = isBase({ chainId, isMainnetOnly }); + expect(result).toEqual(false); + }); }); diff --git a/src/isBase.ts b/src/isBase.ts index e92a58525..2922ffda7 100644 --- a/src/isBase.ts +++ b/src/isBase.ts @@ -6,9 +6,17 @@ import type { isBaseOptions } from './types'; * - Checks if the paymaster operations chain id is valid * - Only allows the Base and Base Sepolia chain ids */ -export function isBase({ chainId }: isBaseOptions): boolean { - if (chainId !== baseSepolia.id && chainId !== base.id) { - return false; +export function isBase({ + chainId, + isMainnetOnly = false, +}: isBaseOptions): boolean { + // If only Base mainnet + if (isMainnetOnly && chainId === base.id) { + return true; } - return true; + // If only Base or Base Sepolia + if (!isMainnetOnly && (chainId === baseSepolia.id || chainId === base.id)) { + return true; + } + return false; } diff --git a/src/isEthereum.test.ts b/src/isEthereum.test.ts index fbee8a2e8..9561350fa 100644 --- a/src/isEthereum.test.ts +++ b/src/isEthereum.test.ts @@ -13,4 +13,16 @@ describe('isEthereum', () => { it('should return false for other chains for testnet', () => { expect(isEthereum({ chainId: optimism.id })).toBeFalsy(); }); + + it('should return true when isMainnetOnly is true and chainId is mainnet', () => { + expect( + isEthereum({ chainId: mainnet.id, isMainnetOnly: true }), + ).toBeTruthy(); + }); + + it('should return false when isMainnetOnly is true and chainId is not mainnet', () => { + expect( + isEthereum({ chainId: sepolia.id, isMainnetOnly: true }), + ).toBeFalsy(); + }); }); diff --git a/src/isEthereum.ts b/src/isEthereum.ts index 6b44952e8..6d55a1034 100644 --- a/src/isEthereum.ts +++ b/src/isEthereum.ts @@ -5,9 +5,17 @@ import type { isEthereumOptions } from './types'; * isEthereum * - Checks if the chain is mainnet or sepolia */ -export function isEthereum({ chainId }: isEthereumOptions): boolean { - if (chainId !== mainnet.id && chainId !== sepolia.id) { - return false; +export function isEthereum({ + chainId, + isMainnetOnly = false, +}: isEthereumOptions): boolean { + // If only ETH mainnet + if (isMainnetOnly && chainId === mainnet.id) { + return true; } - return true; + // If only ETH or ETH Sepolia + if (!isMainnetOnly && (chainId === sepolia.id || chainId === mainnet.id)) { + return true; + } + return false; } diff --git a/src/types.ts b/src/types.ts index bd7ca5558..dc57ce6cf 100644 --- a/src/types.ts +++ b/src/types.ts @@ -7,6 +7,7 @@ import type { EASSchemaUid } from './identity/types'; */ export type isBaseOptions = { chainId: number; + isMainnetOnly?: boolean; // If the chainId check is only allowed on mainnet }; /** @@ -14,6 +15,7 @@ export type isBaseOptions = { */ export type isEthereumOptions = { chainId: number; + isMainnetOnly?: boolean; // If the chainId check is only allowed on mainnet }; /**