Skip to content

Commit

Permalink
fix: getStateContractAndProviderForId - throw error if no config for …
Browse files Browse the repository at this point in the history
…chainId found (#256)

* fix: getStateContractAndProviderForId - throw error if no config for chainId found

* provide chainId in config
  • Loading branch information
volodymyr-basiuk authored Aug 20, 2024
1 parent 1efe40f commit 3f74a4a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@0xpolygonid/js-sdk",
"version": "1.17.3",
"version": "1.17.4",
"description": "SDK to work with Polygon ID",
"main": "dist/node/cjs/index.js",
"module": "dist/node/esm/index.js",
Expand Down
20 changes: 5 additions & 15 deletions src/storage/blockchain/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,6 @@ export class EthStateStorage implements IStateStorage {
provider: JsonRpcProvider;
} {
const idTyped = Id.fromBigInt(id as bigint);
if (!Array.isArray(this.ethConfig)) {
return {
stateContract: this.stateContract,
provider: this.provider
};
}

const chainId = getChainId(DID.blockchainFromId(idTyped), DID.networkIdFromId(idTyped));
const config = this.networkByChainId(chainId);

Expand All @@ -257,14 +250,11 @@ export class EthStateStorage implements IStateStorage {
}

private networkByChainId(chainId: number): EthConnectionConfig {
if (Array.isArray(this.ethConfig)) {
const network = this.ethConfig.find((c) => c.chainId === chainId);
if (!network) {
throw new Error(`chainId "${chainId}" not supported`);
}
return network;
const config = Array.isArray(this.ethConfig) ? this.ethConfig : [this.ethConfig];
const network = config.find((c) => c.chainId === chainId);
if (!network) {
throw new Error(`chainId "${chainId}" not supported`);
}

return this.ethConfig as EthConnectionConfig;
return network;
}
}
1 change: 1 addition & 0 deletions tests/handlers/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1556,6 +1556,7 @@ describe('auth', () => {
const stateEthConfig = defaultEthConnectionConfig;
stateEthConfig.url = RPC_URL;
stateEthConfig.contractAddress = STATE_CONTRACT;
stateEthConfig.chainId = 80002;
const eth = new EthStateStorage(stateEthConfig);

const kms = registerKeyProvidersInMemoryKMS();
Expand Down

0 comments on commit 3f74a4a

Please sign in to comment.