-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
refactor: solana walletconnect rpc interface #2677
Merged
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1564601
refactor: update solana rpc interface for serialized transactions
zoruka c4a5bce
feat: add SolanaSignAndSendTransactionTest for versioned transactions
zoruka bb18ae5
feat: add disclaimer for differents sign and send transaction tests
zoruka 48f5c04
refactor: set same interface for sendTransaction function
zoruka 78da2ac
fix: unnecessary type casting
zoruka d8d8b50
fix: type assertion for connection object
zoruka f9c1a87
Merge branch 'main' into refactor/solana-wallet-rpc-interface
glitch-txs 294104d
chore: address code style improvements
zoruka 6c8f9bb
Merge branch 'main' of github.com:WalletConnect/web3modal into refact…
zoruka 40785a2
Merge branch 'refactor/solana-wallet-rpc-interface' of github.com:Wal…
zoruka 0e4707d
refactor: change options param to sendOptions
zoruka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,28 @@ | ||
import { useState } from 'react' | ||
import { Button, Stack, Text, Spacer, Link } from '@chakra-ui/react' | ||
import { useWeb3ModalAccount, useWeb3ModalProvider } from '@web3modal/solana/react' | ||
import { PublicKey, Transaction, SystemProgram } from '@solana/web3.js' | ||
import { | ||
PublicKey, | ||
Transaction, | ||
SystemProgram, | ||
TransactionMessage, | ||
VersionedTransaction | ||
} from '@solana/web3.js' | ||
|
||
import { solana } from '../../utils/ChainsUtil' | ||
import { useChakraToast } from '../Toast' | ||
|
||
const PHANTOM_TESTNET_ADDRESS = '8vCyX7oB6Pc3pbWMGYYZF5pbSnAdQ7Gyr32JqxqCy8ZR' | ||
const recipientAddress = new PublicKey(PHANTOM_TESTNET_ADDRESS) | ||
const amountInLamports = 50000000 | ||
const amountInLamports = 10000000 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
|
||
export function SolanaSignAndSendTransaction() { | ||
const toast = useChakraToast() | ||
const { address, chainId } = useWeb3ModalAccount() | ||
const { walletProvider, connection } = useWeb3ModalProvider() | ||
const [loading, setLoading] = useState(false) | ||
|
||
async function onSendTransaction() { | ||
async function onSendTransaction(mode: 'legacy' | 'versioned') { | ||
try { | ||
setLoading(true) | ||
if (!walletProvider || !address) { | ||
|
@@ -32,16 +38,34 @@ export function SolanaSignAndSendTransaction() { | |
throw Error('Not enough SOL in wallet') | ||
} | ||
|
||
// Create a new transaction | ||
const transaction = new Transaction().add( | ||
SystemProgram.transfer({ | ||
fromPubkey: walletProvider.publicKey, | ||
toPubkey: recipientAddress, | ||
lamports: amountInLamports | ||
}) | ||
) | ||
transaction.feePayer = walletProvider.publicKey | ||
const signature = await walletProvider.signAndSendTransaction(transaction) | ||
const instruction = SystemProgram.transfer({ | ||
fromPubkey: walletProvider.publicKey, | ||
toPubkey: recipientAddress, | ||
lamports: amountInLamports | ||
}) | ||
const { blockhash } = await connection.getLatestBlockhash() | ||
|
||
let signature = '' | ||
|
||
if (mode === 'versioned') { | ||
// Create v0 compatible message | ||
const messageV0 = new TransactionMessage({ | ||
payerKey: walletProvider.publicKey, | ||
recentBlockhash: blockhash, | ||
instructions: [instruction] | ||
}).compileToV0Message() | ||
|
||
// Make a versioned transaction | ||
const versionedTranasction = new VersionedTransaction(messageV0) | ||
|
||
signature = await walletProvider.signAndSendTransaction(versionedTranasction) | ||
} else { | ||
// Create a new transaction | ||
const transaction = new Transaction().add(instruction) | ||
transaction.feePayer = walletProvider.publicKey | ||
transaction.recentBlockhash = blockhash | ||
signature = await walletProvider.signAndSendTransaction(transaction) | ||
} | ||
|
||
toast({ | ||
title: 'Success', | ||
|
@@ -75,11 +99,18 @@ export function SolanaSignAndSendTransaction() { | |
<Stack direction={['column', 'column', 'row']}> | ||
<Button | ||
data-test-id="sign-transaction-button" | ||
onClick={onSendTransaction} | ||
onClick={() => onSendTransaction('legacy')} | ||
isDisabled={loading} | ||
> | ||
Sign and Send Transaction | ||
</Button> | ||
<Button | ||
data-test-id="sign-transaction-button" | ||
onClick={() => onSendTransaction('versioned')} | ||
isDisabled={loading} | ||
> | ||
Sign and Send Versioned Transaction | ||
</Button> | ||
<Spacer /> | ||
|
||
<Link isExternal href="https://solfaucet.com/"> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use underscores for better readability?