Skip to content

Commit

Permalink
Merge pull request #31 from MartifyLabs/plutus-v2
Browse files Browse the repository at this point in the history
Plutus V2 support & React components
  • Loading branch information
abdelkrimdev authored Nov 5, 2022
2 parents 30e5e01 + 9dd24a1 commit b3d264c
Show file tree
Hide file tree
Showing 227 changed files with 17,416 additions and 1,262 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,5 @@ dist
.DS_Store

_local
.rollup.cache
packages/cli
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ Explore the features on [Mesh Playground](https://mesh.martify.io/).
## Guides and documentations

- [Start a Web3 app on Next.js](https://mesh.martify.io/guides/nextjs)
- [CIP30 wallets intergration](https://mesh.martify.io/apis/browserwallet)
- [Transaction building, minting, burning, smart contracts and more](https://mesh.martify.io/apis/transaction)
- [Minting on Node.js](https://mesh.martify.io/guides/mintingonnodejs)
- [App Wallet - Wallet for building transactions on your applications](https://mesh.martify.io/apis/appwallet)
- [Browser Wallet - CIP30 wallets intergration](https://mesh.martify.io/apis/browserwallet)
- [Transaction - Building, minting, burning, smart contracts and more](https://mesh.martify.io/apis/transaction)
- [Resolvers - Helpful functions that you need while building dApps](https://mesh.martify.io/apis/resolvers)

## Why use Mesh
- Always up to date - Vasil-ready, developed promptly as the network updates so your app always works
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion examples/NodeJS-Minting/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "mesh-mint-nodejs",
"name": "nodejs-minting",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
Expand Down
3 changes: 3 additions & 0 deletions examples/nextjs-connectwallet/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
36 changes: 36 additions & 0 deletions examples/nextjs-connectwallet/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
34 changes: 34 additions & 0 deletions examples/nextjs-connectwallet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file.

[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`.

The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
59 changes: 59 additions & 0 deletions examples/nextjs-connectwallet/components/connectWallet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { useEffect, useState } from 'react';
import { BrowserWallet } from '@martifylabs/mesh';
import type { Wallet } from '@martifylabs/mesh';
import useWallet from '../contexts/wallet';

export default function ConnectWallet() {
const [availableWallets, setAvailableWallets] = useState<
Wallet[] | undefined
>(undefined);
const { walletNameConnected, connecting, connectWallet, walletConnected } =
useWallet();

useEffect(() => {
async function init() {
setAvailableWallets(BrowserWallet.getInstalledWallets());
}
init();
}, []);

return (
<>
{availableWallets
? availableWallets.length == 0
? 'No wallets found'
: availableWallets.map((wallet, i) => (
<button
key={i}
onClick={() => connectWallet(wallet.name)}
disabled={
walletConnected ||
connecting ||
walletNameConnected == wallet.name
}
style={{
fontWeight:
walletNameConnected == wallet.name ? 'bold' : 'normal',
margin: '8px',
backgroundColor:
walletNameConnected == wallet.name
? 'green'
: connecting
? 'orange'
: 'grey',
}}
>
<img
src={wallet.icon}
style={{
width: '40px',
height: '40px',
}}
/>
Connect with {wallet.name}
</button>
))
: ''}
</>
);
}
55 changes: 55 additions & 0 deletions examples/nextjs-connectwallet/contexts/wallet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React, {
createContext,
useState,
useContext,
useMemo,
ReactNode,
} from 'react';
import { BrowserWallet } from '@martifylabs/mesh';

const WalletContext = createContext({
wallet: {} as BrowserWallet,
connecting: false,
walletNameConnected: '',
walletConnected: false,
connectWallet: async (walletName: string) => {},
});

export const WalletProvider = ({ children }: { children: ReactNode }) => {
const [wallet, setWallet] = useState<BrowserWallet>({} as BrowserWallet);
const [walletConnected, setWalletConnected] = useState<boolean>(false);
const [connecting, setConnecting] = useState<boolean>(false);
const [walletNameConnected, setWalletNameConnected] = useState<string>('');

const connectWallet = async (walletName: string) => {
setConnecting(true);
const _wallet = await BrowserWallet.enable(walletName);
if (_wallet) {
setWallet(_wallet);
setWalletNameConnected(walletName);
setWalletConnected(true);
}
setConnecting(false);
};

const memoedValue = useMemo(
() => ({
wallet,
connecting,
walletNameConnected,
walletConnected,
connectWallet,
}),
[wallet, walletConnected, connecting, walletNameConnected]
);

return (
<WalletContext.Provider value={memoedValue}>
{children}
</WalletContext.Provider>
);
};

export default function useWallet() {
return useContext(WalletContext);
}
11 changes: 11 additions & 0 deletions examples/nextjs-connectwallet/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
webpack: function (config, options) {
config.experiments = {
asyncWebAssembly: true,
};
return config;
},
};
module.exports = nextConfig;
25 changes: 25 additions & 0 deletions examples/nextjs-connectwallet/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "nextjs-connectwallet",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@martifylabs/mesh": "^1.1.0",
"next": "12.3.1",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"@types/node": "18.8.2",
"@types/react": "18.0.21",
"@types/react-dom": "18.0.6",
"eslint": "8.24.0",
"eslint-config-next": "12.3.1",
"typescript": "4.8.4"
}
}
13 changes: 13 additions & 0 deletions examples/nextjs-connectwallet/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import "../styles/globals.css";
import type { AppProps } from "next/app";
import { WalletProvider } from "../contexts/wallet";

function MyApp({ Component, pageProps }: AppProps) {
return (
<WalletProvider>
<Component {...pageProps} />
</WalletProvider>
);
}

export default MyApp;
13 changes: 13 additions & 0 deletions examples/nextjs-connectwallet/pages/api/hello.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from 'next'

type Data = {
name: string
}

export default function handler(
req: NextApiRequest,
res: NextApiResponse<Data>
) {
res.status(200).json({ name: 'John Doe' })
}
52 changes: 52 additions & 0 deletions examples/nextjs-connectwallet/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { useState } from "react";
import type { NextPage } from "next";
import useWallet from "../contexts/wallet";
import ConnectWallet from "../components/connectWallet";

const Home: NextPage = () => {
const { wallet, walletConnected, connecting } = useWallet();
const [assets, setAssets] = useState<null | any>(null);
const [loading, setLoading] = useState<boolean>(false);

async function getAssets() {
if (wallet) {
setLoading(true);
const _assets = await wallet.getAssets();
setAssets(_assets);
setLoading(false);
}
}

return (
<div>
<h1>Connect Wallet</h1>
<ConnectWallet />
{walletConnected && (
<>
<h1>Get Wallet Assets</h1>
{assets ? (
<pre>
<code className="language-js">
{JSON.stringify(assets, null, 2)}
</code>
</pre>
) : (
<button
type="button"
onClick={() => getAssets()}
disabled={connecting || loading}
style={{
margin: "8px",
backgroundColor: connecting || loading ? "orange" : "grey",
}}
>
Get Wallet Assets
</button>
)}
</>
)}
</div>
);
};

export default Home;
Binary file added examples/nextjs-connectwallet/public/favicon.ico
Binary file not shown.
4 changes: 4 additions & 0 deletions examples/nextjs-connectwallet/public/vercel.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

1 comment on commit b3d264c

@vercel
Copy link

@vercel vercel bot commented on b3d264c Nov 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.