Skip to content

Commit

Permalink
feat
Browse files Browse the repository at this point in the history
  • Loading branch information
Another-DevX committed Dec 3, 2023
1 parent f6942f2 commit f2c7dfe
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 54 deletions.
1 change: 1 addition & 0 deletions kiwi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@radix-ui/react-tabs": "^1.0.4",
"@radix-ui/react-toast": "^1.1.5",
"@web3modal/wagmi": "^3.4.0",
"axios": "^1.6.2",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"flowbite-react": "^0.7.0",
Expand Down
15 changes: 15 additions & 0 deletions kiwi/src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,18 @@
right: 10%;
}
}

input[type='number']::-webkit-inner-spin-button,
input[type='number']::-webkit-outer-spin-button {
-webkit-appearance: none;
margin: 0;
}

input[type='number'] {
-moz-appearance: textfield;
}

input[type='number']::-ms-clear,
input[type='number']::-ms-reveal {
display: none;
}
1 change: 1 addition & 0 deletions kiwi/src/app/user/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import React from 'react'

function Page () {
const isValidate = useUserValidated()
if(!isValidate) redirect('/validation')

return (
<section className='p-10 pt-20 flex flex-col gap-5 justify-center items-center'>
Expand Down
37 changes: 16 additions & 21 deletions kiwi/src/app/validation/page.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
"use client";
import React, { ChangeEvent, FormEvent, useState } from "react";
import { useUserValidated } from "@/hooks";
import { redirect } from "next/navigation";
import validate from "@/services/validate";
import { Redressed } from "next/font/google";
'use client'
import React, { ChangeEvent, FormEvent, useState } from 'react'
import { validate } from '@/services/validate'

function Page() {
const isValidate = useUserValidated();
const [image, setImage] = useState("");
if (!isValidate) redirect("/");
function Page () {
const [image, setImage] = useState('')

const handleImageChange = (event: ChangeEvent<HTMLInputElement>) => {
const selectedImage = event.target.files && event.target.files[0];
const selectedImage = event.target.files && event.target.files[0]

if (selectedImage) {
const reader = new FileReader()
Expand All @@ -23,25 +18,25 @@ function Page() {
}
reader.readAsDataURL(selectedImage)
}
}

};

const handleSubmit = (event: FormEvent<HTMLFormElement>) => {
event.preventDefault();
console.log(validate(image))
};
const handleSubmit = async (event: FormEvent<HTMLFormElement>) => {
event.preventDefault()
const response = await validate(image)
console.debug(response)
}

return (
<section>
<h1>Page</h1>
<p>Page content</p>

<form onSubmit={handleSubmit}>
<input type="file" accept="image/*" onChange={handleImageChange} />
<button type="submit">Send</button>
<input type='file' accept='image/*' onChange={handleImageChange} />
<button type='submit'>Send</button>
</form>
</section>
);
)
}

export default Page;
export default Page
23 changes: 14 additions & 9 deletions kiwi/src/components/FundLoan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from '@/components/ui/card'
import { useForm } from 'react-hook-form'
import { Input } from './ui/input'
import { useErc20, useErc20Approve, useFund } from '@/hooks'
import { useErc20Approve, useFund } from '@/hooks'
import {
Dialog,
DialogContent,
Expand All @@ -30,6 +30,7 @@ import {
} from './ui/dialog'
import { CeloCopAddress, lendingManagerAddress } from '@/constants'
import { parseEther } from 'viem'
import { useLend } from '@/hooks/useLend'

function FundLoan () {
const fundForm = useForm()
Expand All @@ -40,7 +41,7 @@ function FundLoan () {

async function onSubmit (values) {
console.debug(lendingManagerAddress, values.value)
console.debug(CeloCopAddress)
console.debug(CeloCopAddress)

await approve({
args: [lendingManagerAddress, parseEther(values.value)]
Expand All @@ -50,13 +51,16 @@ console.debug(CeloCopAddress)
const { writeAsync: fund, write: isFundAvailable } = useFund({
value: fundForm.watch('value')
})

const { writeAsync: loan } = useLend()
async function onFundSubmit () {
if (fund) await fund()
}

function onLoanSubmit (values) {
console.log(values)
async function onLoanSubmit (values) {
console.debug(values)
await loan({
args: [parseEther(values.value), values.months]
})
}

return (
Expand All @@ -75,13 +79,13 @@ console.debug(CeloCopAddress)
</CardDescription>
</CardHeader>
<CardContent className='space-y-2'>
<Form {...fundForm}>
<Form {...loanForm}>
<form
onSubmit={fundForm.handleSubmit(onLoanSubmit)}
onSubmit={loanForm.handleSubmit(onLoanSubmit)}
className='space-y-8'
>
<FormField
control={fundForm.control}
control={loanForm.control}
name='value'
rules={{
required: 'Este campo es requerido',
Expand All @@ -101,7 +105,7 @@ console.debug(CeloCopAddress)
)}
/>
<FormField
control={fundForm.control}
control={loanForm.control}
name='months'
rules={{
required: 'Este campo es requerido',
Expand All @@ -120,6 +124,7 @@ console.debug(CeloCopAddress)
</FormItem>
)}
/>
<Button type='submit'>Prestar</Button>
</form>
</Form>
</CardContent>
Expand Down
2 changes: 1 addition & 1 deletion kiwi/src/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Link from 'next/link'

function Nav () {
return (
<Navbar fluid className='bg-slate-400 bg-opacity-10 fixed w-full bg-transparent' rounded>
<Navbar fluid className='bg-slate-400 z-50 bg-opacity-10 fixed w-full bg-transparent' rounded>
<NavbarBrand as={Link} href='/'>
<span className='self-center kiwi text-white whitespace-nowrap text-xl font-semibold dark:text-white'>
Kiwi
Expand Down
2 changes: 1 addition & 1 deletion kiwi/src/hooks/useLend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function useLend () {
const lend = useContractWrite({
address: lendingManagerAddress,
abi: lendingManagerAbi,
functionName: 'feed',
functionName: 'lend',
onSuccess (tx: any) {
toast({
title: 'Prestamo realizado con exito',
Expand Down
4 changes: 2 additions & 2 deletions kiwi/src/hooks/useUserValidated.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import React, { useEffect, useState } from 'react'

function useUserValidated () {
const [isValidate, setIsValidate] = useState(true)
const [isValidate, setIsValidate] = useState(false)
useEffect(() => {
setIsValidate(true)
setIsValidate(false)
}, [])

return isValidate
Expand Down
37 changes: 18 additions & 19 deletions kiwi/src/services/validate.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
const URL = 'http://localhost:2809';
import axios from 'axios'

export default async function validate(img: string): Promise<any> {
try {
const response = await fetch(URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ "country": "CO", "image": img })
});

if (!response.ok) {
throw new Error('Error en la solicitud');
}
const URL = 'http://localhost:2809'

const jsonResponse = await response.json();
console.log(jsonResponse);
return jsonResponse;
async function validate (img: string) {
try {
const response = await axios.post(
URL,
JSON.stringify({ country: 'CO', image: img }),
{
headers: {
'Content-Type': 'application/json'
}
}
)
return response
} catch (error) {
console.error('Error:', error);
throw error;
console.error('Error:', error)
throw error
}
}

export { validate }
57 changes: 57 additions & 0 deletions kiwi/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2520,6 +2520,11 @@ asynciterator.prototype@^1.0.0:
dependencies:
has-symbols "^1.0.3"

asynckit@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==

atomic-sleep@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/atomic-sleep/-/atomic-sleep-1.0.0.tgz#eb85b77a601fc932cfe432c5acd364a9e2c9075b"
Expand Down Expand Up @@ -2554,6 +2559,15 @@ axe-core@=4.7.0:
resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-4.7.0.tgz#34ba5a48a8b564f67e103f0aa5768d76e15bbbbf"
integrity sha512-M0JtH+hlOL5pLQwHOLNYZaXuhqmvS8oExsqB1SBYgA4Dk7u/xx+YdGHXaK5pyUfed5mYXdlYiphWq3G8cRi5JQ==

axios@^1.6.2:
version "1.6.2"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.2.tgz#de67d42c755b571d3e698df1b6504cde9b0ee9f2"
integrity sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==
dependencies:
follow-redirects "^1.15.0"
form-data "^4.0.0"
proxy-from-env "^1.1.0"

axobject-query@^3.2.1:
version "3.2.1"
resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-3.2.1.tgz#39c378a6e3b06ca679f29138151e45b2b32da62a"
Expand Down Expand Up @@ -2898,6 +2912,13 @@ color@^4.2.3:
color-convert "^2.0.1"
color-string "^1.9.0"

combined-stream@^1.0.8:
version "1.0.8"
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==
dependencies:
delayed-stream "~1.0.0"

comma-separated-tokens@^2.0.0:
version "2.0.3"
resolved "https://registry.yarnpkg.com/comma-separated-tokens/-/comma-separated-tokens-2.0.3.tgz#4e89c9458acb61bc8fef19f4529973b2392839ee"
Expand Down Expand Up @@ -3178,6 +3199,11 @@ delay@^5.0.0:
resolved "https://registry.yarnpkg.com/delay/-/delay-5.0.0.tgz#137045ef1b96e5071060dd5be60bf9334436bd1d"
integrity sha512-ReEBKkIfe4ya47wlPYf/gu5ib6yUG0/Aez0JQZQz94kiWtRQvZIQbTiehsnwHvLSWJnQdhVeqYue7Id1dKr0qw==

delayed-stream@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==

denque@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/denque/-/denque-2.1.0.tgz#e93e1a6569fb5e66f16a3c2a2964617d349d6ab1"
Expand Down Expand Up @@ -4000,6 +4026,11 @@ flowbite@^2.0.0:
"@popperjs/core" "^2.9.3"
mini-svg-data-uri "^1.4.3"

follow-redirects@^1.15.0:
version "1.15.3"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.3.tgz#fe2f3ef2690afce7e82ed0b44db08165b207123a"
integrity sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==

for-each@^0.3.3:
version "0.3.3"
resolved "https://registry.yarnpkg.com/for-each/-/for-each-0.3.3.tgz#69b447e88a0a5d32c3e7084f3f1710034b21376e"
Expand All @@ -4012,6 +4043,15 @@ for-in@^1.0.2:
resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80"
integrity sha512-7EwmXrOjyL+ChxMhmG5lnW9MPt1aIeZEwKhQzoBUdTV0N3zuwWDZYVJatDvZ2OyzPUvdIAZDsCetk3coyMfcnQ==

form-data@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452"
integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==
dependencies:
asynckit "^0.4.0"
combined-stream "^1.0.8"
mime-types "^2.1.12"

format@^0.2.0:
version "0.2.2"
resolved "https://registry.yarnpkg.com/format/-/format-0.2.2.tgz#d6170107e9efdc4ed30c9dc39016df942b5cb58b"
Expand Down Expand Up @@ -6121,6 +6161,18 @@ micromatch@^4.0.4, micromatch@^4.0.5:
braces "^3.0.2"
picomatch "^2.3.1"

[email protected]:
version "1.52.0"
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70"
integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==

mime-types@^2.1.12:
version "2.1.35"
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.35.tgz#381a871b62a734450660ae3deee44813f70d959a"
integrity sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==
dependencies:
mime-db "1.52.0"

mime@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/mime/-/mime-3.0.0.tgz#b374550dca3a0c18443b0c950a6a58f1931cf7a7"
Expand Down Expand Up @@ -6805,6 +6857,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/proxy-compare/-/proxy-compare-2.5.1.tgz#17818e33d1653fbac8c2ec31406bce8a2966f600"
integrity sha512-oyfc0Tx87Cpwva5ZXezSp5V9vht1c7dZBhvuV/y3ctkgMVUmiAGDVeeB0dKhGSyT0v1ZTEQYpe/RXlBVBNuCLA==

proxy-from-env@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==

pump@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/pump/-/pump-3.0.0.tgz#b4a2116815bde2f4e1ea602354e8c75565107a64"
Expand Down
Binary file not shown.
4 changes: 3 additions & 1 deletion server/cc_validation/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from flask import Flask,request,jsonify
from flask import Flask,request
from flask_cors import CORS
import tensorflow as tf
import tensorflow_hub as hub
import cv2
Expand All @@ -9,6 +10,7 @@


app=Flask(__name__)
CORS(app)

CL_MODEL=tf.keras.models.load_model("validation_model.hdf5",custom_objects={'KerasLayer':hub.KerasLayer})
CO_MODEL=tf.keras.models.load_model("validation_model.hdf5",custom_objects={'KerasLayer':hub.KerasLayer})
Expand Down

0 comments on commit f2c7dfe

Please sign in to comment.