Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update prettier CI #210

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Prettier
run: yarn prettier
run: yarn prettier-check
test:
name: Tests
runs-on: ubuntu-latest
Expand Down
19 changes: 8 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# Sismo App Store

Welcome to the [Sismo App Store](https://app-store-resources.sismo.io/), the central hub for discovering all apps built with [Sismo Connect](https://docs.sismo.io/sismo-docs/build-with-sismo-connect/getting-started).

Welcome to the [Sismo App Store](https://app-store-resources.sismo.io/), the central hub for discovering all apps built with [Sismo Connect](https://docs.sismo.io/sismo-docs/build-with-sismo-connect/getting-started).

## Building Applications with Sismo Connect

You have two approaches to start building applications with Sismo Connect:
1. **Templated App**: Leverage our ready-made templates. Modify the parameters according to your requirements to create your own Sismo Connect application.
Available templates include:
- zkForm template: More than just a gated form.
- zkTelegramBot template: Facilitates privacy-preserving gated telegram group chats.

1. **Templated App**: Leverage our ready-made templates. Modify the parameters according to your requirements to create your own Sismo Connect application.
Available templates include: - zkForm template: More than just a gated form. - zkTelegramBot template: Facilitates privacy-preserving gated telegram group chats.

2. Custom apps (soon): You will be able to build custom apps

Expand All @@ -18,6 +16,7 @@ Available templates include:
All configurations for templates are located in the [space-configs](./space-configs/) folder.

For example, the [configuration](./space-configs/demo/aave-chan-initiative.ts) for the [aave-chan-initiative](https://demo.apps.sismo.io/aave-chan-initiative/aci-swag) the configuration is setup in this files tree.

```bash
space-configs/
├── main
Expand All @@ -36,8 +35,8 @@ space-configs/
```

### Installation
To set up your environment, follow these steps:

To set up your environment, follow these steps:

```bash
yarn install
Expand Down Expand Up @@ -67,17 +66,15 @@ Now, access the application at http://localhost:3000
### Testing

Test are made using jest

```bash
yarn test
```

## Contact us

Contact us in [Telegram](https://bit.ly/builders-telegram) or [Discord](https://discord.gg/sismo) when you create a Pull Request. We will quickly review it. Once the PR is merged, your Space will appear in the App Store.
Contact us in [Telegram](https://bit.ly/builders-telegram) or [Discord](https://discord.gg/sismo) when you create a Pull Request. We will quickly review it. Once the PR is merged, your Space will appear in the App Store.

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.



4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"sync-all-apps-factory": "NEXT_PUBLIC_NODE_ENV=main yarn sync-apps-factory && NEXT_PUBLIC_NODE_ENV=demo yarn sync-apps-factory",
"upload-zk-drop-metadata": "yarn run build-config && tsx -r ./svgMock.js ./src/scripts/upload-metadata/upload-metadata.script.ts",
"sync-apps-factory": "yarn run build-config && tsx -r ./svgMock.js ./src/scripts/sync-apps-factory/sync-apps-factory.script.ts",
"prettier": "prettier --write 'src/**/*.ts' '.github' 'README.md'"
"prettier": "prettier --write 'src/**/*.ts' '.github' 'README.md'",
"prettier-check": "prettier --check 'src/**/*.ts' '.github' 'README.md'"
},
"dependencies": {
"@google-cloud/local-auth": "^2.1.1",
Expand Down Expand Up @@ -63,6 +64,7 @@
"@types/styled-components": "^5.1.26",
"@types/testing-library__jest-dom": "5.14.5",
"encoding": "^0.1.13",
"husky": "^8.0.3",
"jest": "^29.5.0",
"jest-date-mock": "^1.0.8",
"jest-environment-jsdom": "29.5.0",
Expand Down
28 changes: 12 additions & 16 deletions src/app/api/zk-badge/metadata/[id]/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,39 @@ import { decodeCollectionId } from "@/src/utils/collectionId";
import { spaceMock1, spaceMock2 } from "@/src/services/spaces-service/tests/spaces-mock";
import { GET } from "./route";

describe('GET /api/zk-badge/metadata/[i]', () => {

describe("GET /api/zk-badge/metadata/[i]", () => {
beforeEach(() => {
let spacesService = ServiceFactory.getSpacesService();
const configs = [
spaceMock1,
spaceMock2
]
const configs = [spaceMock1, spaceMock2];
spacesService.updateConfigs(configs);
})
});

afterEach(() => {
let configs = ServiceFactory.getSpaceConfigs();
let spacesService = ServiceFactory.getSpacesService();
spacesService.updateConfigs(configs);
})
it('should return an error response if no badge is found', async () => {
const req = new Request('https://example.com');
});

it("should return an error response if no badge is found", async () => {
const req = new Request("https://example.com");
const id = decodeCollectionId("1234");
const params = { id: id + ".json" };
const response = await GET(req, { params });
const data = await response.json();
expect(data).toEqual({ error: 'No badge found for id: 1234' });
expect(data).toEqual({ error: "No badge found for id: 1234" });
});

it('should return a badge if found', async () => {
const req = new Request('https://example.com');
it("should return a badge if found", async () => {
const req = new Request("https://example.com");
const id = decodeCollectionId("40000001");
const params = { id: id.toString() };

const response = await GET(req, { params });
const data = await response.json();
expect(data).toEqual({
expect(data).toEqual({
name: "Badge name",
description: "Badge description",
image: `https://example.com/api/zk-badge/image/40000001`,
});
});
});
});
43 changes: 25 additions & 18 deletions src/app/api/zk-badge/metadata/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,29 @@ import { ZkBadgeAppType } from "@/src/services/spaces-service";
import { encodeCollectionId } from "@/src/utils/collectionId";
import { NextResponse } from "next/server";


