Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs/value utils #269

Merged
merged 21 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified apps/playground/public/team/abdelkrim.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified apps/playground/public/team/felix.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified apps/playground/public/team/hinson.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified apps/playground/public/team/jingles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified apps/playground/public/team/tszwai.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions apps/playground/src/data/links-articles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { NewspaperIcon } from "@heroicons/react/24/solid";

import { MenuItem } from "~/types/menu-item";

export const articleNew16 = {
title: "What's new in Mesh 1.6",
desc: "",
link: "whats-new-in-16",
thumbnail: "/articles/develop-first-web-app.png",
image: "/articles/arches-1866598_1280.jpg",
};
export const articleMesh20 = {
title: "Introduce Mesh 2.0",
desc: "",
link: "typescript-cardano-sdk",
thumbnail: "/articles/develop-first-web-app.png",
image: "/articles/arches-1866598_1280.jpg",
};
export const articleElementsOfCardano = {
title: "Elements of Cardano",
desc: "Cardano represents a significant advancement in blockchain technology, offering a scalable, secure, and flexible platform that is well-suited for a wide range of applications. Its unique combination of public, permissionless infrastructure, proof-of-stake consensus, and support for smart contracts and native assets makes it a powerful tool for developers and enterprises alike.",
link: "elements-of-cardano",
thumbnail: "/articles/spices-4185324_640.png",
image: "/articles/spices-4185324_640.jpg",
};

export const linksArticles: MenuItem[] = [articleElementsOfCardano,articleMesh20, articleNew16];

export const metaArticles: MenuItem = {
link: `/blogs`,
title: "Blogs",
desc: "Read the latest blogs and articles about Mesh",
icon: NewspaperIcon,
items: linksArticles,
};
28 changes: 0 additions & 28 deletions apps/playground/src/data/links-blogs.ts

This file was deleted.

