-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from MartifyLabs/plutus-v2
Plutus V2 support & React components
- Loading branch information
Showing
227 changed files
with
17,416 additions
and
1,262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,3 +109,5 @@ dist | |
.DS_Store | ||
|
||
_local | ||
.rollup.cache | ||
packages/cli |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "next/core-web-vitals" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
59
examples/nextjs-connectwallet/components/connectWallet.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
)) | ||
: ''} | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
b3d264c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
mesh – ./
mesh-nu.vercel.app
mesh-martifylabs.vercel.app
mesh-git-main-martifylabs.vercel.app
mesh.martify.io