Skip to content

Commit

Permalink
💄 Code format
Browse files Browse the repository at this point in the history
  • Loading branch information
bal7hazar committed Jan 13, 2025
1 parent 6ca23ce commit e42e30a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 47 deletions.
31 changes: 16 additions & 15 deletions packages/sdk/src/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@ import { init } from "@dojoengine/sdk";
import { config } from "../configs";
import { SchemaType, schema } from "../bindings/models.gen";

export const initSDK = async () => init<SchemaType>(
export const initSDK = async () =>
init<SchemaType>(
{
client: {
rpcUrl: config.rpcUrl,
toriiUrl: config.toriiUrl,
relayUrl: config.relayUrl,
worldAddress: config.manifest.world.address,
},
domain: {
name: "Arcade",
version: "1.0",
chainId: "KATANA",
revision: "1",
},
client: {
rpcUrl: config.rpcUrl,
toriiUrl: config.toriiUrl,
relayUrl: config.relayUrl,
worldAddress: config.manifest.world.address,
},
domain: {
name: "Arcade",
version: "1.0",
chainId: "KATANA",
revision: "1",
},
},
schema
);
schema,
);
40 changes: 24 additions & 16 deletions packages/sdk/src/modules/registry/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,35 +120,44 @@ export const Game = {
Game.sdk = sdk;
},

fetch: async (
callback: (models: GameModel[]) => void,
) => {
fetch: async (callback: (models: GameModel[]) => void) => {
if (!Game.sdk) return;

const wrappedCallback = ({ data, error }: { data?: StandardizedQueryResult<SchemaType> | StandardizedQueryResult<SchemaType>[] | undefined; error?: Error | undefined; }) => {
const wrappedCallback = ({
data,
error,
}: {
data?: StandardizedQueryResult<SchemaType> | StandardizedQueryResult<SchemaType>[] | undefined;
error?: Error | undefined;
}) => {
if (error) {
console.error("Error fetching entities:", error);
return;
}
if (!data) return;
const models = (data as ParsedEntity<SchemaType>[]).map((entity) => GameModel.from(entity.models[NAMESPACE][MODEL_NAME]));
const models = (data as ParsedEntity<SchemaType>[]).map((entity) =>
GameModel.from(entity.models[NAMESPACE][MODEL_NAME]),
);
callback(models);
};

const query = new QueryBuilder<SchemaType>()
.namespace(NAMESPACE, (namespace) =>
namespace.entity(MODEL_NAME, (entity) => entity.neq("world_address", "0x0")))
.build()
.namespace(NAMESPACE, (namespace) => namespace.entity(MODEL_NAME, (entity) => entity.neq("world_address", "0x0")))
.build();

await Game.sdk.getEntities({ query, callback: wrappedCallback });
},

sub: async (
callback: (event: GameModel) => void,
) => {
sub: async (callback: (event: GameModel) => void) => {
if (!Game.sdk) return;

const wrappedCallback = ({ data, error }: { data?: StandardizedQueryResult<SchemaType> | StandardizedQueryResult<SchemaType>[] | undefined; error?: Error | undefined; }) => {

const wrappedCallback = ({
data,
error,
}: {
data?: StandardizedQueryResult<SchemaType> | StandardizedQueryResult<SchemaType>[] | undefined;
error?: Error | undefined;
}) => {
if (error) {
console.error("Error subscribing to entities:", error);
return;
Expand All @@ -159,9 +168,8 @@ export const Game = {
};

const query = new QueryBuilder<SchemaType>()
.namespace(NAMESPACE, (namespace) =>
namespace.entity(MODEL_NAME, (entity) => entity.neq("world_address", "0x0")))
.build()
.namespace(NAMESPACE, (namespace) => namespace.entity(MODEL_NAME, (entity) => entity.neq("world_address", "0x0")))
.build();

const subscription = await Game.sdk.subscribeEntityQuery({ query, callback: wrappedCallback });
Game.unsubscribe = () => subscription.cancel();
Expand Down
40 changes: 24 additions & 16 deletions packages/sdk/src/modules/registry/pinning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,44 @@ export const Pinning = {
Pinning.sdk = sdk;
},

fetch: async (
callback: (models: PinningEvent[]) => void,
) => {
fetch: async (callback: (models: PinningEvent[]) => void) => {
if (!Pinning.sdk) return;

const wrappedCallback = ({ data, error }: { data?: StandardizedQueryResult<SchemaType> | StandardizedQueryResult<SchemaType>[] | undefined; error?: Error | undefined; }) => {
const wrappedCallback = ({
data,
error,
}: {
data?: StandardizedQueryResult<SchemaType> | StandardizedQueryResult<SchemaType>[] | undefined;
error?: Error | undefined;
}) => {
if (error) {
console.error("Error fetching entities:", error);
return;
}
if (!data) return;
const models = (data as ParsedEntity<SchemaType>[]).map((entity) => PinningEvent.from(entity.models[NAMESPACE][MODEL_NAME]));
const models = (data as ParsedEntity<SchemaType>[]).map((entity) =>
PinningEvent.from(entity.models[NAMESPACE][MODEL_NAME]),
);
callback(models);
};

const query = new QueryBuilder<SchemaType>()
.namespace(NAMESPACE, (namespace) =>
namespace.entity(MODEL_NAME, (entity) => entity.neq("player_id", "0x0")))
.build()
.namespace(NAMESPACE, (namespace) => namespace.entity(MODEL_NAME, (entity) => entity.neq("player_id", "0x0")))
.build();

await Pinning.sdk.getEventMessages({ query, callback: wrappedCallback });
},

sub: async (
callback: (event: PinningEvent) => void,
) => {
sub: async (callback: (event: PinningEvent) => void) => {
if (!Pinning.sdk) return;

const wrappedCallback = ({ data, error }: { data?: StandardizedQueryResult<SchemaType> | StandardizedQueryResult<SchemaType>[] | undefined; error?: Error | undefined; }) => {

const wrappedCallback = ({
data,
error,
}: {
data?: StandardizedQueryResult<SchemaType> | StandardizedQueryResult<SchemaType>[] | undefined;
error?: Error | undefined;
}) => {
if (error) {
console.error("Error subscribing to entities:", error);
return;
Expand All @@ -71,9 +80,8 @@ export const Pinning = {
};

const query = new QueryBuilder<SchemaType>()
.namespace(NAMESPACE, (namespace) =>
namespace.entity(MODEL_NAME, (entity) => entity.neq("player_id", "0x0")))
.build()
.namespace(NAMESPACE, (namespace) => namespace.entity(MODEL_NAME, (entity) => entity.neq("player_id", "0x0")))
.build();

const subscription = await Pinning.sdk.subscribeEventQuery({ query, callback: wrappedCallback });
Pinning.unsubscribe = () => subscription.cancel();
Expand Down

0 comments on commit e42e30a

Please sign in to comment.