Skip to content

Commit

Permalink
gov update
Browse files Browse the repository at this point in the history
  • Loading branch information
jinglescode committed Nov 20, 2024
1 parent ab51be0 commit 5d3e16f
Show file tree
Hide file tree
Showing 7 changed files with 1,224 additions and 2,677 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function GovernanceDeregistration() {
return (
<TwoColumnsScroll
sidebarTo="deregistration"
title="DRep Deregistration"
title="DRep Retirement"
leftSection={Left()}
rightSection={Right()}
/>
Expand Down Expand Up @@ -127,7 +127,7 @@ function Right() {

return (
<LiveCodeDemo
title="DRep De-registration"
title="DRep Retirement"
subtitle="Retire a DRep certificate amd return the deposit"
code={codeSnippet}
runCodeFunction={runDemo}
Expand Down
11 changes: 7 additions & 4 deletions apps/playground/src/pages/apis/txbuilder/governance/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ import { metaTxbuilderGovernance } from "~/data/links-txbuilders";
import { Intro } from "../common";
import GovernanceDeregistration from "./deregistration";
import GovernanceRegistration from "./registration";
import GovernanceVoteDelegation from "./vote-delegation";
import GovernanceUpdate from "./update";
import GovernanceVote from "./vote";
import GovernanceVoteDelegation from "./vote-delegation";

const ReactPage: NextPage = () => {
const sidebarItems = [
{ label: "DRep Registration", to: "registration" },
{ label: "DRep Deregistration", to: "deregistration" },
{ label: "Vote Delegation", to: "delegation" },
{ label: "DRep Registration", to: "registration" },
{ label: "DRep Update", to: "update" },
{ label: "DRep Retirement", to: "deregistration" },
{ label: "Vote", to: "vote" },
];

Expand Down Expand Up @@ -48,9 +50,10 @@ const ReactPage: NextPage = () => {
</TitleIconDescriptionBody>
<ButtonFloatDocumentation href="https://docs.meshjs.dev/transactions/classes/MeshTxBuilder" />

<GovernanceVoteDelegation />
<GovernanceRegistration />
<GovernanceUpdate />
<GovernanceDeregistration />
<GovernanceVoteDelegation />
<GovernanceVote />
</SidebarFullwidth>
</>
Expand Down
154 changes: 154 additions & 0 deletions apps/playground/src/pages/apis/txbuilder/governance/update.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
import { useState } from "react";

import { getFile, hashDrepAnchor } from "@meshsdk/core";
import { useWallet } from "@meshsdk/react";

import Input from "~/components/form/input";
import Link from "~/components/link";
import InputTable from "~/components/sections/input-table";
import LiveCodeDemo from "~/components/sections/live-code-demo";
import TwoColumnsScroll from "~/components/sections/two-columns-scroll";
import Codeblock from "~/components/text/codeblock";
import { getTxBuilder } from "../common";

export default function GovernanceUpdate() {
return (
<TwoColumnsScroll
sidebarTo="update"
title="DRep Update"
leftSection={Left()}
rightSection={Right()}
/>
);
}

function Left() {
let codeTx = ``;
codeTx += `const utxos = await wallet.getUtxos();\n`;
codeTx += `const changeAddress = await wallet.getChangeAddress();\n`;
codeTx += `\n`;
codeTx += `txBuilder\n`;
codeTx += ` .drepUpdateCertificate(dRepId, {\n`;
codeTx += ` anchorUrl: anchorUrl,\n`;
codeTx += ` anchorDataHash: anchorHash,\n`;
codeTx += ` })\n`;
codeTx += ` .changeAddress(utxos)\n`;
codeTx += ` .selectUtxosFrom(selectedUtxos);\n`;

return (
<>
<p>Updating a DRep is similar to registering.</p>
<p>
We build the transaction by adding the DRep update certificate to the
transaction, providing the change address and the UTxOs needed for the
transaction's fees.
</p>
<Codeblock data={codeTx} />
<p>
This{" "}
<Link href="https://preprod.cardanoscan.io/transaction/4527e43097fb6135cf820a90f7cd30dba0b6463078ba9fa61305cbd7d1fa4e2f">
transaction
</Link>{" "}
is an example of a successful DRep update for{" "}
<Link href="https://preprod.cardanoscan.io/drep/drep1ytk3r5ddfk2cq66ygdtkwf9yck6hhy7uzhk2tgl5d53448skyutw7?tab=dRepUpdates">
DRep ID
</Link>
.
</p>
</>
);
}

function Right() {
const { wallet, connected } = useWallet();

const [anchorUrl, setAnchorUrl] = useState<string>("");

async function getMeshJsonHash(url: string) {
var drepAnchor = getFile(url);
const anchorObj = JSON.parse(drepAnchor);
const anchorHash = hashDrepAnchor(anchorObj);
return anchorHash;
}

async function runDemo() {
const dRep = await wallet.getDRep();

if (dRep === undefined)
throw new Error("No DRep key found, this wallet does not support CIP95");

const dRepId = dRep.dRepIDCip105;

let anchor: { anchorUrl: string; anchorDataHash: string } | undefined =
undefined;
if (anchorUrl.length > 0) {
const anchorHash = await getMeshJsonHash(anchorUrl);
anchor = {
anchorUrl: anchorUrl,
anchorDataHash: anchorHash,
};
}

const utxos = await wallet.getUtxos();
const changeAddress = await wallet.getChangeAddress();

const txBuilder = getTxBuilder();
txBuilder
.drepUpdateCertificate(dRepId, anchor)
.changeAddress(changeAddress)
.selectUtxosFrom(utxos);

const unsignedTx = await txBuilder.complete();
const signedTx = await wallet.signTx(unsignedTx);
const txHash = await wallet.submitTx(signedTx);
return txHash;
}

let codeSnippet = ``;
codeSnippet += `const dRep = await wallet.getDRep();\n`;
codeSnippet += `const dRepId = dRep.dRepIDCip105;\n`;
codeSnippet += `\n`;
codeSnippet += `const anchorUrl = '${anchorUrl}';\n`;
codeSnippet += `const anchorHash = await getMeshJsonHash(anchorUrl);\n`;
codeSnippet += `\n`;
codeSnippet += `const utxos = await wallet.getUtxos();\n`;
codeSnippet += `const changeAddress = await wallet.getChangeAddress();\n`;
codeSnippet += `\n`;
codeSnippet += `txBuilder\n`;
codeSnippet += ` .drepUpdateCertificate(dRepId, {\n`;
codeSnippet += ` anchorUrl: anchorUrl,\n`;
codeSnippet += ` anchorDataHash: anchorHash,\n`;
codeSnippet += ` })\n`;
codeSnippet += ` .changeAddress(changeAddress)\n`;
codeSnippet += ` .selectUtxosFrom(utxos);\n`;
codeSnippet += `\n`;
codeSnippet += `const unsignedTx = await txBuilder.complete();\n`;
codeSnippet += `const signedTx = await wallet.signTx(unsignedTx);\n`;
codeSnippet += `const txHash = await wallet.submitTx(signedTx);\n`;

return (
<LiveCodeDemo
title="DRep Update"
subtitle="Update DRep metadata"
code={codeSnippet}
runCodeFunction={runDemo}
disabled={!connected}
runDemoButtonTooltip={
!connected ? "Connect wallet to run this demo" : undefined
}
runDemoShowBrowseWalletConnect={true}
>
<InputTable
listInputs={[
<Input
value={anchorUrl}
onChange={(e) => setAnchorUrl(e.target.value)}
placeholder="Anchor Url (e.g. https://path.to/file-name.jsonld)"
label="Anchor Url"
key={0}
/>,
]}
/>
</LiveCodeDemo>
);
}
66 changes: 34 additions & 32 deletions apps/playground/src/pages/home/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import { useEffect, useState } from "react";
import { Suspense, useEffect, useState } from "react";
import { DocumentCheckIcon } from "@heroicons/react/24/solid";

import Link from "~/components/link";
import HeroTwoSections from "~/components/sections/hero-two-sections";
import Metatags from "~/components/site/metatags";

export default function HomePage() {
const [isSSR, setIsSSR] = useState(true);
useEffect(() => {
setIsSSR(false);
}, []);

return (
<>
<Metatags />
Expand All @@ -19,32 +14,7 @@ export default function HomePage() {
title="Web3 TypeScript SDK & off-chain Framework"
description="Mesh is a TypeScript open-source library providing numerous tools to easily build powerful dApps on the Cardano blockchain."
link={{ label: "Get started", href: "/getting-started" }}
image={
<div className="col-span-6 hidden h-96 lg:block">
{!isSSR ? (
<video className="w-full" autoPlay muted>
<source
src="/home/starter-template-cli.mp4"
type="video/mp4"
/>
Your browser does not support the video tag.
</video>
) : (
<>
<img
src="/logo-mesh/black/logo-mesh-black-512x512.png"
className="dark:hidden"
alt="mockup"
/>
<img
src="/logo-mesh/white/logo-mesh-white-512x512.png"
className="hidden dark:block"
alt="mockup dark"
/>
</>
)}
</div>
}
image={<Video />}
children={
<Link
href={`/about/catalyst`}
Expand All @@ -59,3 +29,35 @@ export default function HomePage() {
</>
);
}

function Video() {
const [isSSR, setIsSSR] = useState(true);
useEffect(() => {
setIsSSR(false);
}, []);
return (
<div className="col-span-6 hidden h-96 lg:block">
{!isSSR ? (
<Suspense fallback={<></>}>
<video className="w-full" autoPlay muted>
<source src="/home/starter-template-cli.mp4" type="video/mp4" />
Your browser does not support the video tag.
</video>
</Suspense>
) : (
<>
<img
src="/logo-mesh/black/logo-mesh-black-512x512.png"
className="dark:hidden"
alt="mockup"
/>
<img
src="/logo-mesh/white/logo-mesh-white-512x512.png"
className="hidden dark:block"
alt="mockup dark"
/>
</>
)}
</div>
);
}
4 changes: 1 addition & 3 deletions apps/playground/src/pages/providers/blockfrost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ const ReactPage: NextPage = () => {
];

let code1 = `import { BlockfrostProvider } from "@meshsdk/core";\n\n`;
code1 += `const blockchainProvider = new BlockfrostProvider(\n`;
code1 += ` '<Your-API-Key>'\n`;
code1 += `);\n`;
code1 += `const blockchainProvider = new BlockfrostProvider('<Your-API-Key>');\n`;

let code2 = `const blockchainProvider = new BlockfrostProvider('<BLOCKFROST_URL>');\n`;

Expand Down
Loading

0 comments on commit 5d3e16f

Please sign in to comment.