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

Upgrade embed dev #17

Merged
merged 6 commits into from
Feb 25, 2025
Merged
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
1 change: 1 addition & 0 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"dependencies": {
"@passportxyz/passport-embed": "^0.0.2",
"@tanstack/react-query": "^5.62.11",
"buffer": "^6.0.3",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
Expand Down
9 changes: 6 additions & 3 deletions example/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { createRoot } from "react-dom/client";
import { useState } from "react";
import { Buffer } from "buffer";
import {
PassportScoreWidget,
usePassportScore,
Expand All @@ -7,8 +9,6 @@ import {

import "./index.css";

import { useState } from "react";

const passportEmbedParams = {
apiKey: import.meta.env.VITE_API_KEY,
scorerId: import.meta.env.VITE_SCORER_ID,
Expand Down Expand Up @@ -51,10 +51,13 @@ const generateSignature = async (message: string) => {

const signerAddress = accounts[0];

const stringToSign = `0x${Buffer.from(message, "utf8").toString(
"hex"
)}`;
// Sign the message
const signature = await window.ethereum.request({
method: "personal_sign",
params: [message, signerAddress],
params: [stringToSign, signerAddress],
});

return signature ? signature : "";
Expand Down
275 changes: 26 additions & 249 deletions example/yarn.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
"dependencies": {
"@tanstack/react-query": "^5.62.11",
"axios": "^1.7.7",
"buffer": "^6.0.3",
"dompurify": "^3.2.4",
"html-react-parser": "^5.2.2"
}
Expand Down
9 changes: 1 addition & 8 deletions src/components/Body/PlatformVerification.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import styles from "./PlatformVerification.module.css";
import utilStyles from "../../utilStyles.module.css";
import { useEffect, useState } from "react";
import { Buffer } from "buffer";
import { Button } from "../Button";
import { Hyperlink } from "./ScoreTooLowBody";
import { ScrollableDiv } from "../ScrollableDiv";
Expand Down Expand Up @@ -144,12 +143,7 @@ export const PlatformVerification = ({
credential = challenge.credential;
const _challenge = challenge.credential.credentialSubject.challenge;

const challengeToSign = `0x${Buffer.from(
_challenge,
"utf8"
).toString("hex")}`;

signature = await generateSignatureCallback(challengeToSign);
signature = await generateSignatureCallback(_challenge);
}

if (platform.requiresPopup && platform.popupUrl) {
Expand Down Expand Up @@ -184,7 +178,6 @@ export const PlatformVerification = ({
if (popup.closed) {
clearInterval(checkPopupClosed);
console.log("Pop-up closed");
alert("OAuth process completed or cancelled. Interval check");
// Refresh stamps
verifyCredentials(platformCredentialIds);
}
Expand Down
8 changes: 4 additions & 4 deletions test/components/PlatformVerification.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { render, screen, fireEvent, waitFor } from "@testing-library/react";
import { PlatformVerification } from "../../src/components/Body/PlatformVerification";
import * as usePassportScore from "../../src/hooks/usePassportScore";
import * as usePlatformStatus from "../../src/hooks/usePlatformStatus";
import * as QueryContext from "../../src/contexts/QueryContext";
import * as useQueryContext from "../../src/hooks/useQueryContext";
import {
mockExpectedConsoleErrorLog,
setupTestQueryClient,
Expand All @@ -14,7 +14,7 @@ import { Platform } from "../../src/hooks/useStampPages";
// Mock the hooks
jest.mock("../../src/hooks/usePassportScore");
jest.mock("../../src/hooks/usePlatformStatus");
jest.mock("../../src/contexts/QueryContext");
jest.mock("../../src/hooks/useQueryContext");

// Mock fetch
global.fetch = jest.fn();
Expand Down Expand Up @@ -48,7 +48,7 @@ describe("PlatformVerification", () => {
(usePlatformStatus.usePlatformStatus as jest.Mock).mockReturnValue({
claimed: false,
});
(QueryContext.useQueryContext as jest.Mock).mockReturnValue({
(useQueryContext.useQueryContext as jest.Mock).mockReturnValue({
address: "0x123",
embedServiceUrl: "https://test.com",
});
Expand Down Expand Up @@ -196,7 +196,7 @@ describe("PlatformVerification", () => {

it("handles missing address error", async () => {
// Mock missing address in context
(QueryContext.useQueryContext as jest.Mock).mockReturnValue({
(useQueryContext.useQueryContext as jest.Mock).mockReturnValue({
address: null,
});

Expand Down
4 changes: 2 additions & 2 deletions test/components/ScoreTooLowBody.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import {
useWidgetPassportScore,
useWidgetVerifyCredentials,
} from "../../src/hooks/usePassportScore";
import { useHeaderControls } from "../../src/contexts/HeaderContext";
import { useHeaderControls } from "../../src/hooks/useHeaderControls";

jest.mock("../../src/hooks/usePassportScore");
jest.mock("../../src/contexts/HeaderContext");
jest.mock("../../src/hooks/useHeaderControls");

jest.mock("../../src/utils/stampDataApi", () => ({
fetchStampPages: jest.fn().mockResolvedValue([
Expand Down
Loading