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

Supporting versioned transactions in WalletConnect #777

Merged
merged 11 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
5 changes: 5 additions & 0 deletions .changeset/eight-ligers-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@solana/wallet-adapter-walletconnect': patch
---

Add support for versioned transactions
2 changes: 2 additions & 0 deletions packages/starter/example/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ module.exports = function (phase, { defaultConfig }) {
basePath: phase === PHASE_PRODUCTION_BUILD ? '/wallet-adapter/example' : '',
});

config.output = 'export';
jordaaash marked this conversation as resolved.
Show resolved Hide resolved

return config;
};
23 changes: 19 additions & 4 deletions packages/starter/example/src/components/ContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { WalletAdapterNetwork } from '@solana/wallet-adapter-base';
import { WalletDialogProvider as MaterialUIWalletDialogProvider } from '@solana/wallet-adapter-material-ui';
import { ConnectionProvider, WalletProvider } from '@solana/wallet-adapter-react';
import { WalletModalProvider as ReactUIWalletModalProvider } from '@solana/wallet-adapter-react-ui';
import { UnsafeBurnerWalletAdapter } from '@solana/wallet-adapter-wallets';
import { UnsafeBurnerWalletAdapter, WalletConnectWalletAdapter } from '@solana/wallet-adapter-wallets';
import { clusterApiUrl } from '@solana/web3.js';
import { SnackbarProvider, useSnackbar } from 'notistack';
import type { FC, ReactNode } from 'react';
Expand Down Expand Up @@ -52,10 +52,11 @@ const WalletContextProvider: FC<{ children: ReactNode }> = ({ children }) => {
const { autoConnect } = useAutoConnect();

// Can be set to 'devnet', 'testnet', or 'mainnet-beta'
const network = WalletAdapterNetwork.Devnet;
const network = WalletAdapterNetwork.Mainnet;
jordaaash marked this conversation as resolved.
Show resolved Hide resolved

// You can also provide a custom RPC endpoint
const endpoint = useMemo(() => clusterApiUrl(network), [network]);
// const endpoint = useMemo(() => process.env.NEXT_PUBLIC_MAINNET_RPC_URL!, [network]);
const endpoint = useMemo(() => clusterApiUrl(WalletAdapterNetwork.Devnet), [network]);

const wallets = useMemo(
() => [
Expand All @@ -71,7 +72,21 @@ const WalletContextProvider: FC<{ children: ReactNode }> = ({ children }) => {
* instantiate its legacy wallet adapter here. Common legacy adapters can be found
* in the npm package `@solana/wallet-adapter-wallets`.
*/
new UnsafeBurnerWalletAdapter(),
new WalletConnectWalletAdapter({
network,
options: {
relayUrl: 'wss://relay.walletconnect.com',
// example WC app project ID
projectId: 'f1559cce010fd0ba641c3e6e02ca3aa4',
metadata: {
name: 'Example App',
description: 'Example App',
url: 'https://github.com/solana-labs/wallet-adapter',
icons: ['https://avatars.githubusercontent.com/u/35608259?s=200'],
},
},
}),
// new UnsafeBurnerWalletAdapter(),
jordaaash marked this conversation as resolved.
Show resolved Hide resolved
],
// eslint-disable-next-line react-hooks/exhaustive-deps
[network]
Expand Down
8 changes: 4 additions & 4 deletions packages/wallets/walletconnect/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@solana/wallet-adapter-walletconnect",
"version": "0.1.14",
"version": "0.1.15",
jordaaash marked this conversation as resolved.
Show resolved Hide resolved
"author": "Solana Maintainers <maintainers@solana.foundation>",
"repository": "https://github.com/solana-labs/wallet-adapter",
"license": "Apache-2.0",
Expand Down Expand Up @@ -32,14 +32,14 @@
"package": "shx mkdir -p lib/cjs && shx echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json"
},
"peerDependencies": {
"@solana/web3.js": "^1.58.0"
"@solana/web3.js": "^1.63.0"
},
"dependencies": {
"@jnwng/walletconnect-solana": "^0.1.5",
"@jnwng/walletconnect-solana": "0.2.0",
jordaaash marked this conversation as resolved.
Show resolved Hide resolved
"@solana/wallet-adapter-base": "workspace:^"
},
"devDependencies": {
"@solana/web3.js": "^1.73.2",
"@solana/web3.js": "^1.63.0",
jordaaash marked this conversation as resolved.
Show resolved Hide resolved
"@types/pino": "^6.3.12",
"@walletconnect/types": "^2.4.5",
"shx": "^0.3.4"
Expand Down
10 changes: 6 additions & 4 deletions packages/wallets/walletconnect/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
WalletSignTransactionError,
WalletWindowClosedError,
} from '@solana/wallet-adapter-base';
import type { PublicKey, Transaction } from '@solana/web3.js';
import type { PublicKey, Transaction, TransactionVersion, VersionedTransaction } from '@solana/web3.js';

export const WalletConnectWalletName = 'WalletConnect' as WalletName<'WalletConnect'>;

Expand All @@ -30,8 +30,10 @@ export class WalletConnectWalletAdapter extends BaseSignerWalletAdapter {
name = WalletConnectWalletName;
url = 'https://walletconnect.org';
icon =
'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzAwIiBoZWlnaHQ9IjMwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJtNjEuNDM4NTQsOTQuMDAzOGM0OC45MTEyMywtNDcuODg4MTcgMTI4LjIxMTk5LC00Ny44ODgxNyAxNzcuMTIzMjEsMGw1Ljg4NjU1LDUuNzYzNDJjMi40NDU1NiwyLjM5NDQxIDIuNDQ1NTYsNi4yNzY1MSAwLDguNjcwOTJsLTIwLjEzNjcsMTkuNzE1NWMtMS4yMjI3OCwxLjE5NzIxIC0zLjIwNTMsMS4xOTcyMSAtNC40MjgwOCwwbC04LjEwMDU4LC03LjkzMTE1Yy0zNC4xMjE2OSwtMzMuNDA3OTggLTg5LjQ0Mzg5LC0zMy40MDc5OCAtMTIzLjU2NTU4LDBsLTguNjc1MDYsOC40OTM2MWMtMS4yMjI3OCwxLjE5NzIgLTMuMjA1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4wMDAwMjRsNTcuMzUyMTAzMS01Ni4xNTUzMzNjMi40NDU1MDUtMi4zOTQ0NjMzIDYuNDEwNTQ0LTIuMzk0NTUzMSA4Ljg1NjE2MS0uMDAwMi4wMDAwMzQuMDAwMDMzNi4wMDAwNjguMDAwMDY3My4wMDAxMDEuMDAwMTAxbDU3LjM1NDkwMiA1Ni4xNTU0MzJjLjYxMTM5LjU5ODYwMSAxLjYwMjY1LjU5ODYwMSAyLjIxNDA0IDBsNTcuMzUzOTc1LTU2LjE1NDMyNDljMi40NDU1NjEtMi4zOTQ0MDkyIDYuNDEwNTk5LTIuMzk0NDA5MiA4Ljg1NjE2IDB6IiBmaWxsPSIjM2I5OWZjIi8+PC9zdmc+';
// V0 transactions are supported via the `transaction` parameter, and is off-spec.
// Legacy transactions have these [parameters](https://docs.walletconnect.com/2.0/advanced/rpc-reference/solana-rpc#solana_signtransaction)
readonly supportedTransactionVersions: ReadonlySet<TransactionVersion> = new Set(['legacy', 0]);

private _publicKey: PublicKey | null;
private _connecting: boolean;
Expand Down Expand Up @@ -125,7 +127,7 @@ export class WalletConnectWalletAdapter extends BaseSignerWalletAdapter {
this.emit('disconnect');
}

async signTransaction<T extends Transaction>(transaction: T): Promise<T> {
async signTransaction<T extends Transaction | VersionedTransaction>(transaction: T): Promise<T> {
try {
const wallet = this._wallet;
if (!wallet) throw new WalletNotConnectedError();
Expand Down
Loading