Skip to content

Commit

Permalink
feat: update valid chain ids (#155)
Browse files Browse the repository at this point in the history
* feat: add 2741 to valid chains

* changeset

* update wallet connector logic
  • Loading branch information
coffeexcoin authored Jan 2, 2025
1 parent 20aec49 commit 5e15f01
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/slimy-paws-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@abstract-foundation/agw-client': patch
---

Add new valid chain id
4 changes: 2 additions & 2 deletions packages/agw-client/src/actions/signTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down Expand Up @@ -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');
}

Expand Down
1 change: 1 addition & 0 deletions packages/agw-client/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { type Call } from './types/call.js';
// TODO: support Abstract mainnet
export const VALID_CHAINS: Record<number, Chain> = {
[abstractTestnet.id]: abstractTestnet,
[2741]: { id: 2741 } as Chain,
};

export function convertBigIntToString(value: any): any {
Expand Down
17 changes: 9 additions & 8 deletions packages/agw-react/src/abstractWalletConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
http,
type Transport,
} from 'viem';
import { abstractTestnet } from 'viem/chains';

import { AGW_APP_ID, ICON_URL } from './constants.js';

Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 5e15f01

Please sign in to comment.