-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
214 additions
and
4 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { WalletAdapterNetwork } from '@solana/wallet-adapter-base'; | ||
import { PublicKey } from '@solana/web3.js'; | ||
|
||
export const wSolMint = new PublicKey('So11111111111111111111111111111111111111112'); | ||
|
||
// todo change addresses | ||
export const OwnerAddress = { | ||
[WalletAdapterNetwork.Mainnet]: new PublicKey('dBLGG3ERvVsAexwfLeRaPUSzQQryKsabNEFKpuMqQqQ'), | ||
[WalletAdapterNetwork.Devnet]: new PublicKey('dBLGG3ERvVsAexwfLeRaPUSzQQryKsabNEFKpuMqQqQ'), | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { useWallet } from '@solana/wallet-adapter-react'; | ||
import { Transaction, SystemProgram } from '@solana/web3.js'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
|
||
import { OwnerAddress } from '@/constants/addresses'; | ||
import { network } from '@/lib/solana'; | ||
import { sendAndConfirmTransaction } from '@/lib/solana/utils'; | ||
import { showTxToast } from '@/lib/utils'; | ||
|
||
const useTransferSolana = () => { | ||
const { publicKey, sendTransaction } = useWallet(); | ||
|
||
return useMutation({ | ||
async mutationFn() { | ||
if (!publicKey) { | ||
return; | ||
} | ||
|
||
await showTxToast('Send Solana', async () => { | ||
const rawTx = new Transaction(); | ||
|
||
rawTx.add( | ||
SystemProgram.transfer({ | ||
fromPubkey: publicKey, | ||
toPubkey: OwnerAddress[network], | ||
lamports: 0.01 * 1e9, | ||
}), | ||
); | ||
|
||
await sendAndConfirmTransaction(publicKey, rawTx, sendTransaction); | ||
}); | ||
}, | ||
|
||
onError(error) { | ||
console.trace(error); | ||
}, | ||
}); | ||
}; | ||
|
||
export default useTransferSolana; |
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 |
---|---|---|
|
@@ -32,6 +32,7 @@ body { | |
place-items: center; | ||
min-width: 320px; | ||
min-height: 100vh; | ||
background-color: #83a4c5; | ||
} | ||
|
||
h1 { | ||
|
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-expressions */ | ||
import { WalletAdapterProps } from '@solana/wallet-adapter-base'; | ||
import { PublicKey, Transaction } from '@solana/web3.js'; | ||
|
||
import { connection } from '.'; | ||
|
||
export const sendAndConfirmTransaction = async ( | ||
payer: PublicKey, | ||
tx: Transaction, | ||
sendTransaction: WalletAdapterProps['sendTransaction'], | ||
): Promise<string> => { | ||
const latestBlockHash = await connection.getLatestBlockhash({ | ||
commitment: 'finalized', | ||
}); | ||
|
||
tx.feePayer = payer; | ||
tx.recentBlockhash = latestBlockHash.blockhash; | ||
|
||
const txHash = await sendTransaction(tx, connection, { skipPreflight: true }); | ||
|
||
const result = await connection.confirmTransaction( | ||
{ | ||
...latestBlockHash, | ||
signature: txHash, | ||
}, | ||
'finalized', | ||
); | ||
|
||
if (result.value.err) result.value.err; | ||
|
||
return txHash; | ||
}; |
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,10 +1,17 @@ | ||
import { ConnectWalletButton } from '@/components/common/Header/connect-wallet-button'; | ||
import useTransferSolana from '@/hooks/contracts/write/use-transfer-solana'; | ||
|
||
export function HomePage() { | ||
const { mutateAsync: transfer } = useTransferSolana(); | ||
|
||
const handleTransfer = async () => { | ||
await transfer(); | ||
}; | ||
return ( | ||
<div> | ||
<h1>Home page</h1> | ||
<ConnectWalletButton /> | ||
<button onClick={() => void handleTransfer()}>handleTransfer</button> | ||
</div> | ||
); | ||
} |
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 |
---|---|---|
|
@@ -1510,7 +1510,17 @@ | |
dependencies: | ||
"@solana/errors" "2.0.0" | ||
|
||
"@solana/buffer-layout@^4.0.1": | ||
"@solana/buffer-layout-utils@^0.2.0": | ||
version "0.2.0" | ||
resolved "https://registry.yarnpkg.com/@solana/buffer-layout-utils/-/buffer-layout-utils-0.2.0.tgz#b45a6cab3293a2eb7597cceb474f229889d875ca" | ||
integrity sha512-szG4sxgJGktbuZYDg2FfNmkMi0DYQoVjN2h7ta1W1hPrwzarcFLBq9UpX1UjNXsNpT9dn+chgprtWGioUAr4/g== | ||
dependencies: | ||
"@solana/buffer-layout" "^4.0.0" | ||
"@solana/web3.js" "^1.32.0" | ||
bigint-buffer "^1.1.5" | ||
bignumber.js "^9.0.1" | ||
|
||
"@solana/buffer-layout@^4.0.0", "@solana/buffer-layout@^4.0.1": | ||
version "4.0.1" | ||
resolved "https://registry.yarnpkg.com/@solana/buffer-layout/-/buffer-layout-4.0.1.tgz#b996235eaec15b1e0b5092a8ed6028df77fa6c15" | ||
integrity sha512-E1ImOIAD1tBZFRdjeM4/pzTiTApC0AOBGwyAMS4fwIodCWArzJ3DWdoh8cKxeFM2fElkxBh2Aqts1BPC373rHA== | ||
|
@@ -1524,6 +1534,13 @@ | |
dependencies: | ||
"@solana/errors" "2.0.0" | ||
|
||
"@solana/[email protected]": | ||
version "2.0.0-rc.1" | ||
resolved "https://registry.yarnpkg.com/@solana/codecs-core/-/codecs-core-2.0.0-rc.1.tgz#1a2d76b9c7b9e7b7aeb3bd78be81c2ba21e3ce22" | ||
integrity sha512-bauxqMfSs8EHD0JKESaNmNuNvkvHSuN3bbWAF5RjOfDu2PugxHrvRebmYauvSumZ3cTfQ4HJJX6PG5rN852qyQ== | ||
dependencies: | ||
"@solana/errors" "2.0.0-rc.1" | ||
|
||
"@solana/[email protected]": | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/@solana/codecs-data-structures/-/codecs-data-structures-2.0.0.tgz#0a06b8646634dcf44a7b1d968fe8d9218c3cb745" | ||
|
@@ -1533,6 +1550,15 @@ | |
"@solana/codecs-numbers" "2.0.0" | ||
"@solana/errors" "2.0.0" | ||
|
||
"@solana/[email protected]": | ||
version "2.0.0-rc.1" | ||
resolved "https://registry.yarnpkg.com/@solana/codecs-data-structures/-/codecs-data-structures-2.0.0-rc.1.tgz#d47b2363d99fb3d643f5677c97d64a812982b888" | ||
integrity sha512-rinCv0RrAVJ9rE/rmaibWJQxMwC5lSaORSZuwjopSUE6T0nb/MVg6Z1siNCXhh/HFTOg0l8bNvZHgBcN/yvXog== | ||
dependencies: | ||
"@solana/codecs-core" "2.0.0-rc.1" | ||
"@solana/codecs-numbers" "2.0.0-rc.1" | ||
"@solana/errors" "2.0.0-rc.1" | ||
|
||
"@solana/[email protected]": | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/@solana/codecs-numbers/-/codecs-numbers-2.0.0.tgz#c08250968fa1cbfab076367b650269271061c646" | ||
|
@@ -1541,6 +1567,14 @@ | |
"@solana/codecs-core" "2.0.0" | ||
"@solana/errors" "2.0.0" | ||
|
||
"@solana/[email protected]": | ||
version "2.0.0-rc.1" | ||
resolved "https://registry.yarnpkg.com/@solana/codecs-numbers/-/codecs-numbers-2.0.0-rc.1.tgz#f34978ddf7ea4016af3aaed5f7577c1d9869a614" | ||
integrity sha512-J5i5mOkvukXn8E3Z7sGIPxsThRCgSdgTWJDQeZvucQ9PT6Y3HiVXJ0pcWiOWAoQ3RX8e/f4I3IC+wE6pZiJzDQ== | ||
dependencies: | ||
"@solana/codecs-core" "2.0.0-rc.1" | ||
"@solana/errors" "2.0.0-rc.1" | ||
|
||
"@solana/[email protected]": | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/@solana/codecs-strings/-/codecs-strings-2.0.0.tgz#46e728adee9a4737c3ee811af452948aab31cbd4" | ||
|
@@ -1550,6 +1584,15 @@ | |
"@solana/codecs-numbers" "2.0.0" | ||
"@solana/errors" "2.0.0" | ||
|
||
"@solana/[email protected]": | ||
version "2.0.0-rc.1" | ||
resolved "https://registry.yarnpkg.com/@solana/codecs-strings/-/codecs-strings-2.0.0-rc.1.tgz#e1d9167075b8c5b0b60849f8add69c0f24307018" | ||
integrity sha512-9/wPhw8TbGRTt6mHC4Zz1RqOnuPTqq1Nb4EyuvpZ39GW6O2t2Q7Q0XxiB3+BdoEjwA2XgPw6e2iRfvYgqty44g== | ||
dependencies: | ||
"@solana/codecs-core" "2.0.0-rc.1" | ||
"@solana/codecs-numbers" "2.0.0-rc.1" | ||
"@solana/errors" "2.0.0-rc.1" | ||
|
||
"@solana/[email protected]": | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/@solana/codecs/-/codecs-2.0.0.tgz#2a3f272932eebad5b8592e6263b068c7d0761e7f" | ||
|
@@ -1561,6 +1604,17 @@ | |
"@solana/codecs-strings" "2.0.0" | ||
"@solana/options" "2.0.0" | ||
|
||
"@solana/[email protected]": | ||
version "2.0.0-rc.1" | ||
resolved "https://registry.yarnpkg.com/@solana/codecs/-/codecs-2.0.0-rc.1.tgz#146dc5db58bd3c28e04b4c805e6096c2d2a0a875" | ||
integrity sha512-qxoR7VybNJixV51L0G1RD2boZTcxmwUWnKCaJJExQ5qNKwbpSyDdWfFJfM5JhGyKe9DnPVOZB+JHWXnpbZBqrQ== | ||
dependencies: | ||
"@solana/codecs-core" "2.0.0-rc.1" | ||
"@solana/codecs-data-structures" "2.0.0-rc.1" | ||
"@solana/codecs-numbers" "2.0.0-rc.1" | ||
"@solana/codecs-strings" "2.0.0-rc.1" | ||
"@solana/options" "2.0.0-rc.1" | ||
|
||
"@solana/[email protected]": | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/@solana/errors/-/errors-2.0.0.tgz#31c87baaf4b19aaa2a1d8bbc4dfa6efd449d7bbe" | ||
|
@@ -1569,6 +1623,14 @@ | |
chalk "^5.3.0" | ||
commander "^12.1.0" | ||
|
||
"@solana/[email protected]": | ||
version "2.0.0-rc.1" | ||
resolved "https://registry.yarnpkg.com/@solana/errors/-/errors-2.0.0-rc.1.tgz#3882120886eab98a37a595b85f81558861b29d62" | ||
integrity sha512-ejNvQ2oJ7+bcFAYWj225lyRkHnixuAeb7RQCixm+5mH4n1IA4Qya/9Bmfy5RAAHQzxK43clu3kZmL5eF9VGtYQ== | ||
dependencies: | ||
chalk "^5.3.0" | ||
commander "^12.1.0" | ||
|
||
"@solana/[email protected]": | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/@solana/fast-stable-stringify/-/fast-stable-stringify-2.0.0.tgz#ac06b304ee3e050c171bcbe885e91772e22e06fb" | ||
|
@@ -1607,6 +1669,17 @@ | |
"@solana/codecs-strings" "2.0.0" | ||
"@solana/errors" "2.0.0" | ||
|
||
"@solana/[email protected]": | ||
version "2.0.0-rc.1" | ||
resolved "https://registry.yarnpkg.com/@solana/options/-/options-2.0.0-rc.1.tgz#06924ba316dc85791fc46726a51403144a85fc4d" | ||
integrity sha512-mLUcR9mZ3qfHlmMnREdIFPf9dpMc/Bl66tLSOOWxw4ml5xMT2ohFn7WGqoKcu/UHkT9CrC6+amEdqCNvUqI7AA== | ||
dependencies: | ||
"@solana/codecs-core" "2.0.0-rc.1" | ||
"@solana/codecs-data-structures" "2.0.0-rc.1" | ||
"@solana/codecs-numbers" "2.0.0-rc.1" | ||
"@solana/codecs-strings" "2.0.0-rc.1" | ||
"@solana/errors" "2.0.0-rc.1" | ||
|
||
"@solana/[email protected]": | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/@solana/programs/-/programs-2.0.0.tgz#1c0fa1c98a8cf6fab3ac722fe768e110057eeaf9" | ||
|
@@ -1764,6 +1837,31 @@ | |
"@solana/transaction-messages" "2.0.0" | ||
"@solana/transactions" "2.0.0" | ||
|
||
"@solana/spl-token-group@^0.0.7": | ||
version "0.0.7" | ||
resolved "https://registry.yarnpkg.com/@solana/spl-token-group/-/spl-token-group-0.0.7.tgz#83c00f0cd0bda33115468cd28b89d94f8ec1fee4" | ||
integrity sha512-V1N/iX7Cr7H0uazWUT2uk27TMqlqedpXHRqqAbVO2gvmJyT0E0ummMEAVQeXZ05ZhQ/xF39DLSdBp90XebWEug== | ||
dependencies: | ||
"@solana/codecs" "2.0.0-rc.1" | ||
|
||
"@solana/spl-token-metadata@^0.1.6": | ||
version "0.1.6" | ||
resolved "https://registry.yarnpkg.com/@solana/spl-token-metadata/-/spl-token-metadata-0.1.6.tgz#d240947aed6e7318d637238022a7b0981b32ae80" | ||
integrity sha512-7sMt1rsm/zQOQcUWllQX9mD2O6KhSAtY1hFR2hfFwgqfFWzSY9E9GDvFVNYUI1F0iQKcm6HmePU9QbKRXTEBiA== | ||
dependencies: | ||
"@solana/codecs" "2.0.0-rc.1" | ||
|
||
"@solana/spl-token@^0.4.9": | ||
version "0.4.9" | ||
resolved "https://registry.yarnpkg.com/@solana/spl-token/-/spl-token-0.4.9.tgz#24d032d2935f237925c3b058ba6bb1e1ece5428c" | ||
integrity sha512-g3wbj4F4gq82YQlwqhPB0gHFXfgsC6UmyGMxtSLf/BozT/oKd59465DbnlUK8L8EcimKMavxsVAMoLcEdeCicg== | ||
dependencies: | ||
"@solana/buffer-layout" "^4.0.0" | ||
"@solana/buffer-layout-utils" "^0.2.0" | ||
"@solana/spl-token-group" "^0.0.7" | ||
"@solana/spl-token-metadata" "^0.1.6" | ||
buffer "^6.0.3" | ||
|
||
"@solana/[email protected]": | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/@solana/subscribable/-/subscribable-2.0.0.tgz#6476bf253395c077f9fdbd4a9b83011734a86b06" | ||
|
@@ -2237,7 +2335,7 @@ | |
"@solana/wallet-standard-core" "^1.1.1" | ||
"@solana/wallet-standard-wallet-adapter" "^1.1.2" | ||
|
||
"@solana/web3.js@^1.36.0", "@solana/web3.js@^1.63.1", "@solana/web3.js@^1.98.0": | ||
"@solana/web3.js@^1.32.0", "@solana/web3.js@^1.36.0", "@solana/web3.js@^1.63.1", "@solana/web3.js@^1.98.0": | ||
version "1.98.0" | ||
resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.98.0.tgz#21ecfe8198c10831df6f0cfde7f68370d0405917" | ||
integrity sha512-nz3Q5OeyGFpFCR+erX2f6JPt3sKhzhYcSycBCSPkWjzSVDh/Rr1FqTVMRe58FKO16/ivTUcuJjeS5MyBvpkbzA== | ||
|
@@ -6560,6 +6658,13 @@ react-style-singleton@^2.2.1, react-style-singleton@^2.2.2: | |
get-nonce "^1.0.0" | ||
tslib "^2.0.0" | ||
|
||
react-toastify@^11.0.2: | ||
version "11.0.2" | ||
resolved "https://registry.yarnpkg.com/react-toastify/-/react-toastify-11.0.2.tgz#5c5ae745f3c7240015a8746217595cd26701fdc3" | ||
integrity sha512-GjHuGaiXMvbls3ywqv8XdWONwrcO4DXCJIY1zVLkHU73gEElKvTTXNI5Vom3s/k/M8hnkrfsqgBSX3OwmlonbA== | ||
dependencies: | ||
clsx "^2.1.1" | ||
|
||
[email protected]: | ||
version "16.13.1" | ||
resolved "https://registry.yarnpkg.com/react/-/react-16.13.1.tgz#2e818822f1a9743122c063d6410d85c1e3afe48e" | ||
|