From 7c859bcc2d793450326f310e76f7a0bfd26dcf28 Mon Sep 17 00:00:00 2001 From: NikiTaysRD Date: Fri, 17 Jan 2025 17:17:00 +0200 Subject: [PATCH 1/4] feat: add currencies --- package.json | 1 + .../common/CurrencySelect/index.tsx | 22 +++ src/components/pages/game/game.tsx | 18 +-- src/components/ui/select.tsx | 144 ++++++++++++++++++ src/constants/addresses.ts | 24 ++- src/env.ts | 5 + src/hooks/api/use-submit-cards.ts | 13 +- .../contracts/write/use-make-prediction.ts | 38 ++--- src/hooks/contracts/write/use-send-sol.ts | 21 ++- src/hooks/contracts/write/use-send.ts | 63 ++++++++ src/lib/utils.ts | 33 +++- yarn.lock | 60 ++++++++ 12 files changed, 398 insertions(+), 44 deletions(-) create mode 100644 src/components/common/CurrencySelect/index.tsx create mode 100644 src/components/ui/select.tsx create mode 100644 src/hooks/contracts/write/use-send.ts diff --git a/package.json b/package.json index 2196fa7..854e5b5 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "@radix-ui/react-accordion": "^1.2.2", "@radix-ui/react-dialog": "^1.1.4", "@radix-ui/react-popover": "^1.1.4", + "@radix-ui/react-select": "^2.1.4", "@radix-ui/react-slot": "^1.1.1", "@radix-ui/react-tooltip": "^1.1.6", "@solana/spl-token": "^0.4.9", diff --git a/src/components/common/CurrencySelect/index.tsx b/src/components/common/CurrencySelect/index.tsx new file mode 100644 index 0000000..69f983a --- /dev/null +++ b/src/components/common/CurrencySelect/index.tsx @@ -0,0 +1,22 @@ +import Solana from '@/components/common/Svg/Solana.tsx'; +import { Select, SelectTrigger, SelectItem, SelectValue, SelectContent } from '@/components/ui/select.tsx'; + +export const CurrencySelect = () => { + return ( + + ); +}; diff --git a/src/components/pages/game/game.tsx b/src/components/pages/game/game.tsx index ecf4c71..f4a9f70 100644 --- a/src/components/pages/game/game.tsx +++ b/src/components/pages/game/game.tsx @@ -6,12 +6,12 @@ import { toast } from 'react-toastify'; import { z } from 'zod'; import { BaseTooltip } from '@/components/common/BaseTooltip'; +import { CurrencySelect } from '@/components/common/CurrencySelect'; import Solana from '@/components/common/Svg/Solana.tsx'; import { Button } from '@/components/ui/button.tsx'; -import { env } from '@/env'; import useStatus from '@/hooks/api/use-status'; import useMakePrediction from '@/hooks/contracts/write/use-make-prediction'; -import useSendSol from '@/hooks/contracts/write/use-send-sol'; +import useSend from '@/hooks/contracts/write/use-send.ts'; import { cn } from '@/lib/utils'; import { useWalletModalStore } from '@/store/wallet-modal.tsx'; @@ -46,7 +46,7 @@ export const GameSection = () => { const { setIsOpen } = useWalletModalStore(); const { mutateAsync: transfer, isSuccess, isPending, data: predictionAnswer } = useMakePrediction(); - const { mutateAsync: transferSol, isPending: isSolPending, isSuccess: isTipSuccess } = useSendSol(); + const { mutateAsync: transferCurrency, isPending: isSolPending, isSuccess: isTipSuccess } = useSend(); const { data: status } = useStatus(); const [selectedTip, setSelectedTip] = useState(0); @@ -69,7 +69,7 @@ export const GameSection = () => { const onSubmit: SubmitHandler = async (data, e) => { e?.preventDefault(); - await transfer(data.question.trim()); + await transfer({ question: data.question.trim(), tokenName: 'usdcMint' }); }; const handleTip = async () => { @@ -83,7 +83,7 @@ export const GameSection = () => { return; } - await transferSol(selectedTip); + await transferCurrency({ amount: selectedTip, tokenName: 'usdcMint' }); }; useEffect(() => { @@ -213,11 +213,7 @@ export const GameSection = () => {
-
- -
{env.VITE_DEPOSIT_AMOUNT_SOL} SOL
-
- + {publicKey ? (
- {showTip && ( + {true && (
diff --git a/src/components/ui/select.tsx b/src/components/ui/select.tsx new file mode 100644 index 0000000..a33cafc --- /dev/null +++ b/src/components/ui/select.tsx @@ -0,0 +1,144 @@ +'use client'; + +import * as SelectPrimitive from '@radix-ui/react-select'; +import { Check, ChevronDown, ChevronUp } from 'lucide-react'; +import * as React from 'react'; + +import { cn } from '@/lib/utils'; + +const Select = SelectPrimitive.Root; + +const SelectGroup = SelectPrimitive.Group; + +const SelectValue = SelectPrimitive.Value; + +const SelectTrigger = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, children, ...props }, ref) => ( + span]:line-clamp-1', + className, + )} + {...props} + > + {children} + + + + +)); +SelectTrigger.displayName = SelectPrimitive.Trigger.displayName; + +const SelectScrollUpButton = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + + + +)); +SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName; + +const SelectScrollDownButton = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + + + +)); +SelectScrollDownButton.displayName = SelectPrimitive.ScrollDownButton.displayName; + +const SelectContent = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, children, position = 'popper', ...props }, ref) => ( + + + + + {children} + + + + +)); +SelectContent.displayName = SelectPrimitive.Content.displayName; + +const SelectLabel = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)); +SelectLabel.displayName = SelectPrimitive.Label.displayName; + +const SelectItem = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, children, ...props }, ref) => ( + + + + + + + {children} + +)); +SelectItem.displayName = SelectPrimitive.Item.displayName; + +const SelectSeparator = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)); +SelectSeparator.displayName = SelectPrimitive.Separator.displayName; + +export { + Select, + SelectGroup, + SelectValue, + SelectTrigger, + SelectContent, + SelectLabel, + SelectItem, + SelectSeparator, + SelectScrollUpButton, + SelectScrollDownButton, +}; diff --git a/src/constants/addresses.ts b/src/constants/addresses.ts index 7f36eca..ef17b93 100644 --- a/src/constants/addresses.ts +++ b/src/constants/addresses.ts @@ -1,9 +1,31 @@ import { WalletAdapterNetwork } from '@solana/wallet-adapter-base'; import { PublicKey } from '@solana/web3.js'; -export const wSolMint = new PublicKey('So11111111111111111111111111111111111111112'); +import { env } from '@/env.ts'; + +export const wSolMint = new PublicKey(env.VITE_WSOL_MINT); +export const usdcMint = new PublicKey(env.VITE_USDC_MINT); +export const usdtMint = new PublicKey(env.VITE_USDT_MINT); export const OwnerAddress = { [WalletAdapterNetwork.Mainnet]: new PublicKey('2Mko2nLhSiehXGJDseYCj6hYQdrK3cKNMetcGaXtbrJk'), [WalletAdapterNetwork.Devnet]: new PublicKey('8LD69Ao7ULmWJNWULkUa5jhaLY9n7ucWcVGFcbfrFNwm'), }; + +export const currencies = { + wSolMint: { + address: wSolMint, + decimals: 9, + tips: [], + }, + usdcMint: { + address: usdcMint, + decimals: 6, + }, + usdtMint: { + address: usdtMint, + decimals: 6, + }, +}; + +export type TCurrencies = keyof typeof currencies; diff --git a/src/env.ts b/src/env.ts index e3d5456..986ef68 100644 --- a/src/env.ts +++ b/src/env.ts @@ -8,6 +8,11 @@ export const env = createEnv({ VITE_PUBLIC_NETWORKS_MODE: z.enum(['testnet', 'mainnet']).default('testnet'), VITE_PUBLIC_SOLANA_RPC: z.string().optional(), VITE_DEPOSIT_AMOUNT_SOL: z.string().default('0.003'), + VITE_DEPOSIT_AMOUNT_USDT: z.string().default('0.003'), + VITE_DEPOSIT_AMOUNT_USDC: z.string().default('0.003'), + VITE_WSOL_MINT: z.string().default('So11111111111111111111111111111111111111112'), + VITE_USDC_MINT: z.string().default('GcdYBygdoiv6KNH4noHmdkK5hvKqdnfUUKMhe9d7vHek'), + VITE_USDT_MINT: z.string().default('DViAQybZkCmA3RioGmaZ3c5SsxAdPARoCTKpE5qKe8Z9'), VITE_TWITTER_URL: z.string().optional(), }, runtimeEnv: import.meta.env, diff --git a/src/hooks/api/use-submit-cards.ts b/src/hooks/api/use-submit-cards.ts index 30dd55b..27c128b 100644 --- a/src/hooks/api/use-submit-cards.ts +++ b/src/hooks/api/use-submit-cards.ts @@ -10,7 +10,17 @@ const useSubmitTarotCards = () => { const { publicKey } = useWallet(); return useMutation({ - async mutationFn({ tarots, hash, question }: { tarots: TarotCard[]; hash: string; question: string }) { + async mutationFn({ + tarots, + hash, + question, + address, + }: { + tarots: TarotCard[]; + hash: string; + question: string; + address: string; + }) { if (!publicKey) { return; } @@ -21,6 +31,7 @@ const useSubmitTarotCards = () => { tarots, hash, question, + address, }); }, diff --git a/src/hooks/contracts/write/use-make-prediction.ts b/src/hooks/contracts/write/use-make-prediction.ts index 87ef875..9cef8b1 100644 --- a/src/hooks/contracts/write/use-make-prediction.ts +++ b/src/hooks/contracts/write/use-make-prediction.ts @@ -1,13 +1,10 @@ import { useWallet } from '@solana/wallet-adapter-react'; -import { SystemProgram, Transaction } from '@solana/web3.js'; import { useMutation } from '@tanstack/react-query'; import { toast } from 'react-toastify'; -import { OwnerAddress } from '@/constants/addresses'; -import { env } from '@/env'; +import { currencies, TCurrencies } from '@/constants/addresses.ts'; import useSubmitTarotCards from '@/hooks/api/use-submit-cards'; -import { network } from '@/lib/solana'; -import { sendAndConfirmTransaction } from '@/lib/solana/utils'; +import useSend from '@/hooks/contracts/write/use-send.ts'; import { getRandomTarotCards } from '@/lib/utils'; import { Status, useStatusModalStore } from '@/store/status-modal'; @@ -23,34 +20,39 @@ const notify = () => { }); }; +interface IMakePrediction { + question: string; + tokenName: TCurrencies; +} + const useMakePrediction = () => { - const { publicKey, sendTransaction } = useWallet(); + const { publicKey } = useWallet(); const { mutateAsync: submitCards } = useSubmitTarotCards(); + const { mutateAsync: sendCurrency } = useSend(); const { setStatus } = useStatusModalStore(); return useMutation({ - async mutationFn(question: string) { + async mutationFn({ question, tokenName }: IMakePrediction) { if (!publicKey) { return; } notify(); - const rawTx = new Transaction(); - - rawTx.add( - SystemProgram.transfer({ - fromPubkey: publicKey, - toPubkey: OwnerAddress[network], - lamports: Number(env.VITE_DEPOSIT_AMOUNT_SOL) * 1e9, - }), - ); + const txHash = await sendCurrency({ amount: 0.4, tokenName }); - const txHash = await sendAndConfirmTransaction(publicKey, rawTx, sendTransaction); + if (!txHash) { + return; + } const tarots = getRandomTarotCards(txHash + publicKey.toBase58()); - const result = await submitCards({ tarots, hash: txHash, question }); + const result = await submitCards({ + tarots, + hash: txHash, + question, + address: currencies.usdcMint.address.toString(), + }); if (toastId) { toast.dismiss(toastId); diff --git a/src/hooks/contracts/write/use-send-sol.ts b/src/hooks/contracts/write/use-send-sol.ts index 25bebb2..d20f46d 100644 --- a/src/hooks/contracts/write/use-send-sol.ts +++ b/src/hooks/contracts/write/use-send-sol.ts @@ -5,7 +5,6 @@ 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 useSendSol = () => { const { publicKey, sendTransaction } = useWallet(); @@ -16,19 +15,17 @@ const useSendSol = () => { return; } - await showTxToast('Tipping the Oracle', async () => { - const rawTx = new Transaction(); + const rawTx = new Transaction(); - rawTx.add( - SystemProgram.transfer({ - fromPubkey: publicKey, - toPubkey: OwnerAddress[network], - lamports: Number(amount) * 1e9, - }), - ); + rawTx.add( + SystemProgram.transfer({ + fromPubkey: publicKey, + toPubkey: OwnerAddress[network], + lamports: Number(amount) * 1e9, + }), + ); - await sendAndConfirmTransaction(publicKey, rawTx, sendTransaction); - }); + return await sendAndConfirmTransaction(publicKey, rawTx, sendTransaction); }, onError(error) { console.trace(error); diff --git a/src/hooks/contracts/write/use-send.ts b/src/hooks/contracts/write/use-send.ts new file mode 100644 index 0000000..b4d1242 --- /dev/null +++ b/src/hooks/contracts/write/use-send.ts @@ -0,0 +1,63 @@ +import { getAssociatedTokenAddress, createTransferInstruction } from '@solana/spl-token'; +import { useWallet } from '@solana/wallet-adapter-react'; +import { PublicKey, Transaction } from '@solana/web3.js'; +import { useMutation } from '@tanstack/react-query'; + +import { currencies, OwnerAddress, TCurrencies } from '@/constants/addresses'; +import useSendSol from '@/hooks/contracts/write/use-send-sol.ts'; +import { network } from '@/lib/solana'; +import { sendAndConfirmTransaction } from '@/lib/solana/utils'; +import { generateAssociatedTokenAccountInstruction } from '@/lib/utils.ts'; + +const recipient = new PublicKey(OwnerAddress[network]); + +interface ISend { + amount: number; + tokenName: TCurrencies; +} + +const useSend = () => { + const { publicKey, sendTransaction } = useWallet(); + const { mutateAsync: sendSol } = useSendSol(); + + return useMutation({ + async mutationFn({ amount, tokenName }: ISend) { + if (!publicKey) { + return; + } + + if (tokenName === 'wSolMint') { + await sendSol(amount); + return; + } + + const { address: mint, decimals } = currencies[tokenName]; + + const rawTx = new Transaction(); + + const senderTokenAddress = await getAssociatedTokenAddress(mint, publicKey); + const recipientTokenAddress = await getAssociatedTokenAddress(mint, recipient); + + const associatedTokenAccountInstruction = await generateAssociatedTokenAccountInstruction({ + owner: recipient, + payer: publicKey, + mint, + }); + + if (associatedTokenAccountInstruction) { + rawTx.add(associatedTokenAccountInstruction); + } + + rawTx.add( + createTransferInstruction(senderTokenAddress, recipientTokenAddress, publicKey, amount * 10 ** decimals), + ); + + return await sendAndConfirmTransaction(publicKey, rawTx, sendTransaction); + }, + onError(error) { + console.trace(error); + }, + }); +}; + +export default useSend; diff --git a/src/lib/utils.ts b/src/lib/utils.ts index dee146f..89dcc30 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -1,8 +1,15 @@ -import { clsx, type ClassValue } from 'clsx'; +import { + ASSOCIATED_TOKEN_PROGRAM_ID, + createAssociatedTokenAccountInstruction, + TOKEN_PROGRAM_ID, +} from '@solana/spl-token'; +import { PublicKey, TransactionInstruction } from '@solana/web3.js'; +import { type ClassValue, clsx } from 'clsx'; import { toast } from 'react-toastify'; import { twMerge } from 'tailwind-merge'; import { stringToBytes } from 'viem'; +import { connection } from '@/lib/solana'; import { TarotCard } from '@/types/tarot'; export function cn(...inputs: ClassValue[]) { @@ -60,3 +67,27 @@ const splitStringIntoEqualParts = (str: string, partSize: number): string[] => { return parts; }; + +export async function generateAssociatedTokenAccountInstruction({ + owner, + payer, + mint, +}: { + payer: PublicKey; + owner: PublicKey; + mint: PublicKey; +}): Promise { + const associatedTokenAccount = PublicKey.findProgramAddressSync( + [owner.toBuffer(), TOKEN_PROGRAM_ID.toBuffer(), mint.toBuffer()], + ASSOCIATED_TOKEN_PROGRAM_ID, + ); + + const accountInfo = await connection.getAccountInfo(associatedTokenAccount[0]); + + if (accountInfo) { + console.log('Associated token account already exists'); + return undefined; + } + + return createAssociatedTokenAccountInstruction(payer, associatedTokenAccount[0], owner, mint); +} diff --git a/yarn.lock b/yarn.lock index 30cf2d5..8823a04 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1553,6 +1553,13 @@ __metadata: languageName: node linkType: hard +"@radix-ui/number@npm:1.1.0": + version: 1.1.0 + resolution: "@radix-ui/number@npm:1.1.0" + checksum: 10c0/a48e34d5ff1484de1b7cf5d7317fefc831d49e96a2229f300fd37b657bd8cfb59c922830c00ec02838ab21de3b299a523474592e4f30882153412ed47edce6a4 + languageName: node + linkType: hard + "@radix-ui/primitive@npm:1.1.1": version: 1.1.1 resolution: "@radix-ui/primitive@npm:1.1.1" @@ -1917,6 +1924,45 @@ __metadata: languageName: node linkType: hard +"@radix-ui/react-select@npm:^2.1.4": + version: 2.1.4 + resolution: "@radix-ui/react-select@npm:2.1.4" + dependencies: + "@radix-ui/number": "npm:1.1.0" + "@radix-ui/primitive": "npm:1.1.1" + "@radix-ui/react-collection": "npm:1.1.1" + "@radix-ui/react-compose-refs": "npm:1.1.1" + "@radix-ui/react-context": "npm:1.1.1" + "@radix-ui/react-direction": "npm:1.1.0" + "@radix-ui/react-dismissable-layer": "npm:1.1.3" + "@radix-ui/react-focus-guards": "npm:1.1.1" + "@radix-ui/react-focus-scope": "npm:1.1.1" + "@radix-ui/react-id": "npm:1.1.0" + "@radix-ui/react-popper": "npm:1.2.1" + "@radix-ui/react-portal": "npm:1.1.3" + "@radix-ui/react-primitive": "npm:2.0.1" + "@radix-ui/react-slot": "npm:1.1.1" + "@radix-ui/react-use-callback-ref": "npm:1.1.0" + "@radix-ui/react-use-controllable-state": "npm:1.1.0" + "@radix-ui/react-use-layout-effect": "npm:1.1.0" + "@radix-ui/react-use-previous": "npm:1.1.0" + "@radix-ui/react-visually-hidden": "npm:1.1.1" + aria-hidden: "npm:^1.1.1" + react-remove-scroll: "npm:^2.6.1" + peerDependencies: + "@types/react": "*" + "@types/react-dom": "*" + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + peerDependenciesMeta: + "@types/react": + optional: true + "@types/react-dom": + optional: true + checksum: 10c0/c6b70b5340472384b95b94379474b8a68f81dda6b5774cbb153c2930158869620546126b90620f33efdb04d3cc3bde025571f0ddb8f3e79ac8ba6aa40d2b2cc8 + languageName: node + linkType: hard + "@radix-ui/react-slot@npm:1.1.1, @radix-ui/react-slot@npm:^1.1.1": version: 1.1.1 resolution: "@radix-ui/react-slot@npm:1.1.1" @@ -2018,6 +2064,19 @@ __metadata: languageName: node linkType: hard +"@radix-ui/react-use-previous@npm:1.1.0": + version: 1.1.0 + resolution: "@radix-ui/react-use-previous@npm:1.1.0" + peerDependencies: + "@types/react": "*" + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + peerDependenciesMeta: + "@types/react": + optional: true + checksum: 10c0/9787d24790d4e330715127f2f4db56c4cbed9b0a47f97e11a68582c08a356a53c1ec41c7537382f6fb8d0db25de152770f17430e8eaf0fa59705be97760acbad + languageName: node + linkType: hard + "@radix-ui/react-use-rect@npm:1.1.0": version: 1.1.0 resolution: "@radix-ui/react-use-rect@npm:1.1.0" @@ -5109,6 +5168,7 @@ __metadata: "@radix-ui/react-accordion": "npm:^1.2.2" "@radix-ui/react-dialog": "npm:^1.1.4" "@radix-ui/react-popover": "npm:^1.1.4" + "@radix-ui/react-select": "npm:^2.1.4" "@radix-ui/react-slot": "npm:^1.1.1" "@radix-ui/react-tooltip": "npm:^1.1.6" "@solana/spl-token": "npm:^0.4.9" From 6444b42a2aaa599cf1de91fa3d4dc20c947b2ee5 Mon Sep 17 00:00:00 2001 From: NikiTaysRD Date: Fri, 17 Jan 2025 18:19:07 +0200 Subject: [PATCH 2/4] feat: add currencies --- public/icons/currencies/usdcMint.svg | 12 +++++++ public/icons/currencies/usdtMint.svg | 11 +++++++ public/icons/currencies/wSolMint.svg | 20 +++++++++++ .../common/CurrencySelect/index.tsx | 33 +++++++++++-------- src/components/pages/game/game.tsx | 17 ++++++---- src/constants/addresses.ts | 7 +++- src/env.ts | 3 -- .../contracts/write/use-make-prediction.ts | 4 +-- src/hooks/contracts/write/use-send.ts | 3 +- 9 files changed, 82 insertions(+), 28 deletions(-) create mode 100644 public/icons/currencies/usdcMint.svg create mode 100644 public/icons/currencies/usdtMint.svg create mode 100644 public/icons/currencies/wSolMint.svg diff --git a/public/icons/currencies/usdcMint.svg b/public/icons/currencies/usdcMint.svg new file mode 100644 index 0000000..10cdb67 --- /dev/null +++ b/public/icons/currencies/usdcMint.svg @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/public/icons/currencies/usdtMint.svg b/public/icons/currencies/usdtMint.svg new file mode 100644 index 0000000..328392a --- /dev/null +++ b/public/icons/currencies/usdtMint.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/public/icons/currencies/wSolMint.svg b/public/icons/currencies/wSolMint.svg new file mode 100644 index 0000000..919c2bc --- /dev/null +++ b/public/icons/currencies/wSolMint.svg @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/components/common/CurrencySelect/index.tsx b/src/components/common/CurrencySelect/index.tsx index 69f983a..b36ed45 100644 --- a/src/components/common/CurrencySelect/index.tsx +++ b/src/components/common/CurrencySelect/index.tsx @@ -1,21 +1,28 @@ -import Solana from '@/components/common/Svg/Solana.tsx'; import { Select, SelectTrigger, SelectItem, SelectValue, SelectContent } from '@/components/ui/select.tsx'; +import { currencies, TCurrencies } from '@/constants/addresses.ts'; -export const CurrencySelect = () => { +interface ICurrencySelect { + value: string; + onValueChange: (value: TCurrencies) => void; +} + +export const CurrencySelect = ({ value, onValueChange }: ICurrencySelect) => { return ( - + - - -
- -
0.003
-
-
- Dark - System + + {Object.values(currencies).map((e, index) => { + return ( + +
+ currecy +
{e.defaultPrice}
+
+
+ ); + })}
); diff --git a/src/components/pages/game/game.tsx b/src/components/pages/game/game.tsx index f4a9f70..da27e43 100644 --- a/src/components/pages/game/game.tsx +++ b/src/components/pages/game/game.tsx @@ -7,12 +7,12 @@ import { z } from 'zod'; import { BaseTooltip } from '@/components/common/BaseTooltip'; import { CurrencySelect } from '@/components/common/CurrencySelect'; -import Solana from '@/components/common/Svg/Solana.tsx'; import { Button } from '@/components/ui/button.tsx'; +import { currencies, TCurrencies } from '@/constants/addresses.ts'; import useStatus from '@/hooks/api/use-status'; import useMakePrediction from '@/hooks/contracts/write/use-make-prediction'; import useSend from '@/hooks/contracts/write/use-send.ts'; -import { cn } from '@/lib/utils'; +import { cn, showTxToast } from '@/lib/utils'; import { useWalletModalStore } from '@/store/wallet-modal.tsx'; const TarotRequestSchema = z.object({ @@ -56,6 +56,7 @@ export const GameSection = () => { const [showTip, setShowTip] = useState(false); const [isRetry, setRetry] = useState(false); const [dontReload, setDontReload] = useState(false); + const [currencyName, setCurrencyName] = useState(Object.keys(currencies)[0] as TCurrencies); const { register, @@ -69,7 +70,7 @@ export const GameSection = () => { const onSubmit: SubmitHandler = async (data, e) => { e?.preventDefault(); - await transfer({ question: data.question.trim(), tokenName: 'usdcMint' }); + await transfer({ question: data.question.trim(), tokenName: currencyName }); }; const handleTip = async () => { @@ -83,7 +84,9 @@ export const GameSection = () => { return; } - await transferCurrency({ amount: selectedTip, tokenName: 'usdcMint' }); + await showTxToast('Sending Tip to the Oracle', async () => { + await transferCurrency({ amount: selectedTip, tokenName: currencyName }); + }); }; useEffect(() => { @@ -213,7 +216,7 @@ export const GameSection = () => {
- + {publicKey ? (
- {true && ( + {showTip && (
From 451a062fb9832ce6e93fcb8feab50a51764e4b1e Mon Sep 17 00:00:00 2001 From: NikiTaysRD Date: Fri, 17 Jan 2025 18:25:29 +0200 Subject: [PATCH 4/4] feat: add currencies --- src/components/pages/game/game.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/pages/game/game.tsx b/src/components/pages/game/game.tsx index fd47aa1..bbb914b 100644 --- a/src/components/pages/game/game.tsx +++ b/src/components/pages/game/game.tsx @@ -84,7 +84,7 @@ export const GameSection = () => { return; } - await showTxToast('Sending Tip to the Oracle', async () => { + await showTxToast('Tipping the Oracle', async () => { await transferCurrency({ amount: selectedTip, tokenName: currencyName }); }); };