export async function GET(req: Request, { params }: { params: { id: string } }) {
const url = new URL(req.url);
const id = parseInt(params.id.split(".")[0]);
const spacesService = ServiceFactory.getSpacesService();
let apps = await spacesService.getApps();
apps = apps.filter(app => app.type === "zkBadge") ;
const badge = (apps as ZkBadgeAppType[]).find(app => parseInt(app.tokenId) === parseInt(encodeCollectionId(id)));
if (!badge) {
return NextResponse.json({
error: `No badge found for id: ${parseInt(encodeCollectionId(id))}`
})
}
return NextResponse.json({
name: badge.badgeMetadata.name,
description: badge.badgeMetadata.description,
image: url.protocol + "//" + url.hostname + (url.port ? ":" + url.port : "") + "/api/zk-badge/image/" + badge.tokenId
})
}
const url = new URL(req.url);
const id = parseInt(params.id.split(".")[0]);
const spacesService = ServiceFactory.getSpacesService();
let apps = await spacesService.getApps();
apps = apps.filter((app) => app.type === "zkBadge");
const badge = (apps as ZkBadgeAppType[]).find(
(app) => parseInt(app.tokenId) === parseInt(encodeCollectionId(id))
);
if (!badge) {
return NextResponse.json({
error: `No badge found for id: ${parseInt(encodeCollectionId(id))}`,
});
}
return NextResponse.json({
name: badge.badgeMetadata.name,
description: badge.badgeMetadata.description,
image:
url.protocol +
"//" +
url.hostname +
(url.port ? ":" + url.port : "") +
"/api/zk-badge/image/" +
badge.tokenId,
});
}
63 changes: 31 additions & 32 deletions src/app/api/zk-badge/relay-tx/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,41 @@
*/
import { POST } from "./route";


const mockMint = jest.fn().mockImplementation(() => Promise.resolve({ hash: 'mockTxHash' }));
const mockMint = jest.fn().mockImplementation(() => Promise.resolve({ hash: "mockTxHash" }));

jest.mock("../../../../libs/contracts/signers", () => {
return {
getDefenderRelayerSigner: jest.fn().mockReturnValue({}),
};
return {
getDefenderRelayerSigner: jest.fn().mockReturnValue({}),
};
});