8 changes: 8 additions & 0 deletions apps/playground/src/data/links-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ export const metaDataJson = {
link: "/apis/data/json",
icon: Bars3Icon,
};
// todoß
export const metaDataValue = {
title: "Value",
desc: "Manipulate Cardano Value Easily",
link: "/apis/data/value",
icon: Bars3Icon,
};
export const metaDataCbor = {
title: "CBOR Data",
desc: "Parse and manipulate Cardano data with CBOR",
Expand All @@ -44,6 +51,7 @@ export const linksData: MenuItem[] = [
metaOverview,
metaDataMesh,
metaDataJson,
metaDataValue,
// metaDataCbor,
// metaDataUtils,
];
Expand Down
104 changes: 104 additions & 0 deletions apps/playground/src/pages/apis/data/value/accessor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { MeshValue } from "@meshsdk/common";

import LiveCodeDemo from "~/components/sections/live-code-demo";
import TwoColumnsScroll from "~/components/sections/two-columns-scroll";
import { mockUnit } from "./";

export default function ValueAccessor() {
return (
<TwoColumnsScroll
sidebarTo="ValueAccessor"
title="Value Methods for Accessing Mesh Data"
leftSection={Left()}
rightSection={Right()}
/>
);
}

function Left() {
return (
<>
<Section1 />
<Section2 />
</>
);
}

function Section1() {
return (
<>
<p>
<code>get</code> get the quantity of asset object per unit, with
parameters
</p>
<ul>
<li>
<b>unit</b> - the unit of the assets e.g. lovelace
</li>
</ul>
</>
);
}

function Section2() {
return (
<>
<p>
<code>units</code> get all asset units with no parameters (e.g. unit)
needed
</p>
</>
);
}

function Right() {
return (
<>
<LiveCodeDemo
title="Get"
subtitle="Get the quantity of asset object per lovelace unit"
code={getCode()}
runCodeFunction={runGetDemo}
/>
<LiveCodeDemo
title="Units"
subtitle="Get all asset units with no parameters needed"
code={getCode2()}
runCodeFunction={runUnitsDemo}
/>
</>
);
}

function getCode() {
return `
import { MeshValue } from "@meshsdk/common";
const value = new MeshValue({ lovelace: 20n });
return value.get("lovelace");
`;
}

async function runGetDemo() {
const value = new MeshValue({ lovelace: 20n });
value.get("lovelace");
return value;
}

function getCode2() {
return `
import { MeshValue } from "@meshsdk/common";
const value = new MeshValue({
lovelace: 20n,
[mockUnit]: 10n,
});
return value.units();
`;
}

async function runUnitsDemo() {
const value = new MeshValue({
lovelace: 20n,
[mockUnit]: 10n,
});
return value.units();
}
60 changes: 60 additions & 0 deletions apps/playground/src/pages/apis/data/value/addasset-operator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { Asset, MeshValue } from "@meshsdk/common";

import LiveCodeDemo from "~/components/sections/live-code-demo";
import TwoColumnsScroll from "~/components/sections/two-columns-scroll";

export default function AddAssetOperator() {
return (
<TwoColumnsScroll
sidebarTo="AddAssetOperator"
title="Operator - add an asset to the Value class's value record with parameters - asset"
leftSection={Left()}
rightSection={Right()}
/>
);
}

function Left() {
return (
<>
<p>
<code>addAsset</code> Add an asset to the Value class's value record
with parameters:
</p>
<ul>
<b>asset</b> - Asset to add
</ul>
</>
);
}

function Right() {
async function runAddAssetDemo() {
const value = new MeshValue();
const singleAsset: Asset = {
unit: "baefdc6c5b191be372a794cd8d40d839ec0dbdd3c28957267dc817001234",
quantity: "100",
};
value.addAsset(singleAsset);
return value.value;
}

let code = `
import { MeshValue } from "@meshsdk/common";
const value = new MeshValue();
const singleAsset: Asset = { unit: "baefdc6c5b191be372a794cd8d40d839ec0dbdd3c28957267dc817001234", quantity: "100" };
value.addAsset(singleAsset);
return value.value;
`;

return (
<>
<LiveCodeDemo
title="addAsset"
subtitle="Add an asset to the Value class's value record with parameters - asset"
code={code}
runCodeFunction={runAddAssetDemo}
/>
</>
);
}
73 changes: 73 additions & 0 deletions apps/playground/src/pages/apis/data/value/addassets-operator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { Asset, MeshValue } from "@meshsdk/common";

import LiveCodeDemo from "~/components/sections/live-code-demo";
import TwoColumnsScroll from "~/components/sections/two-columns-scroll";

export default function AddassetsOperator() {
return (
<TwoColumnsScroll
sidebarTo="AddassetsOperator"
title="Operator - add an array of assets to the Value class's value record with parameters - assets"
leftSection={Left()}
rightSection={Right()}
/>
);
}

function Left() {
return (
<>
<p>
<code>addAssets</code> Add an array of assets to the Value class's value
record with parameters:
</p>
<ul>
<b>assets</b> - Asset[] to add
</ul>
</>
);
}

function Right() {
async function runaddassetsDemo() {
const value = new MeshValue();
const assets: Asset[] = [
{
unit: "baefdc6c5b191be372a794cd8d40d839ec0dbdd3c28957267dc817001234",
quantity: "100",
},
{ unit: "lovelace", quantity: "10" },
{
unit: "baefdc6c5b191be372a794cd8d40d839ec0dbdd3c28957267dc817001234",
quantity: "100",
},
{ unit: "lovelace", quantity: "10" },
];
value.addAssets(assets);
return value.value;
}

let code = `
import { MeshValue } from "@meshsdk/common";
const value = new MeshValue();
const assets: Asset[] = [
{ unit: "baefdc6c5b191be372a794cd8d40d839ec0dbdd3c28957267dc817001234", quantity: "100" },
{ unit: "lovelace", quantity: "10" },
{ unit: "baefdc6c5b191be372a794cd8d40d839ec0dbdd3c28957267dc817001234", quantity: "100" },
{ unit: "lovelace", quantity: "10" },
];
value.addAssets(assets);
return value.value;
`;

return (
<>
<LiveCodeDemo
title="addAssets"
subtitle="Add an array of assets to the Value class's value record with parameters - assets"
code={code}
runCodeFunction={runaddassetsDemo}
/>
</>
);
}
Loading