Skip to content

Commit

Permalink
Merge pull request #28 from merokudao/verification-change
Browse files Browse the repository at this point in the history
added verification sign
  • Loading branch information
piyush-bitpack committed Jan 4, 2024
2 parents db65a2c + 4e1e0db commit f9f8753
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/api/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/components/card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function ReviewCard(props) {
{review.userId}
<span className="text-[#87868C]">
&#x2022;{" "}
{`${date.getDate()}/${date.getMonth()}/${date.getFullYear()}`}
{`${date.getDate()}/${date.getMonth()+1}/${date.getFullYear()}`}
</span>
</p>
<StarRating rating={review.rating} />
Expand Down
11 changes: 9 additions & 2 deletions src/features/dapp/dapp_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,17 @@ export class DappDataSource implements IDappDataSource {
postReview(builder: EndpointBuilder<any, any, any>) {
return builder.mutation<void, any>({
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,
};
},
});
Expand Down
65 changes: 49 additions & 16 deletions src/pages/dapp/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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 <div className="h-[1px] bg-[#2D2C33]" />;
}
Expand Down Expand Up @@ -219,20 +232,26 @@ export function StarRating(props) {
onChange(rating);
}
}, [rating]);

const handleChangeRating = (ratings: number) => {
setHover(0);
setRating(ratings);
};

return (
<Row
className="gap-x-[4px]"
onMouseLeave={editable ? () => setRating(rating) : undefined}
onMouseLeave={editable ? () => handleChangeRating(rating) : undefined}
>
{[...Array(5)].map((_, idx) => {
idx += 1;
return (
<svg
onClick={editable ? () => 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"
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit f9f8753

Please sign in to comment.