Init
This commit is contained in:
commit
3762066d53
|
@ -0,0 +1,23 @@
|
|||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
|
@ -0,0 +1,46 @@
|
|||
# Getting Started with Create React App
|
||||
|
||||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
|
||||
|
||||
## Available Scripts
|
||||
|
||||
In the project directory, you can run:
|
||||
|
||||
### `yarn start`
|
||||
|
||||
Runs the app in the development mode.\
|
||||
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
|
||||
|
||||
The page will reload if you make edits.\
|
||||
You will also see any lint errors in the console.
|
||||
|
||||
### `yarn test`
|
||||
|
||||
Launches the test runner in the interactive watch mode.\
|
||||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
|
||||
|
||||
### `yarn build`
|
||||
|
||||
Builds the app for production to the `build` folder.\
|
||||
It correctly bundles React in production mode and optimizes the build for the best performance.
|
||||
|
||||
The build is minified and the filenames include the hashes.\
|
||||
Your app is ready to be deployed!
|
||||
|
||||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
|
||||
|
||||
### `yarn eject`
|
||||
|
||||
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
|
||||
|
||||
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
|
||||
|
||||
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
|
||||
|
||||
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
|
||||
|
||||
## Learn More
|
||||
|
||||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
||||
|
||||
To learn React, check out the [React documentation](https://reactjs.org/).
|
|
@ -0,0 +1,58 @@
|
|||
{
|
||||
"name": "multisig-ui",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@material-ui/core": "^4.11.3",
|
||||
"@material-ui/icons": "^4.11.2",
|
||||
"@project-serum/anchor": "^0.4.4",
|
||||
"@project-serum/borsh": "^0.1.1",
|
||||
"@project-serum/common": "^0.0.1-beta.3",
|
||||
"@project-serum/sol-wallet-adapter": "^0.2.0",
|
||||
"@solana/spl-token": "^0.1.3",
|
||||
"@testing-library/jest-dom": "^5.11.4",
|
||||
"@testing-library/react": "^11.1.0",
|
||||
"@testing-library/user-event": "^12.1.10",
|
||||
"@types/jest": "^26.0.15",
|
||||
"@types/node": "^12.0.0",
|
||||
"@types/react": "^17.0.0",
|
||||
"@types/react-dom": "^17.0.0",
|
||||
"@types/react-router-dom": "^5.1.7",
|
||||
"bn.js": "^5.2.0",
|
||||
"buffer-layout": "^1.2.0",
|
||||
"js-base64": "^3.6.0",
|
||||
"notistack": "^1.0.6",
|
||||
"react": "^17.0.2",
|
||||
"react-dom": "^17.0.2",
|
||||
"react-redux": "^7.2.3",
|
||||
"react-router": "^5.2.0",
|
||||
"react-router-dom": "^5.2.0",
|
||||
"react-scripts": "4.0.3",
|
||||
"typescript": "^4.1.2",
|
||||
"web-vitals": "^1.0.1"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"react-app",
|
||||
"react-app/jest"
|
||||
]
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
|
@ -0,0 +1,43 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<meta
|
||||
name="description"
|
||||
content="Web site created using create-react-app"
|
||||
/>
|
||||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
||||
<!--
|
||||
manifest.json provides metadata used when your web app is installed on a
|
||||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
||||
-->
|
||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
||||
<!--
|
||||
Notice the use of %PUBLIC_URL% in the tags above.
|
||||
It will be replaced with the URL of the `public` folder during the build.
|
||||
Only files inside the `public` folder can be referenced from the HTML.
|
||||
|
||||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
||||
work correctly both with client-side routing and a non-root public URL.
|
||||
Learn how to configure a non-root public URL by running `npm run build`.
|
||||
-->
|
||||
<title>React App</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="root"></div>
|
||||
<!--
|
||||
This HTML file is a template.
|
||||
If you open it directly in the browser, you will see an empty page.
|
||||
|
||||
You can add webfonts, meta tags, or analytics to this file.
|
||||
The build step will place the bundled scripts into the <body> tag.
|
||||
|
||||
To begin the development, run `npm start` or `yarn start`.
|
||||
To create a production bundle, use `npm run build` or `yarn build`.
|
||||
-->
|
||||
</body>
|
||||
</html>
|
Binary file not shown.
After Width: | Height: | Size: 5.2 KiB |
Binary file not shown.
After Width: | Height: | Size: 9.4 KiB |
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"short_name": "React App",
|
||||
"name": "Create React App Sample",
|
||||
"icons": [
|
||||
{
|
||||
"src": "favicon.ico",
|
||||
"sizes": "64x64 32x32 24x24 16x16",
|
||||
"type": "image/x-icon"
|
||||
},
|
||||
{
|
||||
"src": "logo192.png",
|
||||
"type": "image/png",
|
||||
"sizes": "192x192"
|
||||
},
|
||||
{
|
||||
"src": "logo512.png",
|
||||
"type": "image/png",
|
||||
"sizes": "512x512"
|
||||
}
|
||||
],
|
||||
"start_url": ".",
|
||||
"display": "standalone",
|
||||
"theme_color": "#000000",
|
||||
"background_color": "#ffffff"
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
# https://www.robotstxt.org/robotstxt.html
|
||||
User-agent: *
|
||||
Disallow:
|
|
@ -0,0 +1,38 @@
|
|||
.App {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.App-logo {
|
||||
height: 40vmin;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: no-preference) {
|
||||
.App-logo {
|
||||
animation: App-logo-spin infinite 20s linear;
|
||||
}
|
||||
}
|
||||
|
||||
.App-header {
|
||||
background-color: #282c34;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: calc(10px + 2vmin);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.App-link {
|
||||
color: #61dafb;
|
||||
}
|
||||
|
||||
@keyframes App-logo-spin {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
import React from 'react';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import App from './App';
|
||||
|
||||
test('renders learn react link', () => {
|
||||
render(<App />);
|
||||
const linkElement = screen.getByText(/learn react/i);
|
||||
expect(linkElement).toBeInTheDocument();
|
||||
});
|
|
@ -0,0 +1,70 @@
|
|||
import React from 'react';
|
||||
import { Provider } from 'react-redux';
|
||||
import { useHistory, useLocation } from 'react-router';
|
||||
import { HashRouter, Route } from 'react-router-dom';
|
||||
import { SnackbarProvider } from 'notistack';
|
||||
import { MuiThemeProvider } from '@material-ui/core/styles';
|
||||
import CssBaseline from '@material-ui/core/CssBaseline';
|
||||
import { unstable_createMuiStrictModeTheme as createMuiTheme } from '@material-ui/core/styles';
|
||||
import { PublicKey } from '@solana/web3.js';
|
||||
import { store } from './store';
|
||||
import WalletProvider from './components/WalletProvider';
|
||||
import Layout from './components/Layout';
|
||||
import Multisig from './components/Multisig';
|
||||
|
||||
function App() {
|
||||
const theme = createMuiTheme({
|
||||
palette: {
|
||||
background: {
|
||||
default: 'rgb(255,255,255)',
|
||||
},
|
||||
},
|
||||
typography: {
|
||||
fontFamily: ['Source Sans Pro', 'sans-serif'].join(','),
|
||||
},
|
||||
overrides: {},
|
||||
});
|
||||
return (
|
||||
<Provider store={store}>
|
||||
<MuiThemeProvider theme={theme}>
|
||||
<CssBaseline />
|
||||
<SnackbarProvider maxSnack={5} autoHideDuration={8000}>
|
||||
<WalletProvider>
|
||||
<HashRouter basename={'/'}>
|
||||
<Layout>
|
||||
<Route exact path="/" component={MultisigPage} />
|
||||
<Route
|
||||
exact
|
||||
path="/:address"
|
||||
component={MultisigInstancePage}
|
||||
/>
|
||||
</Layout>
|
||||
</HashRouter>
|
||||
</WalletProvider>
|
||||
</SnackbarProvider>
|
||||
</MuiThemeProvider>
|
||||
</Provider>
|
||||
);
|
||||
}
|
||||
|
||||
function MultisigPage() {
|
||||
return (
|
||||
<Multisig />
|
||||
);
|
||||
}
|
||||
|
||||
export function MultisigInstancePage() {
|
||||
const history = useHistory();
|
||||
const location = useLocation();
|
||||
const path = location.pathname.split('/');
|
||||
if (path.length !== 2) {
|
||||
history.push(`/multisig`);
|
||||
return <></>;
|
||||
} else {
|
||||
const multisig = new PublicKey(path[1]);
|
||||
return <Multisig multisig={multisig} />;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default App;
|
|
@ -0,0 +1,75 @@
|
|||
import React from 'react';
|
||||
import Typography from '@material-ui/core/Typography';
|
||||
import Link from '@material-ui/core/Link';
|
||||
|
||||
export default function Footer() {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
zIndex: 99,
|
||||
position: 'fixed',
|
||||
width: '100%',
|
||||
bottom: 0,
|
||||
textAlign: 'center',
|
||||
height: '30px',
|
||||
backgroundColor: '#fbfbfb',
|
||||
borderTop: 'solid 1pt #ccc',
|
||||
display: 'flex',
|
||||
justifyContent: 'space-between',
|
||||
paddingLeft: '10px',
|
||||
paddingRight: '10px',
|
||||
}}
|
||||
>
|
||||
<div style={{ marginLeft: 'auto', marginRight: 'auto', display: 'flex' }}>
|
||||
<FooterButton
|
||||
href={
|
||||
'https://github.com/project-serum/anchor/blob/master/examples/lockup/docs/staking.md'
|
||||
}
|
||||
label={'Technical Documentation'}
|
||||
/>
|
||||
<FooterButton
|
||||
href={'https://github.com/project-serum/awesome-serum'}
|
||||
label={'Developer Resources'}
|
||||
/>
|
||||
<FooterButton
|
||||
href={'https://discord.com/channels/739225212658122886'}
|
||||
label={'Discord'}
|
||||
/>
|
||||
<FooterButton href={'https://t.me/ProjectSerum'} label={'Telegram'} />
|
||||
<FooterButton
|
||||
href={'https://github.com/project-serum'}
|
||||
label={'GitHub'}
|
||||
/>
|
||||
<FooterButton
|
||||
href={'https://solanabeach.io/'}
|
||||
label={'Solana Network'}
|
||||
isEnd={true}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
type FooterButtonProps = {
|
||||
label: string;
|
||||
href: string;
|
||||
isEnd?: boolean;
|
||||
};
|
||||
|
||||
function FooterButton(props: FooterButtonProps) {
|
||||
const { label, href, isEnd } = props;
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
flexDirection: 'column',
|
||||
marginRight: isEnd ? '' : '15px',
|
||||
}}
|
||||
>
|
||||
<Link href={href} target="_blank" color="inherit">
|
||||
<Typography style={{ fontSize: '14px' }}>{label}</Typography>
|
||||
</Link>
|
||||
</div>
|
||||
);
|
||||
}
|
|
@ -0,0 +1,350 @@
|
|||
import React, { useState, useEffect, ReactElement } from 'react';
|
||||
import { useSelector, useDispatch } from 'react-redux';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { useSnackbar } from 'notistack';
|
||||
import AppBar from '@material-ui/core/AppBar';
|
||||
import Toolbar from '@material-ui/core/Toolbar';
|
||||
import Select from '@material-ui/core/Select';
|
||||
import Menu from '@material-ui/core/Menu';
|
||||
import Link from '@material-ui/core/Link';
|
||||
import Typography from '@material-ui/core/Typography';
|
||||
import MenuItem from '@material-ui/core/MenuItem';
|
||||
import IconButton from '@material-ui/core/IconButton';
|
||||
import ExitToAppIcon from '@material-ui/icons/ExitToApp';
|
||||
import Button from '@material-ui/core/Button';
|
||||
import PersonIcon from '@material-ui/icons/Person';
|
||||
import BubbleChartIcon from '@material-ui/icons/BubbleChart';
|
||||
import SearchIcon from '@material-ui/icons/Search';
|
||||
import { PublicKey } from '@solana/web3.js';
|
||||
import {
|
||||
networks,
|
||||
State as StoreState,
|
||||
ActionType,
|
||||
} from '../store/reducer';
|
||||
import { useWallet } from './WalletProvider';
|
||||
|
||||
export default function Header() {
|
||||
const { wallet } = useWallet();
|
||||
const history = useHistory();
|
||||
const [multisigAddress, setMultisigAddress] = useState('');
|
||||
const disabled = !isValidPubkey(multisigAddress);
|
||||
const searchFn = () => {
|
||||
history.push(`/${multisigAddress}`);
|
||||
};
|
||||
return (
|
||||
<AppBar
|
||||
position="static"
|
||||
style={{
|
||||
background: '#ffffff',
|
||||
color: '#272727',
|
||||
boxShadow: 'none',
|
||||
borderBottom: 'solid 1pt #ccc',
|
||||
}}
|
||||
>
|
||||
<Toolbar>
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
width: '100%',
|
||||
}}
|
||||
>
|
||||
<div style={{ display: 'flex', flex: 1 }}>
|
||||
<SerumLogoButton />
|
||||
<BarButton label="Multisig" hrefClient="/" />
|
||||
<BarButton label="Trade" href="https://dex.projectserum.com" />
|
||||
<BarButton label="Swap" href="https://swap.projectserum.com" />
|
||||
<BarButton label="Stake" href="https://stake.projectserum.com" />
|
||||
<BarButton label="Lockup" href="https://stake.projectserum.com/#/lockup" />
|
||||
<div
|
||||
style={{
|
||||
marginLeft: '16px',
|
||||
marginRight: '16px',
|
||||
borderRadius: '25px',
|
||||
display: 'flex',
|
||||
flex: 1,
|
||||
backgroundColor: 'rgb(245 245 245)',
|
||||
}}
|
||||
>
|
||||
<input
|
||||
style={{
|
||||
flex: 1,
|
||||
background: 'none',
|
||||
padding: '16px',
|
||||
border: 'none',
|
||||
outlineWidth: 0,
|
||||
color: 'inherit',
|
||||
}}
|
||||
placeholder="Search for a multisig address"
|
||||
value={multisigAddress}
|
||||
onChange={e => setMultisigAddress(e.target.value as string)}
|
||||
onKeyPress={e => {
|
||||
if (e.key === 'Enter') {
|
||||
searchFn();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<IconButton disabled={disabled} onClick={searchFn}>
|
||||
<SearchIcon />
|
||||
</IconButton>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
}}
|
||||
>
|
||||
<NetworkSelector />
|
||||
{!wallet.publicKey ? (
|
||||
<WalletConnectButton
|
||||
style={{
|
||||
display: wallet.publicKey ? 'none' : '',
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<UserSelector />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</Toolbar>
|
||||
</AppBar>
|
||||
);
|
||||
}
|
||||
|
||||
function SerumLogoButton() {
|
||||
const history = useHistory();
|
||||
return (
|
||||
<div style={{ display: 'flex' }} onClick={() => history.push('/')}>
|
||||
<Button color="inherit">
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
justifyContent: 'center',
|
||||
}}
|
||||
>
|
||||
<img
|
||||
style={{
|
||||
display: 'block',
|
||||
height: '35px',
|
||||
}}
|
||||
alt="Logo"
|
||||
src="http://dex.projectserum.com/static/media/logo.49174c73.svg"
|
||||
/>
|
||||
</div>
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
type BarButtonProps = {
|
||||
label: string;
|
||||
hrefClient?: string;
|
||||
href?: string;
|
||||
};
|
||||
|
||||
function BarButton(props: BarButtonProps) {
|
||||
const history = useHistory();
|
||||
const { label, href, hrefClient } = props;
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
justifyContent: 'center',
|
||||
}}
|
||||
onClick={() => hrefClient && history.push(hrefClient)}
|
||||
>
|
||||
<Link
|
||||
style={{ color: 'inherit', textDecoration: 'none' }}
|
||||
href={href}
|
||||
target="_blank"
|
||||
>
|
||||
<Button color="inherit">
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
flexDirection: 'column',
|
||||
}}
|
||||
>
|
||||
<Typography style={{ fontSize: '15px' }}>{label}</Typography>
|
||||
</div>
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function NetworkSelector() {
|
||||
const network = useSelector((state: StoreState) => {
|
||||
return state.common.network;
|
||||
});
|
||||
const dispatch = useDispatch();
|
||||
const [anchorEl, setAnchorEl] = useState(null);
|
||||
|
||||
const handleClose = () => {
|
||||
setAnchorEl(null);
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
marginRight: '10px',
|
||||
fontSize: '15px',
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
flexDirection: 'column',
|
||||
}}
|
||||
>
|
||||
<Button
|
||||
color="inherit"
|
||||
onClick={e =>
|
||||
setAnchorEl(
|
||||
// @ts-ignore
|
||||
e.currentTarget,
|
||||
)
|
||||
}
|
||||
>
|
||||
<BubbleChartIcon />
|
||||
<Typography style={{ marginLeft: '5px', fontSize: '15px' }}>
|
||||
{network.label}
|
||||
</Typography>
|
||||
</Button>
|
||||
<Menu
|
||||
anchorEl={anchorEl}
|
||||
open={Boolean(anchorEl)}
|
||||
onClose={handleClose}
|
||||
style={{
|
||||
marginLeft: '12px',
|
||||
color: 'white',
|
||||
}}
|
||||
>
|
||||
{Object.keys(networks).map((n: string) => (
|
||||
<MenuItem
|
||||
key={n}
|
||||
onClick={() => {
|
||||
handleClose();
|
||||
dispatch({
|
||||
type: ActionType.CommonSetNetwork,
|
||||
item: {
|
||||
network: networks[n],
|
||||
networkKey: n,
|
||||
},
|
||||
});
|
||||
}}
|
||||
>
|
||||
<Typography>{networks[n].label}</Typography>
|
||||
</MenuItem>
|
||||
))}
|
||||
</Menu>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function UserSelector() {
|
||||
const { wallet } = useWallet();
|
||||
|
||||
return (
|
||||
<Select
|
||||
displayEmpty
|
||||
renderValue={() => {
|
||||
return (
|
||||
<Typography style={{ overflow: 'hidden' }}>
|
||||
{wallet.publicKey.toString()}
|
||||
</Typography>
|
||||
);
|
||||
}}
|
||||
style={{
|
||||
marginLeft: '12px',
|
||||
width: '150px',
|
||||
}}
|
||||
onChange={e => {
|
||||
if (e.target.value === 'disconnect') {
|
||||
wallet.disconnect();
|
||||
}
|
||||
}}
|
||||
>
|
||||
<MenuItem value="disconnect">
|
||||
<IconButton color="inherit">
|
||||
<ExitToAppIcon />
|
||||
<Typography style={{ marginLeft: '15px' }}>Disconnect</Typography>
|
||||
</IconButton>
|
||||
</MenuItem>
|
||||
</Select>
|
||||
);
|
||||
}
|
||||
|
||||
type WalletConnectButtonProps = {
|
||||
style?: any;
|
||||
};
|
||||
|
||||
export function WalletConnectButton(
|
||||
props: WalletConnectButtonProps,
|
||||
): ReactElement {
|
||||
const { showDisconnect } = useSelector((state: StoreState) => {
|
||||
return {
|
||||
showDisconnect: state.common.isWalletConnected,
|
||||
};
|
||||
});
|
||||
const dispatch = useDispatch();
|
||||
const { wallet, multisigClient } = useWallet();
|
||||
const { enqueueSnackbar } = useSnackbar();
|
||||
|
||||
// Wallet connection event listeners.
|
||||
useEffect(() => {
|
||||
wallet.on('disconnect', () => {
|
||||
enqueueSnackbar('Disconnected from wallet', {
|
||||
variant: 'info',
|
||||
autoHideDuration: 2500,
|
||||
});
|
||||
dispatch({
|
||||
type: ActionType.CommonWalletDidDisconnect,
|
||||
item: {},
|
||||
});
|
||||
dispatch({
|
||||
type: ActionType.CommonTriggerShutdown,
|
||||
item: {},
|
||||
});
|
||||
});
|
||||
wallet.on('connect', async () => {
|
||||
dispatch({
|
||||
type: ActionType.CommonWalletDidConnect,
|
||||
item: {},
|
||||
});
|
||||
});
|
||||
}, [wallet, dispatch, enqueueSnackbar, multisigClient.provider.connection]);
|
||||
|
||||
return showDisconnect ? (
|
||||
<Button
|
||||
style={props.style}
|
||||
color="inherit"
|
||||
onClick={() => wallet.disconnect()}
|
||||
>
|
||||
<ExitToAppIcon />
|
||||
<Typography style={{ marginLeft: '5px', fontSize: '15px' }}>
|
||||
Disconnect
|
||||
</Typography>
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
style={props.style}
|
||||
color="inherit"
|
||||
onClick={() => wallet.connect()}
|
||||
>
|
||||
<PersonIcon />
|
||||
<Typography style={{ marginLeft: '5px', fontSize: '15px' }}>
|
||||
Connect wallet
|
||||
</Typography>
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function isValidPubkey(addr: string): boolean {
|
||||
try {
|
||||
new PublicKey(addr);
|
||||
return true;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,116 @@
|
|||
import React, { useState, PropsWithChildren } from 'react';
|
||||
import Typography from '@material-ui/core/Typography';
|
||||
import Button from '@material-ui/core/Button';
|
||||
import Header from './Header';
|
||||
import Footer from './Footer';
|
||||
|
||||
type Props = {};
|
||||
|
||||
export default function Layout(props: PropsWithChildren<Props>) {
|
||||
const [refresh, setRefresh] = useState(false);
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
minHeight: '100vh',
|
||||
flexDirection: 'column',
|
||||
backgroundColor: 'rgb(251, 251, 251)',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
position: 'fixed',
|
||||
width: '100%',
|
||||
zIndex: 99,
|
||||
}}
|
||||
>
|
||||
<RiskBar />
|
||||
<Header />
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
width: '100%',
|
||||
marginTop: '94px',
|
||||
flex: 1,
|
||||
display: 'flex',
|
||||
marginBottom: '30px', // Compensates for the fixed position footer.
|
||||
}}
|
||||
>
|
||||
{window.localStorage.getItem('consent') ? (
|
||||
<div style={{ width: '100%' }}>{props.children}</div>
|
||||
) : (
|
||||
<RiskDisclosureForm
|
||||
onConsent={() => {
|
||||
window.localStorage.setItem('consent', 'true');
|
||||
setRefresh(!refresh);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<Footer />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function RiskBar() {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
color: '#fff',
|
||||
backgroundColor: 'rgb(39, 39, 39)',
|
||||
height: '30px',
|
||||
textAlign: 'center',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
flexDirection: 'column',
|
||||
height: '100%',
|
||||
}}
|
||||
>
|
||||
<Typography style={{ fontSize: '14px' }}>
|
||||
Multisig is unaudited software. Use at your own risk.
|
||||
</Typography>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function RiskDisclosureForm({ onConsent }: { onConsent: () => void }) {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
flex: '1',
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
flexDirection: 'column',
|
||||
textAlign: 'center',
|
||||
}}
|
||||
>
|
||||
<div style={{ width: '100%', display: 'flex' }}>
|
||||
<div
|
||||
style={{ display: 'flex', marginLeft: 'auto', marginRight: 'auto' }}
|
||||
>
|
||||
<Typography
|
||||
style={{ marginBottom: '16px', maxWidth: '1000px' }}
|
||||
color="textSecondary"
|
||||
variant="h4"
|
||||
>
|
||||
No statement or warranty is provided in relation to the utility of
|
||||
this program, the safety of its code or its suitability for your
|
||||
use, and by using it, you agree to bear any risk associated with
|
||||
such potential vulnerabilities, including, but not limited to the
|
||||
potential loss of tokens.
|
||||
</Typography>
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ display: 'flex', marginLeft: 'auto', marginRight: 'auto' }}>
|
||||
<Button variant="contained" color="primary" onClick={onConsent}>
|
||||
I agree
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,53 @@
|
|||
import React from 'react';
|
||||
import { useSelector } from 'react-redux';
|
||||
import Button from '@material-ui/core/Button';
|
||||
import { TransactionSignature } from '@solana/web3.js';
|
||||
import { State as StoreState } from '../store/reducer';
|
||||
|
||||
type Props = {
|
||||
signature: string;
|
||||
};
|
||||
|
||||
export async function withTx(
|
||||
snack: any,
|
||||
beforeLabel: string,
|
||||
afterLabel: string,
|
||||
execTx: () => Promise<TransactionSignature>,
|
||||
) {
|
||||
snack.enqueueSnackbar(beforeLabel, {
|
||||
variant: 'info',
|
||||
});
|
||||
try {
|
||||
let tx = await execTx();
|
||||
snack.closeSnackbar();
|
||||
snack.enqueueSnackbar(afterLabel, {
|
||||
variant: 'success',
|
||||
action: <ViewTransactionOnExplorerButton signature={tx} />,
|
||||
});
|
||||
} catch (err) {
|
||||
snack.enqueueSnackbar(`Error: ${err.toString()}`, {
|
||||
variant: 'error',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function ViewTransactionOnExplorerButton(props: Props) {
|
||||
const { signature } = props;
|
||||
const { explorerClusterSuffix } = useSelector((state: StoreState) => {
|
||||
return {
|
||||
explorerClusterSuffix: state.common.network.explorerClusterSuffix,
|
||||
};
|
||||
});
|
||||
const urlSuffix = `?cluster=${explorerClusterSuffix}`;
|
||||
return (
|
||||
<Button
|
||||
color="inherit"
|
||||
component="a"
|
||||
target="_blank"
|
||||
rel="noopener"
|
||||
href={`https://explorer.solana.com/tx/${signature}` + urlSuffix}
|
||||
>
|
||||
View on Solana Explorer
|
||||
</Button>
|
||||
);
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
import React, {
|
||||
PropsWithChildren,
|
||||
ReactElement,
|
||||
ReactNode,
|
||||
useMemo,
|
||||
useContext,
|
||||
} from 'react';
|
||||
import { useSelector } from 'react-redux';
|
||||
import { Connection, ConfirmOptions } from '@solana/web3.js';
|
||||
// @ts-ignore
|
||||
import Wallet from '@project-serum/sol-wallet-adapter';
|
||||
import { Provider } from '@project-serum/common';
|
||||
import { Program } from '@project-serum/anchor';
|
||||
import { State as StoreState } from '../store/reducer';
|
||||
import MultisigIdl from '../idl';
|
||||
|
||||
export function useWallet(): WalletContextValues {
|
||||
const w = useContext(WalletContext);
|
||||
if (!w) {
|
||||
throw new Error('Missing wallet context');
|
||||
}
|
||||
// @ts-ignore
|
||||
return w;
|
||||
}
|
||||
|
||||
const WalletContext = React.createContext<null | WalletContextValues>(null);
|
||||
|
||||
type WalletContextValues = {
|
||||
wallet: Wallet;
|
||||
multisigClient: Program;
|
||||
};
|
||||
|
||||
export default function WalletProvider(
|
||||
props: PropsWithChildren<ReactNode>,
|
||||
): ReactElement {
|
||||
const { walletProvider, network } = useSelector((state: StoreState) => {
|
||||
return {
|
||||
walletProvider: state.common.walletProvider,
|
||||
network: state.common.network,
|
||||
};
|
||||
});
|
||||
|
||||
const {
|
||||
wallet,
|
||||
multisigClient,
|
||||
} = useMemo(() => {
|
||||
const opts: ConfirmOptions = {
|
||||
preflightCommitment: 'recent',
|
||||
commitment: 'recent',
|
||||
};
|
||||
const connection = new Connection(network.url, opts.preflightCommitment);
|
||||
const wallet = new Wallet(walletProvider, network.url);
|
||||
const provider = new Provider(connection, wallet, opts);
|
||||
|
||||
const multisigClient = new Program(
|
||||
MultisigIdl,
|
||||
network.multisigProgramId,
|
||||
provider,
|
||||
);
|
||||
|
||||
return {
|
||||
wallet,
|
||||
multisigClient,
|
||||
};
|
||||
}, [walletProvider, network]);
|
||||
|
||||
return (
|
||||
<WalletContext.Provider
|
||||
value={{ wallet, multisigClient }}
|
||||
>
|
||||
{props.children}
|
||||
</WalletContext.Provider>
|
||||
);
|
||||
}
|
|
@ -0,0 +1,299 @@
|
|||
import { Idl } from '@project-serum/anchor';
|
||||
|
||||
const idl: Idl = {
|
||||
"version": "0.0.0",
|
||||
"name": "multisig",
|
||||
"instructions": [
|
||||
{
|
||||
"name": "createMultisig",
|
||||
"accounts": [
|
||||
{
|
||||
"name": "multisig",
|
||||
"isMut": true,
|
||||
"isSigner": false
|
||||
},
|
||||
{
|
||||
"name": "rent",
|
||||
"isMut": false,
|
||||
"isSigner": false
|
||||
}
|
||||
],
|
||||
"args": [
|
||||
{
|
||||
"name": "owners",
|
||||
"type": {
|
||||
"vec": "publicKey"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "threshold",
|
||||
"type": "u64"
|
||||
},
|
||||
{
|
||||
"name": "nonce",
|
||||
"type": "u8"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "createTransaction",
|
||||
"accounts": [
|
||||
{
|
||||
"name": "multisig",
|
||||
"isMut": false,
|
||||
"isSigner": false
|
||||
},
|
||||
{
|
||||
"name": "transaction",
|
||||
"isMut": true,
|
||||
"isSigner": false
|
||||
},
|
||||
{
|
||||
"name": "proposer",
|
||||
"isMut": false,
|
||||
"isSigner": true
|
||||
},
|
||||
{
|
||||
"name": "rent",
|
||||
"isMut": false,
|
||||
"isSigner": false
|
||||
}
|
||||
],
|
||||
"args": [
|
||||
{
|
||||
"name": "pid",
|
||||
"type": "publicKey"
|
||||
},
|
||||
{
|
||||
"name": "accs",
|
||||
"type": {
|
||||
"vec": {
|
||||
"defined": "TransactionAccount"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"type": "bytes"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "approve",
|
||||
"accounts": [
|
||||
{
|
||||
"name": "multisig",
|
||||
"isMut": false,
|
||||
"isSigner": false
|
||||
},
|
||||
{
|
||||
"name": "transaction",
|
||||
"isMut": true,
|
||||
"isSigner": false
|
||||
},
|
||||
{
|
||||
"name": "owner",
|
||||
"isMut": false,
|
||||
"isSigner": true
|
||||
}
|
||||
],
|
||||
"args": []
|
||||
},
|
||||
{
|
||||
"name": "setOwners",
|
||||
"accounts": [
|
||||
{
|
||||
"name": "multisig",
|
||||
"isMut": true,
|
||||
"isSigner": false
|
||||
},
|
||||
{
|
||||
"name": "multisigSigner",
|
||||
"isMut": false,
|
||||
"isSigner": true
|
||||
}
|
||||
],
|
||||
"args": [
|
||||
{
|
||||
"name": "owners",
|
||||
"type": {
|
||||
"vec": "publicKey"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "changeThreshold",
|
||||
"accounts": [
|
||||
{
|
||||
"name": "multisig",
|
||||
"isMut": true,
|
||||
"isSigner": false
|
||||
},
|
||||
{
|
||||
"name": "multisigSigner",
|
||||
"isMut": false,
|
||||
"isSigner": true
|
||||
}
|
||||
],
|
||||
"args": [
|
||||
{
|
||||
"name": "threshold",
|
||||
"type": "u64"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "executeTransaction",
|
||||
"accounts": [
|
||||
{
|
||||
"name": "multisig",
|
||||
"isMut": false,
|
||||
"isSigner": false
|
||||
},
|
||||
{
|
||||
"name": "multisigSigner",
|
||||
"isMut": false,
|
||||
"isSigner": false
|
||||
},
|
||||
{
|
||||
"name": "transaction",
|
||||
"isMut": true,
|
||||
"isSigner": false
|
||||
}
|
||||
],
|
||||
"args": []
|
||||
}
|
||||
],
|
||||
"accounts": [
|
||||
{
|
||||
"name": "Multisig",
|
||||
"type": {
|
||||
"kind": "struct",
|
||||
"fields": [
|
||||
{
|
||||
"name": "owners",
|
||||
"type": {
|
||||
"vec": "publicKey"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "threshold",
|
||||
"type": "u64"
|
||||
},
|
||||
{
|
||||
"name": "nonce",
|
||||
"type": "u8"
|
||||
},
|
||||
{
|
||||
"name": "ownerSetSeqno",
|
||||
"type": "u32"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Transaction",
|
||||
"type": {
|
||||
"kind": "struct",
|
||||
"fields": [
|
||||
{
|
||||
"name": "multisig",
|
||||
"type": "publicKey"
|
||||
},
|
||||
{
|
||||
"name": "programId",
|
||||
"type": "publicKey"
|
||||
},
|
||||
{
|
||||
"name": "accounts",
|
||||
"type": {
|
||||
"vec": {
|
||||
"defined": "TransactionAccount"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "data",
|
||||
"type": "bytes"
|
||||
},
|
||||
{
|
||||
"name": "signers",
|
||||
"type": {
|
||||
"vec": "bool"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "didExecute",
|
||||
"type": "bool"
|
||||
},
|
||||
{
|
||||
"name": "ownerSetSeqno",
|
||||
"type": "u32"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"types": [
|
||||
{
|
||||
"name": "TransactionAccount",
|
||||
"type": {
|
||||
"kind": "struct",
|
||||
"fields": [
|
||||
{
|
||||
"name": "pubkey",
|
||||
"type": "publicKey"
|
||||
},
|
||||
{
|
||||
"name": "isSigner",
|
||||
"type": "bool"
|
||||
},
|
||||
{
|
||||
"name": "isWritable",
|
||||
"type": "bool"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"errors": [
|
||||
{
|
||||
"code": 100,
|
||||
"name": "InvalidOwner",
|
||||
"msg": "The given owner is not part of this multisig."
|
||||
},
|
||||
{
|
||||
"code": 101,
|
||||
"name": "NotEnoughSigners",
|
||||
"msg": "Not enough owners signed this transaction."
|
||||
},
|
||||
{
|
||||
"code": 102,
|
||||
"name": "TransactionAlreadySigned",
|
||||
"msg": "Cannot delete a transaction that has been signed by an owner."
|
||||
},
|
||||
{
|
||||
"code": 103,
|
||||
"name": "Overflow",
|
||||
"msg": "Overflow when adding."
|
||||
},
|
||||
{
|
||||
"code": 104,
|
||||
"name": "UnableToDelete",
|
||||
"msg": "Cannot delete a transaction the owner did not create."
|
||||
},
|
||||
{
|
||||
"code": 105,
|
||||
"name": "AlreadyExecuted",
|
||||
"msg": "The given transaction has already been executed."
|
||||
},
|
||||
{
|
||||
"code": 106,
|
||||
"name": "InvalidThreshold",
|
||||
"msg": "Threshold must be less than or equal to the number of owners."
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
export default idl;
|
|
@ -0,0 +1,13 @@
|
|||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
||||
sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
|
||||
monospace;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import './index.css';
|
||||
import App from './App';
|
||||
import reportWebVitals from './reportWebVitals';
|
||||
|
||||
ReactDOM.render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>,
|
||||
document.getElementById('root')
|
||||
);
|
||||
|
||||
// If you want to start measuring performance in your app, pass a function
|
||||
// to log results (for example: reportWebVitals(console.log))
|
||||
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
||||
reportWebVitals();
|
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3"><g fill="#61DAFB"><path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/><circle cx="420.9" cy="296.5" r="45.7"/><path d="M520.5 78.1z"/></g></svg>
|
After Width: | Height: | Size: 2.6 KiB |
|
@ -0,0 +1 @@
|
|||
/// <reference types="react-scripts" />
|
|
@ -0,0 +1,15 @@
|
|||
import { ReportHandler } from 'web-vitals';
|
||||
|
||||
const reportWebVitals = (onPerfEntry?: ReportHandler) => {
|
||||
if (onPerfEntry && onPerfEntry instanceof Function) {
|
||||
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
|
||||
getCLS(onPerfEntry);
|
||||
getFID(onPerfEntry);
|
||||
getFCP(onPerfEntry);
|
||||
getLCP(onPerfEntry);
|
||||
getTTFB(onPerfEntry);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export default reportWebVitals;
|
|
@ -0,0 +1,5 @@
|
|||
// jest-dom adds custom jest matchers for asserting on DOM nodes.
|
||||
// allows you to do things like:
|
||||
// expect(element).toHaveTextContent(/react/i)
|
||||
// learn more: https://github.com/testing-library/jest-dom
|
||||
import '@testing-library/jest-dom';
|
|
@ -0,0 +1,4 @@
|
|||
import { createStore } from 'redux';
|
||||
import reducer from './reducer';
|
||||
|
||||
export const store = createStore(reducer);
|
|
@ -0,0 +1,104 @@
|
|||
import { PublicKey } from '@solana/web3.js';
|
||||
|
||||
export type Action = {
|
||||
type: ActionType;
|
||||
item: any;
|
||||
};
|
||||
|
||||
export enum ActionType {
|
||||
CommonTriggerShutdown,
|
||||
CommonDidShutdown,
|
||||
CommonWalletDidConnect,
|
||||
CommonWalletDidDisconnect,
|
||||
CommonWalletSetProvider,
|
||||
CommonSetNetwork,
|
||||
}
|
||||
|
||||
export default function reducer(
|
||||
state: State = initialState,
|
||||
action: Action,
|
||||
): State {
|
||||
let newState = {
|
||||
common: { ...state.common },
|
||||
};
|
||||
switch (action.type) {
|
||||
case ActionType.CommonWalletSetProvider:
|
||||
newState.common.walletProvider = action.item.walletProvider;
|
||||
return newState;
|
||||
case ActionType.CommonWalletDidConnect:
|
||||
newState.common.isWalletConnected = true;
|
||||
return newState;
|
||||
case ActionType.CommonWalletDidDisconnect:
|
||||
newState.common.isWalletConnected = false;
|
||||
return newState;
|
||||
case ActionType.CommonSetNetwork:
|
||||
if (newState.common.network.label !== action.item.network.label) {
|
||||
newState.common.network = action.item.network;
|
||||
}
|
||||
return newState;
|
||||
default:
|
||||
return newState;
|
||||
}
|
||||
}
|
||||
|
||||
export type State = {
|
||||
common: CommonState;
|
||||
};
|
||||
|
||||
export type CommonState = {
|
||||
walletProvider?: string;
|
||||
isWalletConnected: boolean;
|
||||
network: Network;
|
||||
};
|
||||
|
||||
export const networks: Networks = {
|
||||
mainnet: {
|
||||
// Cluster.
|
||||
label: 'Mainnet Beta',
|
||||
url: 'https://solana-api.projectserum.com',
|
||||
//url: 'https://api.mainnet-beta.solana.com',
|
||||
explorerClusterSuffix: '',
|
||||
multisigProgramId: new PublicKey(
|
||||
'3S6ALMCGVib4X3vVR3CLpm2K6Ng5qbWFYMTo5jfxWcEq',
|
||||
),
|
||||
},
|
||||
devnet: {
|
||||
// Cluster.
|
||||
label: 'Devnet',
|
||||
url: 'https://devnet.solana.com',
|
||||
explorerClusterSuffix: 'devnet',
|
||||
multisigProgramId: new PublicKey(
|
||||
'3S6ALMCGVib4X3vVR3CLpm2K6Ng5qbWFYMTo5jfxWcEq',
|
||||
),
|
||||
},
|
||||
|
||||
// Fill in with your local cluster addresses.
|
||||
localhost: {
|
||||
// Cluster.
|
||||
label: 'Localhost',
|
||||
url: 'http://localhost:8899',
|
||||
explorerClusterSuffix: 'localhost',
|
||||
multisigProgramId: new PublicKey(
|
||||
'9z7Pq56To96qbVLzuBcf47Lc7u8uUWZh6k5rhcaTsDjz',
|
||||
),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
export const initialState: State = {
|
||||
common: {
|
||||
isWalletConnected: false,
|
||||
walletProvider: 'https://www.sollet.io',
|
||||
network: networks.localhost,
|
||||
},
|
||||
};
|
||||
|
||||
type Networks = { [label: string]: Network };
|
||||
|
||||
export type Network = {
|
||||
// Cluster.
|
||||
label: string;
|
||||
url: string;
|
||||
explorerClusterSuffix: string;
|
||||
multisigProgramId: PublicKey;
|
||||
};
|
|
@ -0,0 +1,33 @@
|
|||
import { struct, Layout } from 'buffer-layout';
|
||||
import { rustEnum } from '@project-serum/borsh';
|
||||
|
||||
// Simplified since we only use the SetBuffer variant.
|
||||
export type IdlInstruction =
|
||||
| Create
|
||||
| CreateBuffer
|
||||
| Write
|
||||
| SetBuffer
|
||||
| SetAuthority;
|
||||
|
||||
type Create = {};
|
||||
type CreateBuffer = {};
|
||||
type Write = {};
|
||||
type SetBuffer = {};
|
||||
type SetAuthority = {};
|
||||
|
||||
const IDL_INSTRUCTION_LAYOUT: Layout<IdlInstruction> = rustEnum([
|
||||
struct([], 'create'),
|
||||
struct([], 'createBuffer'),
|
||||
struct([], 'write'),
|
||||
struct([], 'setBuffer'),
|
||||
struct([], 'setAuthority'),
|
||||
]);
|
||||
|
||||
export function encodeInstruction(i: IdlInstruction): Buffer {
|
||||
const buffer = Buffer.alloc(1000); // TODO: use a tighter buffer.
|
||||
const len = IDL_INSTRUCTION_LAYOUT.encode(i, buffer);
|
||||
return Buffer.concat([IDL_TAG, buffer.slice(0, len)]);
|
||||
}
|
||||
|
||||
// Reverse for little endian.
|
||||
export const IDL_TAG = Buffer.from('0a69e9a778bcf440', 'hex').reverse();
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"lib": [
|
||||
"dom",
|
||||
"dom.iterable",
|
||||
"esnext"
|
||||
],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"strict": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx",
|
||||
"typeRoots": ["types/", "node_modules/@types"]
|
||||
},
|
||||
"include": [
|
||||
"src"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
declare module 'buffer-layout' {
|
||||
// TODO: remove `any`.
|
||||
export class Layout<T = any> {
|
||||
span: number;
|
||||
property?: string;
|
||||
|
||||
constructor(span: number, property?: string);
|
||||
|
||||
decode(b: Buffer, offset?: number): T;
|
||||
encode(src: T, b: Buffer, offset?: number): number;
|
||||
getSpan(b: Buffer, offset?: number): number;
|
||||
replicate(name: string): this;
|
||||
}
|
||||
// TODO: remove any.
|
||||
export class Structure<T = any> extends Layout<T> {
|
||||
span: any;
|
||||
}
|
||||
export function greedy(
|
||||
elementSpan?: number,
|
||||
property?: string,
|
||||
): Layout<number>;
|
||||
export function offset<T>(
|
||||
layout: Layout<T>,
|
||||
offset?: number,
|
||||
property?: string,
|
||||
): Layout<T>;
|
||||
export function u8(property?: string): Layout<number>;
|
||||
export function u16(property?: string): Layout<number>;
|
||||
export function u24(property?: string): Layout<number>;
|
||||
export function u32(property?: string): Layout<number>;
|
||||
export function u40(property?: string): Layout<number>;
|
||||
export function u48(property?: string): Layout<number>;
|
||||
export function nu64(property?: string): Layout<number>;
|
||||
export function u16be(property?: string): Layout<number>;
|
||||
export function u24be(property?: string): Layout<number>;
|
||||
export function u32be(property?: string): Layout<number>;
|
||||
export function u40be(property?: string): Layout<number>;
|
||||
export function u48be(property?: string): Layout<number>;
|
||||
export function nu64be(property?: string): Layout<number>;
|
||||
export function s8(property?: string): Layout<number>;
|
||||
export function s16(property?: string): Layout<number>;
|
||||
export function s24(property?: string): Layout<number>;
|
||||
export function s32(property?: string): Layout<number>;
|
||||
export function s40(property?: string): Layout<number>;
|
||||
export function s48(property?: string): Layout<number>;
|
||||
export function ns64(property?: string): Layout<number>;
|
||||
export function s16be(property?: string): Layout<number>;
|
||||
export function s24be(property?: string): Layout<number>;
|
||||
export function s32be(property?: string): Layout<number>;
|
||||
export function s40be(property?: string): Layout<number>;
|
||||
export function s48be(property?: string): Layout<number>;
|
||||
export function ns64be(property?: string): Layout<number>;
|
||||
export function f32(property?: string): Layout<number>;
|
||||
export function f32be(property?: string): Layout<number>;
|
||||
export function f64(property?: string): Layout<number>;
|
||||
export function f64be(property?: string): Layout<number>;
|
||||
export function struct<T>(
|
||||
fields: Layout<any>[],
|
||||
property?: string,
|
||||
decodePrefixes?: boolean,
|
||||
): Layout<T>;
|
||||
export function bits(
|
||||
word: Layout<number>,
|
||||
msb?: boolean,
|
||||
property?: string,
|
||||
): any;
|
||||
export function seq<T>(
|
||||
elementLayout: Layout<T>,
|
||||
count: number | Layout<number>,
|
||||
property?: string,
|
||||
): Layout<T[]>;
|
||||
export function union(
|
||||
discr: Layout<any>,
|
||||
defaultLayout?: any,
|
||||
property?: string,
|
||||
): any;
|
||||
export function unionLayoutDiscriminator(
|
||||
layout: Layout<any>,
|
||||
property?: string,
|
||||
): any;
|
||||
export function blob(
|
||||
length: number | Layout<number>,
|
||||
property?: string,
|
||||
): Layout<Buffer>;
|
||||
export function cstr(property?: string): Layout<string>;
|
||||
export function utf8(maxSpan: number, property?: string): Layout<string>;
|
||||
}
|
Loading…
Reference in New Issue