diff --git a/.changeset/slimy-paws-rescue.md b/.changeset/slimy-paws-rescue.md new file mode 100644 index 0000000..66edaa2 --- /dev/null +++ b/.changeset/slimy-paws-rescue.md @@ -0,0 +1,5 @@ +--- +'@abstract-foundation/agw-client': patch +--- + +Add new valid chain id diff --git a/packages/agw-client/src/actions/signTransaction.ts b/packages/agw-client/src/actions/signTransaction.ts index 74d6338..ab7d25e 100644 --- a/packages/agw-client/src/actions/signTransaction.ts +++ b/packages/agw-client/src/actions/signTransaction.ts @@ -23,7 +23,7 @@ import { type AssertEip712RequestParameters, } from '../eip712.js'; import { AccountNotFoundError } from '../errors/account.js'; -import { validChains } from '../exports/index.js'; +import { VALID_CHAINS } from '../utils.js'; import { transformHexValues } from '../utils.js'; export async function signTransaction< @@ -69,7 +69,7 @@ export async function signTransaction< ...(transaction as AssertEip712RequestParameters), }); - if (!chain || validChains[chain.id] === undefined) { + if (!chain || VALID_CHAINS[chain.id] === undefined) { throw new BaseError('Invalid chain specified'); } diff --git a/packages/agw-client/src/utils.ts b/packages/agw-client/src/utils.ts index 1e97ecd..29a1a46 100644 --- a/packages/agw-client/src/utils.ts +++ b/packages/agw-client/src/utils.ts @@ -24,6 +24,7 @@ import { type Call } from './types/call.js'; // TODO: support Abstract mainnet export const VALID_CHAINS: Record = { [abstractTestnet.id]: abstractTestnet, + [2741]: { id: 2741 } as Chain, }; export function convertBigIntToString(value: any): any { diff --git a/packages/agw-react/src/abstractWalletConnector.ts b/packages/agw-react/src/abstractWalletConnector.ts index b289c6f..c45ef4d 100644 --- a/packages/agw-react/src/abstractWalletConnector.ts +++ b/packages/agw-react/src/abstractWalletConnector.ts @@ -12,7 +12,6 @@ import { http, type Transport, } from 'viem'; -import { abstractTestnet } from 'viem/chains'; import { AGW_APP_ID, ICON_URL } from './constants.js'; @@ -64,14 +63,16 @@ function abstractWalletConnector( return (params) => { const chains = [...params.chains]; - const chainIndex = chains.findIndex( - (chain) => chain.id === abstractTestnet.id, - ); // TODO: add mainnet - const hasChain = chainIndex !== -1; let defaultChain = params.chains[0]; - if (hasChain) { - const removedChains = chains.splice(chainIndex, 1); - defaultChain = removedChains[0] ?? defaultChain; + const validChainIds = Object.keys(validChains).map(Number).sort(); + for (const chainId of validChainIds) { + const chainIndex = chains.findIndex((chain) => chain.id === chainId); + const hasChain = chainIndex !== -1; + if (hasChain) { + const removedChains = chains.splice(chainIndex, 1); + defaultChain = removedChains[0] ?? defaultChain; + break; + } } const connector = toPrivyWalletConnector({