Skip to content

Commit

Permalink
(feat): add is claim on connected chain utility method
Browse files Browse the repository at this point in the history
  • Loading branch information
Jipperism committed Apr 7, 2024
1 parent 43c62b7 commit cc330a4
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 3 deletions.
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

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

1 change: 1 addition & 0 deletions sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"axios": "^1.6.2",
"dotenv": "^16.0.3",
"ethers": "5.7.2",
"fast-deep-equal": "^3.1.3",
"graphql": "^16.8.1",
"loglevel": "^1.8.1",
"urql": "^4.0.6",
Expand Down
6 changes: 6 additions & 0 deletions sdk/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { parseAllowListEntriesToMerkleTree } from "./utils/allowlist";
import { DEPLOYMENTS } from "./constants";
import { getClaimStoredDataFromTxHash } from "./utils";
import { ParserReturnType } from "./utils/txParser";
import { isClaimOnChain } from "./utils/chains";

/**
* The `HypercertClient` is a core class in the hypercerts SDK, providing a high-level interface to interact with the hypercerts system.
Expand Down Expand Up @@ -75,6 +76,11 @@ export class HypercertClient implements HypercertClientInterface {
}
}

isClaimOrFractionOnConnectedChain = (claimOrFractionId: string) => {
const connectedChain = this._walletClient?.chain?.id;
return isClaimOnChain(claimOrFractionId, connectedChain);
};

/**
* Gets the config for the client.
* @returns The client config.
Expand Down
6 changes: 5 additions & 1 deletion sdk/src/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ export class HypercertIndexer implements HypercertIndexerInterface {

static getDeploymentsForEnvironment(environment: IndexerEnvironment) {
return Object.entries(DEPLOYMENTS).filter(([_, deployment]) => {
if (environment === "all") {
return true;
}

if (environment === "test") {
return deployment.isTestnet;
}
Expand All @@ -80,7 +84,7 @@ export class HypercertIndexer implements HypercertIndexerInterface {
return !deployment.isTestnet;
}

return true;
return false;
});
}

Expand Down
12 changes: 10 additions & 2 deletions sdk/src/types/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,16 @@ export type HypercertClientConfig = Deployment &
readOnly: boolean;
/** Reason for readOnly mode */
readOnlyReason?: string;
/** The environment to run the indexer in. This can be either production or test. */
/** The environment to run the indexer in. This can be either production, test or all. Defaults to test */
indexerEnvironment: IndexerEnvironment;
};

/**
* The environment to run the indexer in.
* Production will run against all mainnet chains, while test will run against testnet chains.
* All will run against both
*/
export type IndexerEnvironment = "production" | "test";
export type IndexerEnvironment = "production" | "test" | "all";

/**
* Configuration options for the Hypercert storage layer.
Expand Down Expand Up @@ -292,4 +293,11 @@ export interface HypercertClientMethods {
units: bigint[],
proofs: (Hex | ByteArray)[][],
) => Promise<`0x${string}` | undefined>;

/**
* Check if a claim or fraction is on the chain that the Hypercertclient
* is currently connected to
* @param claimOrFractionId The ID of the claim or fraction to check.
*/
isClaimOrFractionOnConnectedChain: (claimOrFractionId: string) => boolean;
}
9 changes: 9 additions & 0 deletions sdk/src/utils/chains.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { parseClaimOrFractionId } from "./parsing";

export const isClaimOnChain = (claimId: string, chainId: number | undefined) => {
if (chainId === undefined) {
return false;
}
const { chainId: parsedChainId } = parseClaimOrFractionId(claimId);
return parsedChainId === chainId;
};

0 comments on commit cc330a4

Please sign in to comment.