-
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.
Merge pull request #1 from RedDuck-Software/feat/game-page
feat: random function & min layout
- Loading branch information
Showing
23 changed files
with
754 additions
and
168 deletions.
There are no files selected for viewing
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const Loader = () => { | ||
return ( | ||
<div> | ||
<h1>Loading...</h1> | ||
</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
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,95 @@ | ||
import { Slot } from '@radix-ui/react-slot'; | ||
import { cva, type VariantProps } from 'class-variance-authority'; | ||
import * as React from 'react'; | ||
import { ReactNode } from 'react'; | ||
|
||
import { cn } from '@/lib/utils'; | ||
|
||
const inputVariants = cva( | ||
'w-full bg-transparent py-2 md:py-3 pl-3 md:pl-4 pr-1 text-xs font-[600] leading-[30px] text-[#FFFFFF] sm:text-[20px] focus:outline-none', | ||
{ | ||
variants: { | ||
variant: { | ||
default: '', | ||
}, | ||
sizes: { | ||
default: '', | ||
large: '', | ||
}, | ||
}, | ||
defaultVariants: { | ||
sizes: 'default', | ||
variant: 'default', | ||
}, | ||
}, | ||
); | ||
|
||
export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement>, VariantProps<typeof inputVariants> { | ||
asChild?: boolean; | ||
error?: ReactNode; | ||
label?: ReactNode; | ||
endAdornment?: ReactNode; | ||
startAdornment?: ReactNode; | ||
wrapperClassName?: string; | ||
} | ||
|
||
const Input = React.forwardRef<HTMLInputElement, InputProps>( | ||
( | ||
{ | ||
label, | ||
wrapperClassName, | ||
endAdornment, | ||
startAdornment, | ||
error, | ||
className, | ||
variant, | ||
sizes, | ||
asChild = false, | ||
...props | ||
}, | ||
ref, | ||
) => { | ||
const Comp = asChild ? Slot : 'input'; | ||
|
||
if (props.type === 'checkbox') { | ||
return ( | ||
<div className="flex flex-col"> | ||
<div className="flex flex-row items-center gap-2"> | ||
<Comp ref={ref} className={cn(className)} id={props.name} {...props} /> | ||
<label htmlFor={props.name}>{label}</label> | ||
</div> | ||
<div className="text-red-400">{error}</div> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div className="flex flex-col gap-2"> | ||
{label} | ||
<div | ||
className={cn( | ||
'grid grid-cols-[auto_1fr_auto] items-center rounded-[16px] bg-[#FFFFFF1A] pr-2 text-white md:pr-3', | ||
wrapperClassName, | ||
error ? 'border-red border' : '', | ||
)} | ||
> | ||
{startAdornment ?? <div />} | ||
<Comp | ||
className={cn( | ||
inputVariants({ variant, className, sizes }), | ||
props.disabled ? 'cursor-not-allowed text-white/50' : 'cursor-pointer placeholder:text-white', | ||
)} | ||
ref={ref} | ||
{...props} | ||
/> | ||
{endAdornment ?? <div />} | ||
</div> | ||
{error && <div className="text-red text-[15px]">{error}</div>} | ||
</div> | ||
); | ||
}, | ||
); | ||
|
||
Input.displayName = 'Input'; | ||
|
||
export { Input }; |
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,33 @@ | ||
import { useWallet } from '@solana/wallet-adapter-react'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
|
||
import { post } from './utils'; | ||
|
||
import { authClient } from '@/lib/fetcher'; | ||
import { TarotCard } from '@/types/tarot'; | ||
|
||
const useSubmitTarotCards = () => { | ||
const { publicKey } = useWallet(); | ||
|
||
return useMutation({ | ||
async mutationFn({ tarots, hash, question }: { tarots: TarotCard[]; hash: string; question: string }) { | ||
if (!publicKey) { | ||
return; | ||
} | ||
|
||
const client = authClient(); | ||
|
||
return await post<{ response: string }>(client, `tarot/generate-response`, { | ||
tarots, | ||
hash, | ||
question, | ||
}); | ||
}, | ||
|
||
onError(error) { | ||
console.trace(error); | ||
}, | ||
}); | ||
}; | ||
|
||
export default useSubmitTarotCards; |
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,52 @@ | ||
import { Fetcher } from '@/lib/fetcher'; | ||
|
||
export const get = async <T>(fetcher: Fetcher, method: string) => { | ||
const response = await fetcher.get<T>(method); | ||
if (!(response.status >= 200 && response.status < 300)) { | ||
throw new Error(response.statusText); | ||
} | ||
|
||
return response.data; | ||
}; | ||
|
||
export const put = async <T>(client: Fetcher, method: string, data: Record<string, unknown>) => { | ||
const response = await client.put<T>(method, { data }); | ||
if (!(response.status >= 200 && response.status < 300)) { | ||
throw new Error(response.statusText); | ||
} | ||
|
||
return response.data; | ||
}; | ||
|
||
export const post = async <T>( | ||
client: Fetcher, | ||
method: string, | ||
data?: Record<string, unknown>, | ||
signal?: AbortSignal, | ||
) => { | ||
const response = await client.post<T>(method, data, signal); | ||
if (!(response.status >= 200 && response.status < 300)) { | ||
throw new Error(response.error ?? response.statusText); | ||
} | ||
|
||
console.log('response', response); | ||
return response.data; | ||
}; | ||
|
||
export const patch = async <T>(client: Fetcher, method: string, data: Record<string, unknown>) => { | ||
const response = await client.patch<T>(method, data); | ||
if (!(response.status >= 200 && response.status < 300)) { | ||
throw new Error(response.statusText); | ||
} | ||
|
||
return response.data; | ||
}; | ||
|
||
export const deleteOperation = async <T>(client: Fetcher, method: string) => { | ||
const response = await client.delete<T>(method); | ||
if (!(response.status >= 200 && response.status < 300)) { | ||
throw new Error(response.statusText); | ||
} | ||
|
||
return response.data; | ||
}; |
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,50 @@ | ||
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 { env } from '@/env'; | ||
import useSubmitTarotCards from '@/hooks/api/use-submit-cards'; | ||
import { network } from '@/lib/solana'; | ||
import { sendAndConfirmTransaction } from '@/lib/solana/utils'; | ||
import { getRandomTarotCards, showTxToast } from '@/lib/utils'; | ||
|
||
const useMakePrediction = () => { | ||
const { publicKey, sendTransaction } = useWallet(); | ||
const { mutateAsync: submitCards, data: predictionAnswer } = useSubmitTarotCards(); | ||
|
||
return useMutation({ | ||
async mutationFn(question: string) { | ||
if (!publicKey) { | ||
return; | ||
} | ||
|
||
await showTxToast('Making prediction', async () => { | ||
const rawTx = new Transaction(); | ||
|
||
rawTx.add( | ||
SystemProgram.transfer({ | ||
fromPubkey: publicKey, | ||
toPubkey: OwnerAddress[network], | ||
lamports: Number(env.VITE_DEPOSIT_AMOUNT_SOL) * 1e9, | ||
}), | ||
); | ||
|
||
const txHash = await sendAndConfirmTransaction(publicKey, rawTx, sendTransaction); | ||
console.log('txHash', txHash); | ||
|
||
const tarots = getRandomTarotCards(txHash + publicKey.toBase58()); | ||
|
||
await submitCards({ tarots, hash: txHash, question }); | ||
}); | ||
|
||
return predictionAnswer; | ||
}, | ||
|
||
onError(error) { | ||
console.trace(error); | ||
}, | ||
}); | ||
}; | ||
|
||
export default useMakePrediction; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.