Skip to content

Commit

Permalink
style: run biome format
Browse files Browse the repository at this point in the history
  • Loading branch information
moreal committed Jul 28, 2024
1 parent 00066e6 commit 9a230ce
Show file tree
Hide file tree
Showing 8 changed files with 247 additions and 229 deletions.
4 changes: 1 addition & 3 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"recommendations": [
"biomejs.biome"
]
"recommendations": ["biomejs.biome"]
}
70 changes: 35 additions & 35 deletions codegen.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
import { CodegenConfig } from "@graphql-codegen/cli";

const config: CodegenConfig = {
schema: "./schema.graphql", // change to endpoint url after release
documents: "./src/graphql/*.graphql",
ignoreNoDocuments: true, // for better experience with the watcher
generates: {
"./src/generated/": {
preset: "client",
plugins: [],
config: {
scalars: {
ID: {
input: "string | number",
output: "string",
},
Address: {
input: "string",
output: "string",
},
BigInt: {
input: "string",
output: "string",
},
TxID: {
input: "string",
output: "string",
},
Long: {
input: "number",
output: "number",
},
Guid: {
input: "string",
output: "string",
},
schema: "./schema.graphql", // change to endpoint url after release
documents: "./src/graphql/*.graphql",
ignoreNoDocuments: true, // for better experience with the watcher
generates: {
"./src/generated/": {
preset: "client",
plugins: [],
config: {
scalars: {
ID: {
input: "string | number",
output: "string",
},
Address: {
input: "string",
output: "string",
},
BigInt: {
input: "string",
output: "string",
},
TxID: {
input: "string",
output: "string",
},
Long: {
input: "number",
output: "number",
},
Guid: {
input: "string",
output: "string",
},
},
},
},
},
},
},
};

export default config;
6 changes: 3 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
preset: "ts-jest",
testEnvironment: "node",
};
5 changes: 4 additions & 1 deletion src/events/assets-transferred.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { IHeadlessGraphQLClient } from "../headless-graphql-client";
import { AssetTransferredEvent } from "../types/asset-transferred-event";
import { TransactionLocation } from "../types/transaction-location";

export type ValidatedAssetTransferredEvent = Omit<AssetTransferredEvent, "memo"> & {
export type ValidatedAssetTransferredEvent = Omit<
AssetTransferredEvent,
"memo"
> & {
targetAddress: Address;
};

Expand Down
2 changes: 1 addition & 1 deletion src/events/garage-unload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export async function getGarageUnloadEvents(
try {
if (event.memo === null) {
console.error(
`Skip ${event.txId} because event.memo field is required but null.`
`Skip ${event.txId} because event.memo field is required but null.`,
);
continue;
}
Expand Down
80 changes: 55 additions & 25 deletions src/headless-graphql-client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { Address } from "@planetarium/account";
import { BencodexDictionary, Dictionary, Value, decode, isDictionary } from "@planetarium/bencodex";
import {
BencodexDictionary,
Dictionary,
Value,
decode,
isDictionary,
} from "@planetarium/bencodex";
import { Currency, FungibleAssetValue } from "@planetarium/tx";
import { Client, fetchExchange, mapExchange } from "@urql/core";
import { retryExchange } from "@urql/exchange-retry";
Expand Down Expand Up @@ -42,7 +48,7 @@ export interface IHeadlessGraphQLClient {
}

function isArray<T>(obj: unknown): obj is T[] {
return Array.isArray(obj)
return Array.isArray(obj);
}

export class HeadlessGraphQLClient implements IHeadlessGraphQLClient {
Expand Down Expand Up @@ -123,13 +129,15 @@ export class HeadlessGraphQLClient implements IHeadlessGraphQLClient {

return data.transaction.ncTransactions
.map((tx) => {
if (tx === null || tx.actions.length > 1 || tx.actions[0] === null) {
if (
tx === null ||
tx.actions.length > 1 ||
tx.actions[0] === null
) {
return null;
}

const action = decode(
Buffer.from(tx.actions[0].raw, "hex"),
);
const action = decode(Buffer.from(tx.actions[0].raw, "hex"));
if (!isDictionary(action)) {
return null;
}
Expand All @@ -144,22 +152,35 @@ export class HeadlessGraphQLClient implements IHeadlessGraphQLClient {
return null;
}

if (!(payload[0] instanceof Uint8Array) ||
if (
!(payload[0] instanceof Uint8Array) ||
!(isArray<Value>(payload[1]) || payload[1] === null) ||
!(isArray<Value>(payload[2]) || payload[2] === null) ||
!(typeof payload[3] === "string" || payload[3] === null)
) {
return null;
}

function isValidFungibleAssetValuePayload(x: Value): x is [Uint8Array, [BencodexDictionary, bigint]] {
return isArray<Value>(x) && x[0] instanceof Uint8Array &&
isArray<Value>(x[1]) && isDictionary(x[1][0]) && typeof x[1][1] === "bigint";
function isValidFungibleAssetValuePayload(
x: Value,
): x is [Uint8Array, [BencodexDictionary, bigint]] {
return (
isArray<Value>(x) &&
x[0] instanceof Uint8Array &&
isArray<Value>(x[1]) &&
isDictionary(x[1][0]) &&
typeof x[1][1] === "bigint"
);
}

function isValidFungibleItemPayload(x: Value): x is [Uint8Array, bigint] {
return isArray<Value>(x) && x[0] instanceof Uint8Array &&
typeof x[1] === "bigint";
function isValidFungibleItemPayload(
x: Value,
): x is [Uint8Array, bigint] {
return (
isArray<Value>(x) &&
x[0] instanceof Uint8Array &&
typeof x[1] === "bigint"
);
}

const recipientAvatarAddress = Address.fromBytes(payload[0]);
Expand Down Expand Up @@ -208,7 +229,9 @@ export class HeadlessGraphQLClient implements IHeadlessGraphQLClient {
}

async getBlockIndex(blockHash: BlockHash): Promise<number> {
const response = await this._client.query(GetBlockIndexDocument, { hash: blockHash });
const response = await this._client.query(GetBlockIndexDocument, {
hash: blockHash,
});
const block = response.data?.chainQuery.blockQuery?.block;
if (!block) {
throw new Error("Failed to fetch data through GraphQL.");
Expand All @@ -231,9 +254,9 @@ export class HeadlessGraphQLClient implements IHeadlessGraphQLClient {
const response = await this._client.query(GetBlockHashDocument, {
index,
});
const block = response.data?.chainQuery.blockQuery?.block;
const block = response.data?.chainQuery.blockQuery?.block;
if (!block) {
throw new Error("Failed to fetch data through GraphQL.");
throw new Error("Failed to fetch data through GraphQL.");
}

return block.hash;
Expand All @@ -247,17 +270,17 @@ export class HeadlessGraphQLClient implements IHeadlessGraphQLClient {
blockIndex,
});


const transactions = response.data?.transaction.ncTransactions;
if (!transactions) {
throw new Error("Invalid operation.");
}

return transactions.filter(x => x !== null)
.filter(x => x.actions.every(v => v !== null))
return transactions
.filter((x) => x !== null)
.filter((x) => x.actions.every((v) => v !== null))
.map((tx) => {
const txId = tx.id;
const actions = tx.actions.filter(x => x !== null);
const actions = tx.actions.filter((x) => x !== null);
const action = decode(
Buffer.from(actions[0].raw, "hex"),
) as Dictionary;
Expand Down Expand Up @@ -294,7 +317,9 @@ export class HeadlessGraphQLClient implements IHeadlessGraphQLClient {
}

async getNextTxNonce(address: string): Promise<number> {
const response = await this._client.query(GetNextTxNonceDocument, { address });
const response = await this._client.query(GetNextTxNonceDocument, {
address,
});
if (!response.data) {
throw new Error("Failed to fetch data through GraphQL.");
}
Expand All @@ -318,19 +343,24 @@ export class HeadlessGraphQLClient implements IHeadlessGraphQLClient {
}

async stageTransaction(payload: string): Promise<string> {
const response = await this._client.mutation(StageTransactionDocument, { payload });
const response = await this._client.mutation(StageTransactionDocument, {
payload,
});
const txid = response.data?.stageTransaction;
if (!txid) {
throw new Error("Failed to stage transaction.");
throw new Error("Failed to stage transaction.");
}

return txid;
}

async getTransactionResult(txId: TxId): Promise<TransactionResult> {
const response = await this._client.query(GetTransactionResultDocument, { txId });
const response = await this._client.query(
GetTransactionResultDocument,
{ txId },
);
if (!response.data) {
throw new Error("Failed to fetch data through GraphQL.");
throw new Error("Failed to fetch data through GraphQL.");
}

return response.data.transaction.transactionResult;
Expand Down
2 changes: 1 addition & 1 deletion src/slack/messages/bridge-event.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ISlackMessage, SlackMessageSymbol } from ".";
import { TxIdWithNetwork, ncscanTxLinkGetter } from "./utils";
import { ResponseType } from "@prisma/client"
import { ResponseType } from "@prisma/client";

export class BridgeEvent implements ISlackMessage {
[SlackMessageSymbol] = true as const;
Expand Down
Loading

0 comments on commit 9a230ce

Please sign in to comment.