Skip to content

Commit

Permalink
feat: wip marketplace
Browse files Browse the repository at this point in the history
  • Loading branch information
jinglescode committed Apr 30, 2024
1 parent 13c9b3a commit a912cd8
Show file tree
Hide file tree
Showing 14 changed files with 1,107 additions and 1,232 deletions.
25 changes: 2 additions & 23 deletions packages/demo/components/pages/contracts/escrow/cancelEscrow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import Button from '../../../ui/button';
import { CardanoWallet, useWallet } from '@meshsdk/react';
import { useState } from 'react';
import RunDemoResult from '../../../common/runDemoResult';
import { BlockfrostProvider, MeshTxBuilder } from '@meshsdk/core';
import { MeshEscrowContract } from '@meshsdk/contracts';
import useLocalStorage from '../../../../hooks/useLocalStorage';
import { getContract } from './common';

export default function EscrowCancel() {
return (
Expand Down Expand Up @@ -61,33 +60,13 @@ function Right() {
undefined
);

function getContract() {
const blockchainProvider = new BlockfrostProvider(
process.env.NEXT_PUBLIC_BLOCKFROST_API_KEY_PREPROD!
);

const meshTxBuilder = new MeshTxBuilder({
fetcher: blockchainProvider,
submitter: blockchainProvider,
});

const contract = new MeshEscrowContract({
mesh: meshTxBuilder,
fetcher: blockchainProvider,
wallet: wallet,
networkId: 0,
});

return contract;
}

async function rundemo() {
setLoading(true);
setResponse(null);
setResponseError(null);

try {
const contract = getContract();
const contract = getContract(wallet);

const utxo = await contract.getUtxoByTxHash(userLocalStorage);

Expand Down
22 changes: 22 additions & 0 deletions packages/demo/components/pages/contracts/escrow/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { MeshEscrowContract } from '@meshsdk/contracts';
import { BlockfrostProvider, MeshTxBuilder } from '@meshsdk/core';

export function getContract(wallet) {
const blockchainProvider = new BlockfrostProvider(
process.env.NEXT_PUBLIC_BLOCKFROST_API_KEY_PREPROD!
);

const meshTxBuilder = new MeshTxBuilder({
fetcher: blockchainProvider,
submitter: blockchainProvider,
});

const contract = new MeshEscrowContract({
mesh: meshTxBuilder,
fetcher: blockchainProvider,
wallet: wallet,
networkId: 0,
});

return contract;
}
25 changes: 2 additions & 23 deletions packages/demo/components/pages/contracts/escrow/completeEscrow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import Button from '../../../ui/button';
import { CardanoWallet, useWallet } from '@meshsdk/react';
import { useState } from 'react';
import RunDemoResult from '../../../common/runDemoResult';
import { BlockfrostProvider, MeshTxBuilder } from '@meshsdk/core';
import { MeshEscrowContract } from '@meshsdk/contracts';
import useLocalStorage from '../../../../hooks/useLocalStorage';
import { getContract } from './common';

export default function EscrowComplete() {
return (
Expand Down Expand Up @@ -82,33 +81,13 @@ function Right() {
undefined
);

function getContract() {
const blockchainProvider = new BlockfrostProvider(
process.env.NEXT_PUBLIC_BLOCKFROST_API_KEY_PREPROD!
);

const meshTxBuilder = new MeshTxBuilder({
fetcher: blockchainProvider,
submitter: blockchainProvider,
});

const contract = new MeshEscrowContract({
mesh: meshTxBuilder,
fetcher: blockchainProvider,
wallet: wallet,
networkId: 0,
});

return contract;
}

async function rundemo() {
setLoading(true);
setResponse(null);
setResponseError(null);

try {
const contract = getContract();
const contract = getContract(wallet);

const utxo = await contract.getUtxoByTxHash(userLocalStorage);

Expand Down
29 changes: 5 additions & 24 deletions packages/demo/components/pages/contracts/escrow/initiateEscrow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import Button from '../../../ui/button';
import { CardanoWallet, useWallet } from '@meshsdk/react';
import { useState } from 'react';
import RunDemoResult from '../../../common/runDemoResult';
import { Asset, BlockfrostProvider, MeshTxBuilder } from '@meshsdk/core';
import { MeshEscrowContract } from '@meshsdk/contracts';
import useLocalStorage from '../../../../hooks/useLocalStorage';
import { getContract } from './common';
import { Asset } from '@meshsdk/core';

export default function EscrowInitiate() {
return (
Expand Down Expand Up @@ -44,7 +44,8 @@ function Left() {
</p>
<ul>
<li>
<b>escrowAmount (Asset[])</b> - a list of assets user A is trading / sending
<b>escrowAmount (Asset[])</b> - a list of assets user A is trading /
sending
</li>
</ul>
<p>
Expand All @@ -66,33 +67,13 @@ function Right() {
undefined
);

function getContract() {
const blockchainProvider = new BlockfrostProvider(
process.env.NEXT_PUBLIC_BLOCKFROST_API_KEY_PREPROD!
);

const meshTxBuilder = new MeshTxBuilder({
fetcher: blockchainProvider,
submitter: blockchainProvider,
});

const contract = new MeshEscrowContract({
mesh: meshTxBuilder,
fetcher: blockchainProvider,
wallet: wallet,
networkId: 0,
});

return contract;
}

async function rundemo() {
setLoading(true);
setResponse(null);
setResponseError(null);

try {
const contract = getContract();
const contract = getContract(wallet);

const escrowAmount: Asset[] = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@ import Button from '../../../ui/button';
import { CardanoWallet, useWallet } from '@meshsdk/react';
import { useState } from 'react';
import RunDemoResult from '../../../common/runDemoResult';
import {
Asset,
BlockfrostProvider,
MeshTxBuilder,
PlutusScript,
resolvePlutusScriptAddress,
} from '@meshsdk/core';
import { MeshEscrowContract } from '@meshsdk/contracts';
import { Asset } from '@meshsdk/core';
import useLocalStorage from '../../../../hooks/useLocalStorage';
import Link from 'next/link';
import { getContract } from './common';

export default function EscrowDeposit() {
return (
Expand Down Expand Up @@ -57,7 +51,8 @@ function Left() {
<code>initiateEscrow()</code>
</li>
<li>
<b>depositAmount (Asset[])</b> - a list of assets user B is trading / sending
<b>depositAmount (Asset[])</b> - a list of assets user B is trading /
sending
</li>
</ul>
<Codeblock data={code} isJson={false} />
Expand All @@ -75,33 +70,13 @@ function Right() {
undefined
);

function getContract() {
const blockchainProvider = new BlockfrostProvider(
process.env.NEXT_PUBLIC_BLOCKFROST_API_KEY_PREPROD!
);

const meshTxBuilder = new MeshTxBuilder({
fetcher: blockchainProvider,
submitter: blockchainProvider,
});

const contract = new MeshEscrowContract({
mesh: meshTxBuilder,
fetcher: blockchainProvider,
wallet: wallet,
networkId: 0,
});

return contract;
}

async function rundemo() {
setLoading(true);
setResponse(null);
setResponseError(null);

try {
const contract = getContract();
const contract = getContract(wallet);

const utxo = await contract.getUtxoByTxHash(userLocalStorage);

Expand Down
22 changes: 22 additions & 0 deletions packages/demo/components/pages/contracts/giftcard/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { MeshGiftCardContract } from '@meshsdk/contracts';
import { BlockfrostProvider, MeshTxBuilder } from '@meshsdk/core';

export function getContract(wallet) {
const blockchainProvider = new BlockfrostProvider(
process.env.NEXT_PUBLIC_BLOCKFROST_API_KEY_PREPROD!
);

const meshTxBuilder = new MeshTxBuilder({
fetcher: blockchainProvider,
submitter: blockchainProvider,
});

const contract = new MeshGiftCardContract({
mesh: meshTxBuilder,
fetcher: blockchainProvider,
wallet: wallet,
networkId: 0,
});

return contract;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import Button from '../../../ui/button';
import { CardanoWallet, useWallet } from '@meshsdk/react';
import { useState } from 'react';
import RunDemoResult from '../../../common/runDemoResult';
import { Asset, BlockfrostProvider, MeshTxBuilder } from '@meshsdk/core';
import { MeshGiftCardContract } from '@meshsdk/contracts';
import { Asset } from '@meshsdk/core';
import useLocalStorage from '../../../../hooks/useLocalStorage';
import { getContract } from './common';

export default function GiftcardCreate() {
return (
Expand Down Expand Up @@ -73,33 +73,13 @@ function Right() {
undefined
);

function getContract() {
const blockchainProvider = new BlockfrostProvider(
process.env.NEXT_PUBLIC_BLOCKFROST_API_KEY_PREPROD!
);

const meshTxBuilder = new MeshTxBuilder({
fetcher: blockchainProvider,
submitter: blockchainProvider,
});

const contract = new MeshGiftCardContract({
mesh: meshTxBuilder,
fetcher: blockchainProvider,
wallet: wallet,
networkId: 0,
});

return contract;
}

async function rundemo() {
setLoading(true);
setResponse(null);
setResponseError(null);

try {
const contract = getContract();
const contract = getContract(wallet);

const tokenName = `Mesh_Gift_Card_${parseInt(
(Math.random() * 1000).toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@ import Button from '../../../ui/button';
import { CardanoWallet, useWallet } from '@meshsdk/react';
import { useState } from 'react';
import RunDemoResult from '../../../common/runDemoResult';
import {
BlockfrostProvider,
MeshTxBuilder,
PlutusScript,
resolvePlutusScriptAddress,
} from '@meshsdk/core';
import { MeshGiftCardContract } from '@meshsdk/contracts';
import useLocalStorage from '../../../../hooks/useLocalStorage';
import { getContract } from './common';

export default function GiftcardRedeem() {
return (
Expand Down Expand Up @@ -66,32 +60,13 @@ function Right() {
undefined
);

function getContract() {
const blockchainProvider = new BlockfrostProvider(
process.env.NEXT_PUBLIC_BLOCKFROST_API_KEY_PREPROD!
);

const meshTxBuilder = new MeshTxBuilder({
fetcher: blockchainProvider,
submitter: blockchainProvider,
});

const contract = new MeshGiftCardContract({
mesh: meshTxBuilder,
fetcher: blockchainProvider,
wallet: wallet,
});

return contract;
}

async function rundemo() {
setLoading(true);
setResponse(null);
setResponseError(null);

try {
const contract = getContract();
const contract = getContract(wallet);

const utxo = await contract.getUtxoByTxHash(userLocalStorage); // todo hinson: script address extracted from scriptCbor is not correct

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import { CardanoWallet, useWallet } from '@meshsdk/react';
import { useState } from 'react';
import RunDemoResult from '../../../common/runDemoResult';
import useLocalStorage from '../../../../hooks/useLocalStorage';
import { asset, getContract, price } from './config';
import { asset, getContract, price } from './common';
import Input from '../../../ui/input';
import { MeshMarketplaceContract } from '@meshsdk/contracts';
import { BlockfrostProvider, MeshTxBuilder } from '@meshsdk/core';

export default function MarketplaceListAsset() {
return (
Expand Down Expand Up @@ -65,15 +63,6 @@ function Right() {
);
const [listPrice, updateListPrice] = useState<number>(price);

let code1 = ``;
code1 += `const { wallet } = useWallet();\n`;
code1 += `const sellerAddress = (await wallet.getUsedAddresses())[0];\n`;
code1 += `const txHash = await marketplace.listAsset(\n`;
code1 += ` sellerAddress,\n`;
code1 += ` '${asset}',\n`;
code1 += ` ${listPrice}\n`;
code1 += `);`;

// async function rundemo() {
// setLoading(true);
// setResponse(null);
Expand Down Expand Up @@ -122,7 +111,6 @@ function Right() {
placeholder="Listing price in Lovelace"
label="Listing price in Lovelace"
/>
<Codeblock data={code1} isJson={false} />
{connected ? (
<>
<Button
Expand Down

0 comments on commit a912cd8

Please sign in to comment.