Skip to content

Commit 4fa4d56

Browse files
committed
refactor: use gill createTransaction
1 parent 3e0a3c8 commit 4fa4d56

File tree

6 files changed

+54
-120
lines changed

6 files changed

+54
-120
lines changed

templates/template-next-tailwind-basic/src/components/solana/use-wallet-transaction-sign-and-send.tsx

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,21 @@
11
import { useWalletUi } from '@wallet-ui/react'
2-
import {
3-
appendTransactionMessageInstruction,
4-
assertIsTransactionMessageWithSingleSendingSigner,
5-
createTransactionMessage,
6-
getBase58Decoder,
7-
IInstruction,
8-
pipe,
9-
setTransactionMessageFeePayerSigner,
10-
setTransactionMessageLifetimeUsingBlockhash,
11-
signAndSendTransactionMessageWithSigners,
12-
TransactionSendingSigner,
13-
} from 'gill'
2+
import type { IInstruction, TransactionSendingSigner } from 'gill'
3+
import { createTransaction, getBase58Decoder, signAndSendTransactionMessageWithSigners } from 'gill'
144

155
export function useWalletTransactionSignAndSend() {
166
const { client } = useWalletUi()
177

188
return async (ix: IInstruction, signer: TransactionSendingSigner) => {
199
const { value: latestBlockhash } = await client.rpc.getLatestBlockhash().send()
20-
const message = pipe(
21-
createTransactionMessage({ version: 0 }),
22-
(tx) => setTransactionMessageFeePayerSigner(signer, tx),
23-
(tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx),
24-
(tx) => appendTransactionMessageInstruction(ix, tx),
25-
)
2610

27-
assertIsTransactionMessageWithSingleSendingSigner(message)
11+
const transaction = createTransaction({
12+
feePayer: signer,
13+
version: 0,
14+
latestBlockhash,
15+
instructions: [ix],
16+
})
2817

29-
const signature = await signAndSendTransactionMessageWithSigners(message)
18+
const signature = await signAndSendTransactionMessageWithSigners(transaction)
3019

3120
return getBase58Decoder().decode(signature)
3221
}

templates/template-next-tailwind-counter/src/components/solana/use-wallet-transaction-sign-and-send.tsx

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,21 @@
11
import { useWalletUi } from '@wallet-ui/react'
2-
import {
3-
appendTransactionMessageInstruction,
4-
assertIsTransactionMessageWithSingleSendingSigner,
5-
createTransactionMessage,
6-
getBase58Decoder,
7-
IInstruction,
8-
pipe,
9-
setTransactionMessageFeePayerSigner,
10-
setTransactionMessageLifetimeUsingBlockhash,
11-
signAndSendTransactionMessageWithSigners,
12-
TransactionSendingSigner,
13-
} from 'gill'
2+
import type { IInstruction, TransactionSendingSigner } from 'gill'
3+
import { createTransaction, getBase58Decoder, signAndSendTransactionMessageWithSigners } from 'gill'
144

155
export function useWalletTransactionSignAndSend() {
166
const { client } = useWalletUi()
177

188
return async (ix: IInstruction, signer: TransactionSendingSigner) => {
199
const { value: latestBlockhash } = await client.rpc.getLatestBlockhash().send()
20-
const message = pipe(
21-
createTransactionMessage({ version: 0 }),
22-
(tx) => setTransactionMessageFeePayerSigner(signer, tx),
23-
(tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx),
24-
(tx) => appendTransactionMessageInstruction(ix, tx),
25-
)
2610

27-
assertIsTransactionMessageWithSingleSendingSigner(message)
11+
const transaction = createTransaction({
12+
feePayer: signer,
13+
version: 0,
14+
latestBlockhash,
15+
instructions: [ix],
16+
})
2817

29-
const signature = await signAndSendTransactionMessageWithSigners(message)
18+
const signature = await signAndSendTransactionMessageWithSigners(transaction)
3019

3120
return getBase58Decoder().decode(signature)
3221
}

templates/template-next-tailwind/src/components/solana/use-wallet-transaction-sign-and-send.tsx

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,21 @@
11
import { useWalletUi } from '@wallet-ui/react'
2-
import {
3-
appendTransactionMessageInstruction,
4-
assertIsTransactionMessageWithSingleSendingSigner,
5-
createTransactionMessage,
6-
getBase58Decoder,
7-
IInstruction,
8-
pipe,
9-
setTransactionMessageFeePayerSigner,
10-
setTransactionMessageLifetimeUsingBlockhash,
11-
signAndSendTransactionMessageWithSigners,
12-
TransactionSendingSigner,
13-
} from 'gill'
2+
import type { IInstruction, TransactionSendingSigner } from 'gill'
3+
import { createTransaction, getBase58Decoder, signAndSendTransactionMessageWithSigners } from 'gill'
144

155
export function useWalletTransactionSignAndSend() {
166
const { client } = useWalletUi()
177

188
return async (ix: IInstruction, signer: TransactionSendingSigner) => {
199
const { value: latestBlockhash } = await client.rpc.getLatestBlockhash().send()
20-
const message = pipe(
21-
createTransactionMessage({ version: 0 }),
22-
(tx) => setTransactionMessageFeePayerSigner(signer, tx),
23-
(tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx),
24-
(tx) => appendTransactionMessageInstruction(ix, tx),
25-
)
2610

27-
assertIsTransactionMessageWithSingleSendingSigner(message)
11+
const transaction = createTransaction({
12+
feePayer: signer,
13+
version: 0,
14+
latestBlockhash,
15+
instructions: [ix],
16+
})
2817

29-
const signature = await signAndSendTransactionMessageWithSigners(message)
18+
const signature = await signAndSendTransactionMessageWithSigners(transaction)
3019

3120
return getBase58Decoder().decode(signature)
3221
}

templates/template-react-vite-tailwind-basic/src/components/solana/use-wallet-transaction-sign-and-send.tsx

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,21 @@
11
import { useWalletUi } from '@wallet-ui/react'
2-
import {
3-
appendTransactionMessageInstruction,
4-
assertIsTransactionMessageWithSingleSendingSigner,
5-
createTransactionMessage,
6-
getBase58Decoder,
7-
IInstruction,
8-
pipe,
9-
setTransactionMessageFeePayerSigner,
10-
setTransactionMessageLifetimeUsingBlockhash,
11-
signAndSendTransactionMessageWithSigners,
12-
TransactionSendingSigner,
13-
} from 'gill'
2+
import type { IInstruction, TransactionSendingSigner } from 'gill'
3+
import { createTransaction, getBase58Decoder, signAndSendTransactionMessageWithSigners } from 'gill'
144

155
export function useWalletTransactionSignAndSend() {
166
const { client } = useWalletUi()
177

188
return async (ix: IInstruction, signer: TransactionSendingSigner) => {
199
const { value: latestBlockhash } = await client.rpc.getLatestBlockhash().send()
20-
const message = pipe(
21-
createTransactionMessage({ version: 0 }),
22-
(tx) => setTransactionMessageFeePayerSigner(signer, tx),
23-
(tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx),
24-
(tx) => appendTransactionMessageInstruction(ix, tx),
25-
)
2610

27-
assertIsTransactionMessageWithSingleSendingSigner(message)
11+
const transaction = createTransaction({
12+
feePayer: signer,
13+
version: 0,
14+
latestBlockhash,
15+
instructions: [ix],
16+
})
2817

29-
const signature = await signAndSendTransactionMessageWithSigners(message)
18+
const signature = await signAndSendTransactionMessageWithSigners(transaction)
3019

3120
return getBase58Decoder().decode(signature)
3221
}

templates/template-react-vite-tailwind-counter/src/components/solana/use-wallet-transaction-sign-and-send.tsx

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,21 @@
11
import { useWalletUi } from '@wallet-ui/react'
2-
import {
3-
appendTransactionMessageInstruction,
4-
assertIsTransactionMessageWithSingleSendingSigner,
5-
createTransactionMessage,
6-
getBase58Decoder,
7-
IInstruction,
8-
pipe,
9-
setTransactionMessageFeePayerSigner,
10-
setTransactionMessageLifetimeUsingBlockhash,
11-
signAndSendTransactionMessageWithSigners,
12-
TransactionSendingSigner,
13-
} from 'gill'
2+
import type { IInstruction, TransactionSendingSigner } from 'gill'
3+
import { createTransaction, getBase58Decoder, signAndSendTransactionMessageWithSigners } from 'gill'
144

155
export function useWalletTransactionSignAndSend() {
166
const { client } = useWalletUi()
177

188
return async (ix: IInstruction, signer: TransactionSendingSigner) => {
199
const { value: latestBlockhash } = await client.rpc.getLatestBlockhash().send()
20-
const message = pipe(
21-
createTransactionMessage({ version: 0 }),
22-
(tx) => setTransactionMessageFeePayerSigner(signer, tx),
23-
(tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx),
24-
(tx) => appendTransactionMessageInstruction(ix, tx),
25-
)
2610

27-
assertIsTransactionMessageWithSingleSendingSigner(message)
11+
const transaction = createTransaction({
12+
feePayer: signer,
13+
version: 0,
14+
latestBlockhash,
15+
instructions: [ix],
16+
})
2817

29-
const signature = await signAndSendTransactionMessageWithSigners(message)
18+
const signature = await signAndSendTransactionMessageWithSigners(transaction)
3019

3120
return getBase58Decoder().decode(signature)
3221
}

templates/template-react-vite-tailwind/src/components/solana/use-wallet-transaction-sign-and-send.tsx

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,21 @@
11
import { useWalletUi } from '@wallet-ui/react'
2-
import {
3-
appendTransactionMessageInstruction,
4-
assertIsTransactionMessageWithSingleSendingSigner,
5-
createTransactionMessage,
6-
getBase58Decoder,
7-
IInstruction,
8-
pipe,
9-
setTransactionMessageFeePayerSigner,
10-
setTransactionMessageLifetimeUsingBlockhash,
11-
signAndSendTransactionMessageWithSigners,
12-
TransactionSendingSigner,
13-
} from 'gill'
2+
import type { IInstruction, TransactionSendingSigner } from 'gill'
3+
import { createTransaction, getBase58Decoder, signAndSendTransactionMessageWithSigners } from 'gill'
144

155
export function useWalletTransactionSignAndSend() {
166
const { client } = useWalletUi()
177

188
return async (ix: IInstruction, signer: TransactionSendingSigner) => {
199
const { value: latestBlockhash } = await client.rpc.getLatestBlockhash().send()
20-
const message = pipe(
21-
createTransactionMessage({ version: 0 }),
22-
(tx) => setTransactionMessageFeePayerSigner(signer, tx),
23-
(tx) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx),
24-
(tx) => appendTransactionMessageInstruction(ix, tx),
25-
)
2610

27-
assertIsTransactionMessageWithSingleSendingSigner(message)
11+
const transaction = createTransaction({
12+
feePayer: signer,
13+
version: 0,
14+
latestBlockhash,
15+
instructions: [ix],
16+
})
2817

29-
const signature = await signAndSendTransactionMessageWithSigners(message)
18+
const signature = await signAndSendTransactionMessageWithSigners(transaction)
3019

3120
return getBase58Decoder().decode(signature)
3221
}

0 commit comments

Comments
 (0)