Skip to content

Commit

Permalink
Merge branch 'main' of github.com:simon0820s/HackaETH
Browse files Browse the repository at this point in the history
  • Loading branch information
Cocodrilette committed Dec 3, 2023
2 parents c37eb18 + 0819e78 commit f83eef6
Show file tree
Hide file tree
Showing 13 changed files with 555 additions and 10 deletions.
1 change: 1 addition & 0 deletions kiwi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-tabs": "^1.0.4",
"@radix-ui/react-toast": "^1.1.5",
"@web3modal/wagmi": "^3.4.0",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
Expand Down
8 changes: 5 additions & 3 deletions kiwi/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Inter } from 'next/font/google'
import './globals.css'
import { Providers } from './providers'
import { Nav } from '@/components/Navbar'

import { Toaster } from '@/components/ui/toaster'

const inter = Inter({ subsets: ['latin'] })

Expand All @@ -21,8 +21,10 @@ export default function RootLayout ({
<html lang='en'>
<body className={inter.className}>
<Providers>
<Nav/>
{children}</Providers>
<Nav />
{children}
<Toaster />
</Providers>
</body>
</html>
)
Expand Down
6 changes: 4 additions & 2 deletions kiwi/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function Home () {
<motion.path
d='M6.278027057647705,390.134521484375C34.3497757434845,375.4260025024414,269.86546902656556,265.20179748535156,286.9955139160156,243.04933166503906C304.1255588054657,220.89686584472656,193.5426010131836,165.56053619384767,177.57847595214844,168.60986328125C161.61435089111328,171.65919036865233,114.88789520263671,255.15695190429688,127.35426330566406,273.5426025390625C139.8206314086914,291.9282531738281,275.78475799560545,352.28699645996096,302.2421569824219,352.46636962890625C328.6995559692383,352.64574279785154,379.0134552001953,300.44844207763674,391.9282531738281,275.3363342285156C404.8430511474609,250.22422637939454,418.11659240722656,122.86995582580566,431.39013671875,101.34529113769531C444.66368103027344,79.82062644958496,508.8789428710937,55.156951141357425,524.6636962890625,60.08968734741211C540.4484497070313,65.0224235534668,575.2466430664062,131.7488872528076,589.2376708984375,150.6726531982422C603.2286987304688,169.59641914367677,644.573974609375,226.1883346557617,664.573974609375,249.3273468017578C684.573974609375,272.4663589477539,776.7713012695312,368.7892318725586,789.2376708984375,382.0627746582031'
fill='none'
strokeWidth='6'
strokeWidth='3'
stroke='url("#SvgjsLinearGradient1001")'
strokeLinecap='round'
strokeDasharray='450 100'
Expand Down Expand Up @@ -58,7 +58,9 @@ export default function Home () {
decentralizado de toda america latina
</p>
</div>
<Button className='landing__container--button px-10 font-bold text-xl'>Empieza</Button>
<Link href='/user' className='landing__container--button'>
<Button className='px-10 font-bold text-xl'>Empieza</Button>
</Link>
</div>
</main>
)
Expand Down
75 changes: 72 additions & 3 deletions kiwi/src/components/FundLoan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,32 @@ import {
} from '@/components/ui/card'
import { useForm } from 'react-hook-form'
import { Input } from './ui/input'
import { useErc20, useFund } from '@/hooks'
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger
} from './ui/dialog'
import { lendingManagerAddress } from '@/constants'

function FundLoan () {
const fundForm = useForm()
const form = useForm()

function onFundSubmit (values) {
console.log(values)
const { writeAsync: approve } = useErc20()

async function onSubmit (values) {
await approve({
args: [lendingManagerAddress, values.value]
})
}

const { writeAsync: fund, write: isFundAvailable } = useFund()

function onFundSubmit (values) {}
const loanForm = useForm()

function onLoanSubmit (values) {
Expand Down Expand Up @@ -93,7 +112,57 @@ function FundLoan () {
</FormItem>
)}
/>
<Button type='submit'>Solicitar prestamo</Button>

{isFundAvailable ? (
<Button type='submit'>Solicitar prestamo</Button>
) : (
<Dialog>
<DialogTrigger className='cursor-pointer' asChild>
<Button type='button'>Solicitar prestamo</Button>
</DialogTrigger>
<DialogContent className='sm:max-w-[425px]'>
<DialogHeader>
<DialogTitle>Preaprueba la transacción</DialogTitle>
<DialogDescription>
Para poder realizar la transacción debes tener
preaprobado un monto.
</DialogDescription>
</DialogHeader>
<Form {...form}>
<form
onSubmit={form.handleSubmit(onSubmit)}
className='space-y-8'
>
<FormField
control={form.control}
name='value'
rules={{
required: 'Este campo es requerido',
min: {
value: 0,
message: 'El monto debe ser mayor a: 0'
}
}}
render={({ field }) => (
<FormItem>
<FormLabel>Valor</FormLabel>
<FormControl>
<Input
type='number'
placeholder='0'
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<Button type='submit'>Aprobar monto</Button>
</form>
</Form>
</DialogContent>
</Dialog>
)}
</form>
</Form>
</CardContent>
Expand Down
127 changes: 127 additions & 0 deletions kiwi/src/components/ui/toast.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import * as React from "react"
import * as ToastPrimitives from "@radix-ui/react-toast"
import { cva, type VariantProps } from "class-variance-authority"
import { X } from "lucide-react"

import { cn } from "@/lib/utils"

const ToastProvider = ToastPrimitives.Provider

const ToastViewport = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Viewport>,
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Viewport>
>(({ className, ...props }, ref) => (
<ToastPrimitives.Viewport
ref={ref}
className={cn(
"fixed top-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-[420px]",
className
)}
{...props}
/>
))
ToastViewport.displayName = ToastPrimitives.Viewport.displayName

const toastVariants = cva(
"group pointer-events-auto relative flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full",
{
variants: {
variant: {
default: "border bg-background text-foreground",
destructive:
"destructive group border-destructive bg-destructive text-destructive-foreground",
},
},
defaultVariants: {
variant: "default",
},
}
)

const Toast = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Root>,
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> &
VariantProps<typeof toastVariants>
>(({ className, variant, ...props }, ref) => {
return (
<ToastPrimitives.Root
ref={ref}
className={cn(toastVariants({ variant }), className)}
{...props}
/>
)
})
Toast.displayName = ToastPrimitives.Root.displayName

const ToastAction = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Action>,
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Action>
>(({ className, ...props }, ref) => (
<ToastPrimitives.Action
ref={ref}
className={cn(
"inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium ring-offset-background transition-colors hover:bg-secondary focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive",
className
)}
{...props}
/>
))
ToastAction.displayName = ToastPrimitives.Action.displayName

const ToastClose = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Close>,
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Close>
>(({ className, ...props }, ref) => (
<ToastPrimitives.Close
ref={ref}
className={cn(
"absolute right-2 top-2 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-2 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600",
className
)}
toast-close=""
{...props}
>
<X className="h-4 w-4" />
</ToastPrimitives.Close>
))
ToastClose.displayName = ToastPrimitives.Close.displayName

const ToastTitle = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Title>,
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Title>
>(({ className, ...props }, ref) => (
<ToastPrimitives.Title
ref={ref}
className={cn("text-sm font-semibold", className)}
{...props}
/>
))
ToastTitle.displayName = ToastPrimitives.Title.displayName

const ToastDescription = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Description>,
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Description>
>(({ className, ...props }, ref) => (
<ToastPrimitives.Description
ref={ref}
className={cn("text-sm opacity-90", className)}
{...props}
/>
))
ToastDescription.displayName = ToastPrimitives.Description.displayName

type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>

type ToastActionElement = React.ReactElement<typeof ToastAction>

export {
type ToastProps,
type ToastActionElement,
ToastProvider,
ToastViewport,
Toast,
ToastTitle,
ToastDescription,
ToastClose,
ToastAction,
}
35 changes: 35 additions & 0 deletions kiwi/src/components/ui/toaster.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"use client"

import {
Toast,
ToastClose,
ToastDescription,
ToastProvider,
ToastTitle,
ToastViewport,
} from "@/components/ui/toast"
import { useToast } from "@/components/ui/use-toast"

export function Toaster() {
const { toasts } = useToast()

return (
<ToastProvider>
{toasts.map(function ({ id, title, description, action, ...props }) {
return (
<Toast key={id} {...props}>
<div className="grid gap-1">
{title && <ToastTitle>{title}</ToastTitle>}
{description && (
<ToastDescription>{description}</ToastDescription>
)}
</div>
{action}
<ToastClose />
</Toast>
)
})}
<ToastViewport />
</ToastProvider>
)
}
Loading

0 comments on commit f83eef6

Please sign in to comment.