Skip to content

Commit

Permalink
lint / minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jordaaash committed Sep 15, 2022
1 parent 88af6ac commit 719c447
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 28 deletions.
28 changes: 20 additions & 8 deletions packages/starter/example/src/components/SendLegacyTransaction.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Button } from '@mui/material';
import { useConnection, useWallet } from '@solana/wallet-adapter-react';
import { TransactionMessage, TransactionSignature, VersionedTransaction } from '@solana/web3.js';
import type { TransactionSignature } from '@solana/web3.js';
import { TransactionMessage, VersionedTransaction } from '@solana/web3.js';
import { PublicKey } from '@solana/web3.js';
import type { FC } from 'react';
import React, { useCallback } from 'react';
Expand All @@ -19,7 +20,10 @@ export const SendLegacyTransaction: FC = () => {
}

if (!supportedTransactionVersions) {
notify('error', 'Wallet doesn\'t support versioned transactions!');
notify('error', "Wallet doesn't support versioned transactions!");
return;
} else if (!supportedTransactionVersions.has('legacy')) {
notify('error', "Wallet doesn't support legacy transactions!");
return;
}

Expand All @@ -32,15 +36,18 @@ export const SendLegacyTransaction: FC = () => {

const message = new TransactionMessage({
payerKey: publicKey,
instructions: [{
data: Buffer.from('Hello, from the Solana Wallet Adapter example app!'),
keys: [],
programId: new PublicKey('MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr'),
}],
instructions: [
{
data: Buffer.from('Hello, from the Solana Wallet Adapter example app!'),
keys: [],
programId: new PublicKey('MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr'),
},
],
recentBlockhash: blockhash,
});

const transaction = new VersionedTransaction(message.compileToLegacyMessage());

signature = await sendTransaction(transaction, connection, { minContextSlot });
notify('info', 'Transaction sent:', signature);

Expand All @@ -53,7 +60,12 @@ export const SendLegacyTransaction: FC = () => {
}, [publicKey, notify, connection, sendTransaction, supportedTransactionVersions]);

return (
<Button variant="contained" color="secondary" onClick={onClick} disabled={!publicKey || !supportedTransactionVersions}>
<Button
variant="contained"
color="secondary"
onClick={onClick}
disabled={!publicKey || !supportedTransactionVersions?.has('legacy')}
>
Send Legacy Transaction (devnet)
</Button>
);
Expand Down
46 changes: 27 additions & 19 deletions packages/starter/example/src/components/SendV0Transaction.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Button } from '@mui/material';
import { useConnection, useWallet } from '@solana/wallet-adapter-react';
import { AddressLookupTableAccount, TransactionMessage, TransactionSignature, VersionedTransaction } from '@solana/web3.js';
import { PublicKey } from '@solana/web3.js';
import type { TransactionSignature } from '@solana/web3.js';
import { PublicKey, TransactionMessage, VersionedTransaction } from '@solana/web3.js';
import type { FC } from 'react';
import React, { useCallback } from 'react';
import { useNotify } from './notify';
Expand All @@ -19,10 +19,10 @@ export const SendV0Transaction: FC = () => {
}

if (!supportedTransactionVersions) {
notify('error', 'Wallet doesn\'t support versioned transactions!');
notify('error', "Wallet doesn't support versioned transactions!");
return;
} else if (!supportedTransactionVersions.has(0)) {
notify('error', 'Wallet doesn\'t support v0 transactions!');
notify('error', "Wallet doesn't support v0 transactions!");
return;
}

Expand All @@ -33,9 +33,11 @@ export const SendV0Transaction: FC = () => {
* needed. To create and manage a lookup table, use the `solana
* address-lookup-table` commands.
*/
const lookupTable = (await connection.getAddressLookupTable(new PublicKey("F3MfgEJe1TApJiA14nN2m4uAH4EBVrqdBnHeGeSXvQ7B"))).value;
if (lookupTable === null) {
notify('error', 'Address lookup table wasn\'t found!');
const { value: lookupTable } = await connection.getAddressLookupTable(
new PublicKey('F3MfgEJe1TApJiA14nN2m4uAH4EBVrqdBnHeGeSXvQ7B')
);
if (!lookupTable) {
notify('error', "Address lookup table wasn't found!");
return;
}

Expand All @@ -46,19 +48,21 @@ export const SendV0Transaction: FC = () => {

const message = new TransactionMessage({
payerKey: publicKey,
instructions: [{
data: Buffer.from('Hello, from the Solana Wallet Adapter example app!'),
keys: lookupTable.state.addresses.map((pubkey, index) => ({
pubkey,
isWritable: index % 2 == 0,
isSigner: false,
})),
programId: new PublicKey('MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr'),
}],
instructions: [
{
data: Buffer.from('Hello, from the Solana Wallet Adapter example app!'),
keys: lookupTable.state.addresses.map((pubkey, index) => ({
pubkey,
isWritable: index % 2 == 0,
isSigner: false,
})),
programId: new PublicKey('MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr'),
},
],
recentBlockhash: blockhash,
});

const lookupTables: AddressLookupTableAccount[] = [lookupTable];
const lookupTables = [lookupTable];
const transaction = new VersionedTransaction(message.compileToV0Message(lookupTables));

signature = await sendTransaction(transaction, connection, { minContextSlot });
Expand All @@ -72,9 +76,13 @@ export const SendV0Transaction: FC = () => {
}
}, [publicKey, notify, connection, sendTransaction, supportedTransactionVersions]);

const disabled = !publicKey || !(supportedTransactionVersions && supportedTransactionVersions.has(0));
return (
<Button variant="contained" color="secondary" onClick={onClick} disabled={disabled}>
<Button
variant="contained"
color="secondary"
onClick={onClick}
disabled={!publicKey || !supportedTransactionVersions?.has(0)}
>
Send V0 Transaction using Address Lookup Table (devnet)
</Button>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/starter/example/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ const Index: NextPage = () => {
</TableCell>
</TableRow>
<TableRow>
<TableCell></TableCell>
<TableCell></TableCell>
<TableCell>
<SendLegacyTransaction />
Expand All @@ -130,7 +131,6 @@ const Index: NextPage = () => {
<SendV0Transaction />
</TableCell>
<TableCell></TableCell>
<TableCell></TableCell>
</TableRow>
</TableBody>
</Table>
Expand Down

0 comments on commit 719c447

Please sign in to comment.