diff --git a/.changeset/cool-walls-dream.md b/.changeset/cool-walls-dream.md new file mode 100644 index 0000000000..db41e92b6e --- /dev/null +++ b/.changeset/cool-walls-dream.md @@ -0,0 +1,5 @@ +--- +'@coinbase/onchainkit': patch +--- + +- **feat**: added `isMainnetOnly` to `isBase` and `isEthereum` utilities. By @zizzamia #1167 #1221 diff --git a/CHANGELOG.md b/CHANGELOG.md index 60620dd45b..d733910bb0 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/site/docs/pages/config/is-ethereum.mdx b/site/docs/pages/config/is-ethereum.mdx new file mode 100644 index 0000000000..1c6e6e4af6 --- /dev/null +++ b/site/docs/pages/config/is-ethereum.mdx @@ -0,0 +1,33 @@ +# `isEthereum` + +The `isEthereum` utility is designed to verify if the chain id is a valid Ethereum Mainnet or Ethereum Sepolia chain id. + +## Usage + +:::code-group + +```tsx [code] +import { isEthereum } from '@coinbase/onchainkit'; + +const chainId = 1; + +if (isEthereum({ chainId })) { + console.log('The chainId is Ethereum Mainnet or Ethereum Sepolia.'); +} else { + console.log('The chainId is not Ethereum.'); +} +``` + +```ts [return value] +true; +``` + +::: + +## Returns + +`boolean` - Returns `true` if the chain id is Ethereum Mainnet or Ethereum Sepolia, otherwise `false`. + +## Parameters + +[`isEthereumOptions`](/config/types#isethereumoptions) diff --git a/site/docs/public/sitemap.xml b/site/docs/public/sitemap.xml index 7f5de683a4..07ece67aa5 100644 --- a/site/docs/public/sitemap.xml +++ b/site/docs/public/sitemap.xml @@ -1,293 +1,298 @@ - - + + https://onchainkit.xyz/ - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/getting-started - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/wallet/wallet - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/transaction/transaction - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/token/types - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/swap/swap - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/identity/avatar - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/identity/badge - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/identity/name - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/identity/address - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/identity/identity - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/frame/frame-metadata - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/playground - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/guides/lifecycle-status - 2024-08-30 + 2024-09-08 + daily + + + https://onchainkit.xyz/guides/build-onchain-apps + 2024-09-08 daily https://onchainkit.xyz/guides/use-basename-in-onchain-app - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/frame/framegear - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/guides/tailwind - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/guides/reporting-bug - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/guides/contribution - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/config/onchainkit-provider - 2024-08-30 + 2024-09-08 daily - https://onchainkit.xyz/token/token-chip - 2024-08-30 + https://onchainkit.xyz/token/token-image + 2024-09-08 daily - https://onchainkit.xyz/token/token-image - 2024-08-30 + https://onchainkit.xyz/token/token-chip + 2024-09-08 daily https://onchainkit.xyz/token/token-row - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/token/token-search - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/token/token-select-dropdown - 2024-08-30 + 2024-09-08 daily - https://onchainkit.xyz/wallet/wallet-dropdown-basename - 2024-08-30 + https://onchainkit.xyz/wallet/wallet-dropdown-disconnect + 2024-09-08 daily - https://onchainkit.xyz/wallet/wallet-dropdown-disconnect - 2024-08-30 + https://onchainkit.xyz/wallet/wallet-dropdown-basename + 2024-09-08 daily https://onchainkit.xyz/wallet/wallet-dropdown-fund-link - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/wallet/wallet-dropdown-link - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/api/build-swap-transaction - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/api/get-swap-quote - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/api/get-tokens - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/wallet/types - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/transaction/types - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/api/types - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/config/types - 2024-08-30 + 2024-09-08 daily - https://onchainkit.xyz/farcaster/types - 2024-08-30 + https://onchainkit.xyz/frame/types + 2024-09-08 daily - https://onchainkit.xyz/frame/types - 2024-08-30 + https://onchainkit.xyz/farcaster/types + 2024-09-08 daily https://onchainkit.xyz/identity/types - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/swap/types - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/identity/use-avatar - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/identity/use-name - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/identity/get-name - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/config/is-base - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/farcaster/get-farcaster-user-address - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/frame/get-frame-html-response - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/frame/get-frame-message - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/frame/get-frame-metadata - 2024-08-30 + 2024-09-08 daily - https://onchainkit.xyz/xmtp/get-xmtp-frame-message - 2024-08-30 + https://onchainkit.xyz/xmtp/is-xmtp-frame-request + 2024-09-08 daily - https://onchainkit.xyz/xmtp/is-xmtp-frame-request - 2024-08-30 + https://onchainkit.xyz/xmtp/get-xmtp-frame-message + 2024-09-08 daily https://onchainkit.xyz/identity/get-address - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/identity/get-attestations - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/identity/get-avatar - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/identity/use-address - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/token/format-amount - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/wallet/is-valid-aa-entrypoint - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/wallet/is-wallet-a-coinbase-smart-wallet - 2024-08-30 + 2024-09-08 daily https://onchainkit.xyz/xmtp/types - 2024-08-30 + 2024-09-08 daily \ No newline at end of file diff --git a/site/sidebar.ts b/site/sidebar.ts index a7df8a6b77..6734709c58 100644 --- a/site/sidebar.ts +++ b/site/sidebar.ts @@ -205,6 +205,10 @@ export const sidebar = [ text: 'isBase', link: '/config/is-base', }, + { + text: 'isEthereum', + link: '/config/is-ethereum', + }, ], }, { diff --git a/src/isBase.test.ts b/src/isBase.test.ts index bb046efe39..9a071cd3f6 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 e92a585254..2922ffda73 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 fbee8a2e8e..9561350fa7 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 6b44952e8b..6d55a1034e 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 bd7ca55585..dc57ce6cfb 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 }; /**