Skip to content

Commit

Permalink
refactor: Update AnyKeyValue and GroupRule type imports to use Fragme…
Browse files Browse the repository at this point in the history
…nt suffix
  • Loading branch information
bigint committed Mar 1, 2025
1 parent 7876abb commit f2950eb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
17 changes: 11 additions & 6 deletions apps/web/src/helpers/getAnyKeyValue.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
import type { AnyKeyValue } from "@hey/indexer";
import type { AnyKeyValueFragment } from "@hey/indexer";

const isAddressKeyValue = (
kv: AnyKeyValue
kv: AnyKeyValueFragment
): kv is { key: string; address: string; __typename: "AddressKeyValue" } =>
kv.__typename === "AddressKeyValue";

const isBigDecimalKeyValue = (
kv: AnyKeyValue
kv: AnyKeyValueFragment
): kv is {
key: string;
bigDecimal: string;
__typename: "BigDecimalKeyValue";
} => kv.__typename === "BigDecimalKeyValue";

const isStringKeyValue = (
kv: AnyKeyValue
kv: AnyKeyValueFragment
): kv is { key: string; string: string; __typename: "StringKeyValue" } =>
kv.__typename === "StringKeyValue";

const getAnyKeyValue = (
anyKeyValue: AnyKeyValue[],
anyKeyValue: AnyKeyValueFragment[],
key: string
): { address?: string; bigDecimal?: string; string?: string } | null => {
for (const item of anyKeyValue) {
if (item.key === key) {
if (
(item.__typename === "AddressKeyValue" ||
item.__typename === "BigDecimalKeyValue" ||
item.__typename === "StringKeyValue") &&
item.key === key
) {
if (isAddressKeyValue(item)) return { address: item.address };
if (isBigDecimalKeyValue(item)) return { bigDecimal: item.bigDecimal };
if (isStringKeyValue(item)) return { string: item.string };
Expand Down
8 changes: 4 additions & 4 deletions apps/web/src/helpers/rules.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type {
AccountFollowRule,
AccountFollowRuleFragment,
AccountFollowRules,
GroupRule,
GroupRuleFragment,
GroupRules
} from "@hey/indexer";
import getAnyKeyValue from "./getAnyKeyValue";

const extractMembershipApproval = (rules: GroupRule[]): boolean => {
const extractMembershipApproval = (rules: GroupRuleFragment[]): boolean => {
for (const rule of rules) {
if (rule.type === "MEMBERSHIP_APPROVAL") {
return true;
Expand All @@ -27,7 +27,7 @@ interface AssetDetails {
}

const extractPaymentDetails = (
rules: GroupRule[] | AccountFollowRule[]
rules: GroupRuleFragment[] | AccountFollowRuleFragment[]
): AssetDetails => {
for (const rule of rules) {
if (rule.type === "SIMPLE_PAYMENT") {
Expand Down
10 changes: 10 additions & 0 deletions packages/indexer/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,10 @@ export type AmountInput = {
value: Scalars['BigDecimal']['input'];
};

export type AnyJsonRequest = {
uri: Scalars['URI']['input'];
};

export type AnyKeyValue = AddressKeyValue | ArrayKeyValue | BigDecimalKeyValue | BooleanKeyValue | DictionaryKeyValue | IntKeyValue | IntNullableKeyValue | RawKeyValue | StringKeyValue;

export type AnyKeyValueInput = {
Expand Down Expand Up @@ -6064,6 +6068,7 @@ export type Query = {
accountsBulk: Array<Account>;
/** Get admins for a graph/app/sponsor/feed/username/group address */
adminsFor: PaginatedAdminsResult;
anyJson: Scalars['JSON']['output'];
/** Get an app */
app?: Maybe<App>;
/** Get the feeds for an app */
Expand Down Expand Up @@ -6243,6 +6248,11 @@ export type QueryAdminsForArgs = {
};


export type QueryAnyJsonArgs = {
request: AnyJsonRequest;
};


export type QueryAppArgs = {
request: AppRequest;
};
Expand Down

0 comments on commit f2950eb

Please sign in to comment.