Skip to content

Commit 8e7df64

Browse files
committed
add deploy sc demo
1 parent 50ce60e commit 8e7df64

File tree

6 files changed

+161
-49
lines changed

6 files changed

+161
-49
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
### [9.4.0](https://github.com/xdevguild/nextjs-dapp-template/releases/tag/v9.4.0) (2023-12-03)
2+
- update useElven and add deploy a smart contract demo
3+
14
### [9.3.0](https://github.com/xdevguild/nextjs-dapp-template/releases/tag/v9.3.0) (2023-11-30)
25
- update useElven and add Sign message demo
36

components/demo/simple-demo.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { SimpleNftMintDemo } from './simple-nft-mint-demo';
1414
import { SimpleScQeryDemo } from './simple-sc-query-demo';
1515
import { shortenHash } from '@/lib/shortenHash';
1616
import { SimpleSignMessageDemo } from './sign-message-demo';
17+
import { SimpleDeployScDemo } from './simple-deploy-sc-demo';
1718

1819
export const SimpleDemo = () => {
1920
const [result, setResult] = useState<{ type: string; content: string }>();
@@ -65,6 +66,27 @@ export const SimpleDemo = () => {
6566
[]
6667
);
6768

69+
const handleDeployCb = useCallback(
70+
({ txResult, pending, error }: TransactionCallbackParams) => {
71+
if (txResult) {
72+
setResult({ type: 'tx', content: txResult.hash });
73+
setPending(false);
74+
setError(undefined);
75+
}
76+
if (pending) {
77+
setPending(true);
78+
setError(undefined);
79+
setResult(undefined);
80+
}
81+
if (error) {
82+
setError(error);
83+
setPending(false);
84+
setResult(undefined);
85+
}
86+
},
87+
[]
88+
);
89+
6890
const handleClose = useCallback(() => {
6991
setResult(undefined);
7092
setPending(false);
@@ -76,9 +98,10 @@ export const SimpleDemo = () => {
7698
<div className="flex gap-8 flex-wrap justify-center items-stretch mb-4 flex-col lg:flex-row">
7799
<SimpleEGLDTxDemo cb={handleTxCb} />
78100
<SimpleNftMintDemo cb={handleTxCb} />
101+
<SimpleScQeryDemo cb={handleQueryCb} />
79102
</div>
80103
<div className="flex gap-8 flex-wrap justify-center items-stretch mb-4 flex-col lg:flex-row">
81-
<SimpleScQeryDemo cb={handleQueryCb} />
104+
<SimpleDeployScDemo cb={handleDeployCb} />
82105
<SimpleSignMessageDemo />
83106
</div>
84107
{error && (
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
'use client';
2+
3+
import {
4+
TransactionCallbackParams,
5+
useConfig,
6+
useScDeploy,
7+
} from '@useelven/core';
8+
import { Card, CardContent, CardFooter } from '@/components/ui/card';
9+
import { Button } from '@/components/ui/button';
10+
11+
export const SimpleDeployScDemo = ({
12+
cb,
13+
}: {
14+
cb: (params: TransactionCallbackParams) => void;
15+
}) => {
16+
const { explorerAddress } = useConfig();
17+
const { deploy, scAddress, txResult, pending } = useScDeploy({ cb });
18+
19+
const handleDeploy = () => {
20+
deploy({ source: '/piggybank.wasm' });
21+
};
22+
23+
return (
24+
<Card className="flex-1 flex flex-col justify-between w-full">
25+
<CardContent className="mt-6">
26+
<div className="mb-4">
27+
You will be deploying a{' '}
28+
<a
29+
href="https://github.com/xdevguild/multiversx-simple-sc"
30+
target="_blank"
31+
className="underline"
32+
>
33+
<strong>Piggy Bank</strong>
34+
</a>{' '}
35+
simple smart contract.
36+
</div>
37+
{!pending && txResult && scAddress && (
38+
<div className="lg:max-w-lg w-full break-words white">
39+
Your deployed smart contract address:
40+
<br />
41+
<strong>
42+
<a
43+
href={`${explorerAddress}/accounts/${scAddress}`}
44+
target="_blank"
45+
>
46+
{scAddress}
47+
</a>
48+
</strong>
49+
</div>
50+
)}
51+
</CardContent>
52+
<CardFooter>
53+
<Button variant="outline" disabled={pending} onClick={handleDeploy}>
54+
{pending ? 'Pending...' : 'Deploy'}
55+
</Button>
56+
</CardFooter>
57+
</Card>
58+
);
59+
};

package-lock.json

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

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nextjs-dapp-template",
3-
"version": "9.3.0",
3+
"version": "9.4.0",
44
"author": "Julian Ćwirko <julian.io>",
55
"license": "MIT",
66
"homepage": "https://github.com/xdevguild/nextjs-dapp-template",
@@ -23,7 +23,7 @@
2323
"@radix-ui/react-dropdown-menu": "2.0.6",
2424
"@radix-ui/react-slot": "1.0.2",
2525
"@radix-ui/react-tooltip": "1.0.7",
26-
"@useelven/core": "0.12.0",
26+
"@useelven/core": "0.13.0",
2727
"class-variance-authority": "0.7.0",
2828
"clsx": "2.0.0",
2929
"lucide-react": "0.294.0",
@@ -32,22 +32,22 @@
3232
"qrcode": "1.5.3",
3333
"react": "18.2.0",
3434
"react-dom": "18.2.0",
35-
"tailwind-merge": "2.0.0",
35+
"tailwind-merge": "2.1.0",
3636
"tailwindcss": "3.3.5",
3737
"tailwindcss-animate": "1.0.7"
3838
},
3939
"devDependencies": {
40-
"@types/node": "20.10.1",
40+
"@types/node": "20.10.2",
4141
"@types/qrcode": "1.5.5",
42-
"@types/react": "18.2.39",
42+
"@types/react": "18.2.41",
4343
"@types/react-dom": "18.2.17",
4444
"@typescript-eslint/eslint-plugin": "6.13.1",
4545
"@typescript-eslint/parser": "6.13.1",
4646
"autoprefixer": "10.4.16",
47-
"eslint": "8.54.0",
47+
"eslint": "8.55.0",
4848
"eslint-config-next": "14.0.3",
49-
"eslint-config-prettier": "9.0.0",
50-
"postcss": "8.4.31",
49+
"eslint-config-prettier": "9.1.0",
50+
"postcss": "8.4.32",
5151
"prettier": "3.1.0",
5252
"typescript": "5.3.2"
5353
}

public/piggybank.wasm

2.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)