Skip to content

Commit e82d0d2

Browse files
committed
add signing message operation
1 parent 5dbc5fa commit e82d0d2

6 files changed

Lines changed: 123 additions & 73 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
### [0.10.0](https://github.com/xdevguild/buildo.dev/releases/tag/v0.10.0) (2023-12-01)
2+
- add sign a message operation
3+
14
### [0.9.0](https://github.com/xdevguild/buildo.dev/releases/tag/v0.9.0) (2023-11-29)
25
- add verify signature operation
36
- update dependencies

components/home-cards.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,16 @@ export const HomeCards = () => {
118118
setDialogState('general', 'multiTransfer');
119119
},
120120
},
121-
{
122-
title: 'Deploy a custom smart contract',
123-
description: 'You can deploy any custom smart contract',
124-
onClick: () => {},
125-
disabled: true,
126-
},
127121
{
128122
title: 'Sign a message',
129123
description: 'You can sign any message using your wallet',
124+
onClick: () => {
125+
setDialogState('general', 'signMessage');
126+
},
127+
},
128+
{
129+
title: 'Deploy a custom smart contract',
130+
description: 'You can deploy any custom smart contract',
130131
onClick: () => {},
131132
disabled: true,
132133
},
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import * as z from 'zod';
2+
import { useForm } from 'react-hook-form';
3+
import { zodResolver } from '@hookform/resolvers/zod';
4+
import { Form } from '@/components/ui/form';
5+
import {
6+
DialogFooter,
7+
DialogHeader,
8+
DialogTitle,
9+
} from '@/components/ui/dialog';
10+
import { OperationsInputField } from '@/components/operations/operations-input-field';
11+
import { OperationsSubmitButton } from '@/components/operations/operations-submit-button';
12+
import { DialogDescription } from '@radix-ui/react-dialog';
13+
import { useSignMessage } from '@useelven/core';
14+
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert';
15+
import { AlertCircle } from 'lucide-react';
16+
17+
const formSchema = z.object({
18+
message: z.string().min(1, 'The field is required'),
19+
});
20+
21+
export const SignMessage = () => {
22+
const { signMessage, pending, signature } = useSignMessage();
23+
24+
const form = useForm<z.infer<typeof formSchema>>({
25+
resolver: zodResolver(formSchema),
26+
defaultValues: {
27+
message: '',
28+
},
29+
});
30+
31+
const onSubmit = async ({ message }: z.infer<typeof formSchema>) => {
32+
signMessage({ message });
33+
};
34+
35+
return (
36+
<>
37+
<DialogHeader className="p-8 pb-0">
38+
<DialogTitle>Sign a message</DialogTitle>
39+
<DialogDescription>
40+
You can sign any message using your wallet address as a key. You can
41+
also verify signed messages. Check the Utilities section.
42+
</DialogDescription>
43+
</DialogHeader>
44+
<div className="overflow-y-auto py-0 px-8">
45+
<Form {...form}>
46+
<form
47+
id="sign-message-form"
48+
onSubmit={form.handleSubmit(onSubmit)}
49+
className="space-y-8"
50+
>
51+
<div className="flex-1 overflow-auto p-1">
52+
<OperationsInputField
53+
name="message"
54+
label="Message"
55+
type="textarea"
56+
placeholder="Example: <Your custom message...>"
57+
description="Please provide the message to sign"
58+
/>
59+
</div>
60+
</form>
61+
</Form>
62+
{signature && (
63+
<Alert className="break-words">
64+
<AlertCircle className="h-4 w-4" />
65+
<AlertTitle>The signature:</AlertTitle>
66+
<AlertDescription className="mt-3 font-bold">
67+
{signature}
68+
</AlertDescription>
69+
</Alert>
70+
)}
71+
</div>
72+
<DialogFooter className="py-4 px-8">
73+
<OperationsSubmitButton formId="sign-message-form" pending={pending} />
74+
</DialogFooter>
75+
</>
76+
);
77+
};

components/operations/operations-content-map.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import { AddNftUris } from '@/components/operations/non-fungible-tokens/add-nft-
4040
import { MultiTransfer } from '@/components/operations/general/multi-transfer';
4141
import { BurnNft } from '@/components/operations/non-fungible-tokens/burn';
4242
import { VerifySignature } from '@/components/operations/utils-operations/verify-signature';
43+
import { SignMessage } from '@/components/operations/general/sign-message';
4344

4445
export type OperationsContentMap = Record<
4546
string,
@@ -466,5 +467,8 @@ export const getOperationsContentsMap = ({
466467
additionalInfo: 'You have sent multiple ESDTs.',
467468
tokenTransfer: true,
468469
},
470+
signMessage: {
471+
component: <SignMessage />,
472+
},
469473
},
470474
});

package-lock.json

Lines changed: 29 additions & 64 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "buildo.dev",
3-
"version": "0.9.0",
3+
"version": "0.10.0",
44
"author": "Julian Ćwirko <julian.io>",
55
"license": "MIT",
66
"homepage": "https://www.buildo.dev",
@@ -31,7 +31,7 @@
3131
"@radix-ui/react-separator": "1.0.3",
3232
"@radix-ui/react-slot": "1.0.2",
3333
"@radix-ui/react-tooltip": "1.0.7",
34-
"@useelven/core": "0.11.0",
34+
"@useelven/core": "0.12.0",
3535
"axios": "1.6.2",
3636
"bignumber.js": "9.1.2",
3737
"buffer": "6.0.3",
@@ -52,7 +52,7 @@
5252
},
5353
"devDependencies": {
5454
"@types/keccak": "3.0.4",
55-
"@types/node": "20.10.0",
55+
"@types/node": "20.10.1",
5656
"@types/qrcode": "1.5.5",
5757
"@types/react": "18.2.39",
5858
"@types/react-dom": "18.2.17",

0 commit comments

Comments
 (0)