Skip to content

Commit

Permalink
feat: add currencies
Browse files Browse the repository at this point in the history
  • Loading branch information
NikiTays committed Jan 17, 2025
1 parent 7c859bc commit 6444b42
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 28 deletions.
12 changes: 12 additions & 0 deletions public/icons/currencies/usdcMint.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions public/icons/currencies/usdtMint.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions public/icons/currencies/wSolMint.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 20 additions & 13 deletions src/components/common/CurrencySelect/index.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<Select>
<SelectTrigger>
<Select value={value} onValueChange={onValueChange}>
<SelectTrigger className="font-poppins">
<SelectValue placeholder="Theme" />
</SelectTrigger>
<SelectContent>
<SelectItem value="light">
<div className="flex flex-row items-center gap-4">
<Solana />
<div>0.003</div>
</div>
</SelectItem>
<SelectItem value="dark">Dark</SelectItem>
<SelectItem value="system">System</SelectItem>
<SelectContent className="font-poppins">
{Object.values(currencies).map((e, index) => {
return (
<SelectItem key={index} value={Object.keys(currencies)[index]}>
<div className="flex flex-row items-center gap-4">
<img src={`/icons/currencies/${Object.keys(currencies)[index]}.svg`} alt="currecy" />
<div>{e.defaultPrice}</div>
</div>
</SelectItem>
);
})}
</SelectContent>
</Select>
);
Expand Down
17 changes: 10 additions & 7 deletions src/components/pages/game/game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -56,6 +56,7 @@ export const GameSection = () => {
const [showTip, setShowTip] = useState<boolean>(false);
const [isRetry, setRetry] = useState(false);
const [dontReload, setDontReload] = useState(false);
const [currencyName, setCurrencyName] = useState<TCurrencies>(Object.keys(currencies)[0] as TCurrencies);

const {
register,
Expand All @@ -69,7 +70,7 @@ export const GameSection = () => {

const onSubmit: SubmitHandler<TarotRequestSchemaType> = async (data, e) => {
e?.preventDefault();
await transfer({ question: data.question.trim(), tokenName: 'usdcMint' });
await transfer({ question: data.question.trim(), tokenName: currencyName });
};

const handleTip = async () => {
Expand All @@ -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(() => {
Expand Down Expand Up @@ -213,7 +216,7 @@ export const GameSection = () => {
</div>

<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 sm:gap-10">
<CurrencySelect />
<CurrencySelect onValueChange={setCurrencyName} value={currencyName} />
{publicKey ? (
<BaseTooltip content={status?.isShutDown ? 'Oracle is taking a brake' : ''}>
<Button
Expand Down Expand Up @@ -253,10 +256,10 @@ export const GameSection = () => {
<div className="grid grid-rows-[auto_auto] gap-5 lg:grid-cols-2 lg:gap-10">
<div className="grid grid-cols-2 gap-[20px] md:grid-cols-5">
<div className="flex w-full items-center justify-center rounded-[8px] border border-[#3A3939] bg-[#D0C7A3] p-[14px] text-[20px] max-md:col-span-2">
<Solana />
<img src={`/icons/currencies/${currencyName}.svg`} alt="currecy" />
</div>

{[0.002, 0.004, 0.02, 0.5].map((tip) => (
{currencies[currencyName].tips.map((tip) => (
<Button
size="responsive"
variant="outline"
Expand Down
7 changes: 6 additions & 1 deletion src/constants/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@ export const currencies = {
wSolMint: {
address: wSolMint,
decimals: 9,
tips: [],
tips: [0.002, 0.004, 0.02, 0.5],
defaultPrice: 0.003,
},
usdcMint: {
address: usdcMint,
decimals: 6,
tips: [0.5, 1, 5, 10],
defaultPrice: 0.4,
},
usdtMint: {
address: usdtMint,
decimals: 6,
tips: [0.5, 1, 5, 10],
defaultPrice: 0.4,
},
};

Expand Down
3 changes: 0 additions & 3 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ export const env = createEnv({
VITE_API_URL: z.string().optional(),
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'),
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/contracts/write/use-make-prediction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const useMakePrediction = () => {

notify();

const txHash = await sendCurrency({ amount: 0.4, tokenName });
const txHash = await sendCurrency({ amount: currencies[tokenName].defaultPrice, tokenName });

if (!txHash) {
return;
Expand All @@ -51,7 +51,7 @@ const useMakePrediction = () => {
tarots,
hash: txHash,
question,
address: currencies.usdcMint.address.toString(),
address: currencies[tokenName].address.toString(),
});

if (toastId) {
Expand Down
3 changes: 1 addition & 2 deletions src/hooks/contracts/write/use-send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ const useSend = () => {
}

if (tokenName === 'wSolMint') {
await sendSol(amount);
return;
return await sendSol(amount);
}

const { address: mint, decimals } = currencies[tokenName];
Expand Down

0 comments on commit 6444b42

Please sign in to comment.