From d3a0d4ab0bc6918402a034a97ce3453557c2f80c Mon Sep 17 00:00:00 2001 From: piyush-bitpack Date: Tue, 26 Dec 2023 17:16:12 +0530 Subject: [PATCH 1/2] added verification sign --- src/features/dapp/dapp_api.ts | 4 +++ src/pages/dapp/index.tsx | 65 ++++++++++++++++++++++++++--------- 2 files changed, 53 insertions(+), 16 deletions(-) diff --git a/src/features/dapp/dapp_api.ts b/src/features/dapp/dapp_api.ts index bbf4eeb..7bf3c84 100644 --- a/src/features/dapp/dapp_api.ts +++ b/src/features/dapp/dapp_api.ts @@ -186,6 +186,10 @@ export class DappDataSource implements IDappDataSource { query: ({ ...body }) => { return { url: `${ApiEndpoints.RATING}`, + headers: { + 'x-message': body?.message, + 'x-signature': body?.signature + }, method: "POST", body: body, }; diff --git a/src/pages/dapp/index.tsx b/src/pages/dapp/index.tsx index 627ef9e..0269e76 100644 --- a/src/pages/dapp/index.tsx +++ b/src/pages/dapp/index.tsx @@ -30,6 +30,7 @@ import { useSearchByIdQuery } from "../../features/search"; import { AppStrings } from "../constants"; import { convertUrl } from "../../utils"; import VerificationDetails from "../../components/VerificationDetails"; +import { signTypedData } from "@wagmi/core"; Modal.setAppElement("#__next"); @@ -62,6 +63,18 @@ const reviewModalStyle = { }, }; +// The named list of all type definitions +const types = { + Dapp: [ + { name: "Wallet", type: "address" }, + { name: "DappId", type: "string" }, + { name: "Rating", type: "string" }, + { name: "Review", type: "string" }, + { name: "Time", type: "string" }, + ], +}; + + function Divider(props) { return
; } @@ -219,20 +232,26 @@ export function StarRating(props) { onChange(rating); } }, [rating]); + + const handleChangeRating = (ratings: number) => { + setHover(0); + setRating(ratings); + }; + return ( setRating(rating) : undefined} + onMouseLeave={editable ? () => handleChangeRating(rating) : undefined} > {[...Array(5)].map((_, idx) => { idx += 1; return ( setRating(idx) : undefined} + onClick={editable ? () => handleChangeRating(idx) : undefined} onMouseEnter={editable ? () => setHover(idx) : undefined} - onMouseLeave={editable ? () => setRating(rating) : undefined} + onMouseLeave={editable ? () => handleChangeRating(rating) : undefined} className={`icon ${ - idx <= (rating || hover) ? "icon-filled" : null + idx <= (hover || rating) ? "icon-filled" : null }`} width="24" height="25" @@ -261,19 +280,33 @@ function ReviewDialog(props) { dappId: props.dappId, userAddress: address, } as Review); - const onSubmit = (evt) => { - console.log(result.isUpdating); - - postReview({ ...review, rating: review.rating ?? 0 }) - .unwrap() - .then((_) => { - props.onRequestClose(); - }) - .catch((err) => { - console.log(err); - setErrors(err); + const onSubmit = async (evt) => { + try { + const message = { + Wallet: address, + DappId: props.dappId, + Rating: review?.rating ? `${review.rating}` : `0`, + Review: review?.comment ?? "None", + Time: new Date().toString(), + }; + const sign = await signTypedData({ + domain: {}, + message, + primaryType: "Dapp", + types, }); - console.log(result.isUpdating); + postReview({ ...review, rating: review.rating ?? 0, signature: sign, message: JSON.stringify(message), }) + .unwrap() + .then((_) => { + props.onRequestClose(); + }) + .catch((err) => { + console.log(err); + setErrors(err); + }); + } catch (err: any) { + setErrors(err); + } }; if (errors) { From 4e1e0dbbf0ef9acd981229ec5d2e6b8c17f0e01b Mon Sep 17 00:00:00 2001 From: piyush-bitpack Date: Wed, 3 Jan 2024 15:15:21 +0530 Subject: [PATCH 2/2] changes route --- src/api/constants.ts | 1 + src/components/card/index.tsx | 2 +- src/features/dapp/dapp_api.ts | 7 +++++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/api/constants.ts b/src/api/constants.ts index df65106..aeeb074 100644 --- a/src/api/constants.ts +++ b/src/api/constants.ts @@ -19,6 +19,7 @@ export const ApiEndpoints = { SEARCH_BY_PKG_ID: "dapp/queryWithPackageId", REVIEWS: "reviews", RATING: "dapp/rate", + POSTRATING: "dapp/newRate", FETCH_USER: "fetchuser", POST_USER: "postuser", SEARCH: "dapp/search", diff --git a/src/components/card/index.tsx b/src/components/card/index.tsx index f3a029c..b7fb4c2 100644 --- a/src/components/card/index.tsx +++ b/src/components/card/index.tsx @@ -66,7 +66,7 @@ export function ReviewCard(props) { {review.userId} •{" "} - {`${date.getDate()}/${date.getMonth()}/${date.getFullYear()}`} + {`${date.getDate()}/${date.getMonth()+1}/${date.getFullYear()}`}

diff --git a/src/features/dapp/dapp_api.ts b/src/features/dapp/dapp_api.ts index 7bf3c84..c071c1e 100644 --- a/src/features/dapp/dapp_api.ts +++ b/src/features/dapp/dapp_api.ts @@ -184,14 +184,17 @@ export class DappDataSource implements IDappDataSource { postReview(builder: EndpointBuilder) { return builder.mutation({ query: ({ ...body }) => { + const newBody = {...body} + delete newBody?.signature + delete newBody?.message return { - url: `${ApiEndpoints.RATING}`, + url: `${ApiEndpoints.POSTRATING}`, headers: { 'x-message': body?.message, 'x-signature': body?.signature }, method: "POST", - body: body, + body: newBody, }; }, });