jest.mock('../../../../libs/contracts/zk-badge', () => {
const originalModule = jest.requireActual("../../../../libs/contracts/zk-badge");
return {
__esModule: true,
...originalModule,
ZkBadgeContract: jest.fn().mockImplementation(() => {
return {
mint: mockMint,
};
}),
};
jest.mock("../../../../libs/contracts/zk-badge", () => {
const originalModule = jest.requireActual("../../../../libs/contracts/zk-badge");
return {
__esModule: true,
...originalModule,
ZkBadgeContract: jest.fn().mockImplementation(() => {
return {
mint: mockMint,
};
}),
};
});

describe('POST /api/zk-badge/relay-tx', () => {
it('calls mint with the correct arguments', async () => {
const req: any = {
json: jest.fn().mockResolvedValue({
responseBytes: 'mockResponseBytes',
destination: 'mockDestination',
tokenId: 'mockTokenId'
})
};
await POST(req);
expect(mockMint).toHaveBeenCalledWith({
responseBytes: 'mockResponseBytes',
address: 'mockDestination',
tokenId: 'mockTokenId'
});
describe("POST /api/zk-badge/relay-tx", () => {
it("calls mint with the correct arguments", async () => {
const req: any = {
json: jest.fn().mockResolvedValue({
responseBytes: "mockResponseBytes",
destination: "mockDestination",
tokenId: "mockTokenId",
}),
};
await POST(req);
expect(mockMint).toHaveBeenCalledWith({
responseBytes: "mockResponseBytes",
address: "mockDestination",
tokenId: "mockTokenId",
});
});
});
});
42 changes: 21 additions & 21 deletions src/app/api/zk-badge/relay-tx/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ import { ZkBadgeContract } from "@/src/libs/contracts/zk-badge";
import { NextResponse } from "next/server";

export async function POST(req: Request) {
const { responseBytes, destination, tokenId, chain } = await req.json();
const { responseBytes, destination, tokenId, chain } = await req.json();

const signer = getDefenderRelayerSigner(Network.Mumbai, env.defenderAPIKeys.zkBadge);
const zkMinterContract = new ZkBadgeContract({ network: chain, signer });
const signer = getDefenderRelayerSigner(Network.Mumbai, env.defenderAPIKeys.zkBadge);
const zkMinterContract = new ZkBadgeContract({ network: chain, signer });

try {
const tx = await zkMinterContract.mint({
responseBytes,
address: destination,
tokenId
});
return NextResponse.json({
success: true,
txHash: tx.hash
});
} catch (e) {
console.error(e);
return NextResponse.json({
code: "minting-error"
})
}
}
try {
const tx = await zkMinterContract.mint({
responseBytes,
address: destination,
tokenId,
});

return NextResponse.json({
success: true,
txHash: tx.hash,
});
} catch (e) {
console.error(e);
return NextResponse.json({
code: "minting-error",
});
}
}
2 changes: 1 addition & 1 deletion src/app/api/zk-form/verify/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function POST(req: Request) {
const store = ServiceFactory.getZkFormTableStore();
const spacesService = ServiceFactory.getSpacesService();

const apps = await spacesService.getApps({ where: { appSlug: appSlug, spaceSlug: spaceSlug }});
const apps = await spacesService.getApps({ where: { appSlug: appSlug, spaceSlug: spaceSlug } });

if (!apps || apps.length !== 1 || apps[0].type !== "zkForm") {
return errorResponse(`App ${appSlug} not found or not a zkForm app`);
Expand Down
6 changes: 4 additions & 2 deletions src/app/api/zk-telegram-bot/verify/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ export async function POST(req: Request) {
const logger = ServiceFactory.getLoggerService();
const userStore = ServiceFactory.getZkTelegramBotUserStore();
const spacesService = ServiceFactory.getSpacesService();

const { response, spaceSlug, appSlug } = await req.json();

const spaces = await spacesService.getSpaces({ where: { spaceSlug: spaceSlug } });
const apps = await spacesService.getApps({ where: { appSlug: appSlug, spaceSlug: spaces[0].slug }});
const apps = await spacesService.getApps({
where: { appSlug: appSlug, spaceSlug: spaces[0].slug },
});

if (!apps || apps.length !== 1) {
return errorResponse(`Failed to find app ${appSlug} in space ${spaceSlug}`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { encodeAbiParameters } from "viem";

export const getMessageSignature = ({ destination, tokenId }: {
destination: `0x${string}`, tokenId: string
}) => {
if (!destination || !tokenId) return "";
export const getMessageSignature = ({
destination,
tokenId,
}: {
destination: `0x${string}`;
tokenId: string;
}) => {
if (!destination || !tokenId) return "";

return encodeAbiParameters(
[{ type: "address", name: "destination" }, { type: "uint256", name: "tokenId" }],
[destination as `0x${string}`, BigInt(tokenId)]
);
};
return encodeAbiParameters(
[
{ type: "address", name: "destination" },
{ type: "uint256", name: "tokenId" },
],
[destination as `0x${string}`, BigInt(tokenId)]
);
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { encodeAbiParameters } from "viem";

export const getMessageSignature = ({ destination }: {
destination: `0x${string}`
}) => {
if (!destination) return "";
export const getMessageSignature = ({ destination }: { destination: `0x${string}` }) => {
if (!destination) return "";

return encodeAbiParameters(
[{ type: "address", name: "destination" }],
[destination as `0x${string}`]
);
};
return encodeAbiParameters(
[{ type: "address", name: "destination" }],
[destination as `0x${string}`]
);
};
Loading