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

Added wallets with sol-wallet-adapter #85

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
46 changes: 41 additions & 5 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,43 @@ import {
import Swap from "@project-serum/swap-ui";
import "./App.css";

import { ConnectionProvider, WalletProvider, useWallet, useConnection } from '@solana/wallet-adapter-react';
import {
getPhantomWallet,
getSolletWallet,
} from '@solana/wallet-adapter-wallets';
import { WalletAdapterNetwork } from "@solana/wallet-adapter-base";
import {
WalletDialogProvider as MaterialUIWalletDialogProvider,
WalletMultiButton as MaterialUIWalletMultiButton,
} from '@solana/wallet-adapter-material-ui';

// App illustrating the use of the Swap component.
//
// One needs to just provide an Anchor `Provider` and a `TokenListContainer`
// to the `Swap` component, and then everything else is taken care of.
function App() {

const network = "https://solana-api.projectserum.com";

const wallets = useMemo(
() => [
getPhantomWallet(),
getSolletWallet({ network: "htpps://api.devnet.solana.com" as WalletAdapterNetwork }),
],
[]
);

return (
<SnackbarProvider maxSnack={5} autoHideDuration={8000}>
<AppInner />
</SnackbarProvider>
<ConnectionProvider endpoint={network}>
<WalletProvider wallets={wallets} >
<MaterialUIWalletDialogProvider style={{backgroundColor: 'white', color: 'red'}}>
<SnackbarProvider maxSnack={5} autoHideDuration={8000}>
<AppInner />
</SnackbarProvider>
</MaterialUIWalletDialogProvider>
</WalletProvider>
</ConnectionProvider>
);
}

Expand All @@ -46,6 +74,13 @@ function AppInner() {
const [isConnected, setIsConnected] = useState(false);
const [tokenList, setTokenList] = useState<TokenListContainer | null>(null);

const opts: ConfirmOptions = {
preflightCommitment: "recent"
}
const newWallet = useWallet();
const { connection: newConnection } = useConnection();
const newProvider = new Provider(newConnection, newWallet as AnchorWallet, opts);

const [provider, wallet] = useMemo(() => {
const opts: ConfirmOptions = {
preflightCommitment: "recent",
Expand Down Expand Up @@ -103,7 +138,7 @@ function AppInner() {
return (
<Grid
container
justify="center"
justifyContent="center"
alignItems="center"
className={styles.root}
>
Expand All @@ -114,7 +149,8 @@ function AppInner() {
>
{!isConnected ? "Connect" : "Disconnect"}
</Button>
{tokenList && <Swap provider={provider} tokenList={tokenList} />}
<MaterialUIWalletMultiButton style={{ position: "fixed", left: 24, top: 24 }}/>
{tokenList && <Swap provider={newProvider} tokenList={tokenList} />}
</Grid>
);
}
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
"dependencies": {
"@project-serum/serum": "^0.13.58",
"@project-serum/swap": "^0.1.0-alpha.32",
"@solana/spl-token": "^0.1.8"
"@solana/spl-token": "^0.1.8",
"@solana/wallet-adapter-base": "^0.6.0",
"@solana/wallet-adapter-material-ui": "^0.12.0",
"@solana/wallet-adapter-react": "^0.12.0",
"@solana/wallet-adapter-wallets": "^0.10.0"
},
"peerDependencies": {
"@material-ui/core": "^4.12.3",
Expand Down
Loading