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 bbf4eeb..c071c1e 100644 --- a/src/features/dapp/dapp_api.ts +++ b/src/features/dapp/dapp_api.ts @@ -184,10 +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, }; }, }); 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) {