Skip to content

Commit

Permalink
fix: create loan
Browse files Browse the repository at this point in the history
  • Loading branch information
rsamudragawang committed Aug 22, 2024
1 parent 0f0acc6 commit e7eceb3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
11 changes: 11 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
dfx start --clean --background

cd scripts
./deploy_ledger_icp.sh
cd ..
dfx deploy

sh upload-model.sh


npm start
21 changes: 14 additions & 7 deletions src/frontend/src/pages/CreateLoanView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,14 @@
playsinline></video>
<canvas id="canvas" ref="canvasRef" :class="{ hidden: !state.isCanvasVisible }"
class="w-full rounded-lg"></canvas>
<Button @click="store" label="Take Photo" fluid class="mt-[40px]" severity="contrast" />
<Button @click="recognize" label="Take Photo" fluid class="mt-[40px]" severity="contrast" />
<Button @click="restart" label="Retake Photo" fluid class="mt-[40px]" severity="contrast" />
</div>
{{ state.message }}
</div>
</div>
<Button @click="create" label="Create Loan" fluid class="mt-[40px]" severity="contrast" />
<Button @click="create" :disabled="disableButton" label="Create Loan" fluid class="mt-[40px]" severity="contrast" />
{{ authStore.user }}
</div>
</div>
</div>
Expand All @@ -151,8 +152,10 @@ import Button from 'primevue/button';
import { useRouter } from 'vue-router';
import { user } from 'declarations/user/index';
import { loan } from 'declarations/loan/index';
import { useAuthStore } from '../stores/auth';
import { Principal } from '@dfinity/principal';
const router = useRouter();
const authStore = useAuthStore();
const name = ref('');
const description = ref('');
Expand All @@ -164,6 +167,7 @@ const amount = ref(0);
const commit = ref(null);
const photo = ref(null)
const disableButton = ref(false)
const categories = ref([
{ name: 'F&B', code: 'F&B' },
Expand Down Expand Up @@ -274,6 +278,7 @@ const onChangeUploadPhoto = async (e) => {
}
photo.value = await toDataURL(file)
console.log(photo.value)
store()
}
const recognize = async (event) => {
Expand All @@ -285,7 +290,7 @@ const recognize = async (event) => {
try {
const [blob, scaling] = await captureImage();
let result = await user.detect(new Uint8Array(blob));
console.log(result,"Result blob")
if (!result.Ok) throw new Error(result.Err.message);
const face = await render(scaling, result.Ok);
Expand All @@ -297,17 +302,19 @@ const recognize = async (event) => {
const label = sanitize(result.Ok.label);
const score = Math.round(result.Ok.score * 100) / 100;
state.message = `${label}, difference=${score}`;
console.log(label,score)
} catch (err) {
console.error(`An error occurred: ${err}`);
state.message = err.toString();
disableButton.value = true
}
state.isLoaderVisible = false;
state.isRestartVisible = true;
};
const store = async (event) => {
event.preventDefault();
// event.preventDefault();
state.isButtonsVisible = false;
state.isLoaderVisible = true;
state.message = 'Detecting face..';
Expand All @@ -319,7 +326,7 @@ const store = async (event) => {
if (!result.Ok) throw new Error(result.Err.message);
const face = await render(scaling, result.Ok);
const label = prompt('Enter name of the person');
const label = authStore.user.name
console.log(face, "Face")
if (!label) throw new Error('Cannot add without a name');
Expand Down Expand Up @@ -453,7 +460,7 @@ const create = async () => {
const diffDaysWait = Math.ceil(waitingTime / (1000 * 60 * 60 * 24));
console.log(diffDaysWait)
console.log(name.value, description.value, category.value.code, parseFloat(amount.value), diffDays, diffDaysWait, parseFloat(interest.value.code))
loan.registerLoan(name.value, description.value, category.value.code, parseFloat(amount.value), diffDays, diffDaysWait, parseFloat(interest.value.code)).then((res) => {
loan.registerLoan(Principal.fromText(authStore.principalId) ,name.value, description.value, category.value.code, parseFloat(amount.value), diffDays, diffDaysWait, parseFloat(interest.value.code)).then((res) => {
console.log(res)
})
}
Expand Down

0 comments on commit e7eceb3

Please sign in to comment.