From be90ff746bdd7145e230e322c429b2340f2a7dd6 Mon Sep 17 00:00:00 2001 From: RcleydsonR Date: Wed, 18 Jan 2023 23:38:00 -0300 Subject: [PATCH] Refactor decimalCount method and add it on a file to be used in many components --- src/components/SearchComponent.vue | 11 +---------- src/components/SellerSteps/SellerSearchComponent.vue | 11 +---------- src/components/SellerSteps/WantSellComponent.vue | 11 +---------- src/utils/decimalCount.ts | 7 +++++++ 4 files changed, 10 insertions(+), 30 deletions(-) create mode 100644 src/utils/decimalCount.ts diff --git a/src/components/SearchComponent.vue b/src/components/SearchComponent.vue index 5eaed7e..b49813a 100644 --- a/src/components/SearchComponent.vue +++ b/src/components/SearchComponent.vue @@ -8,6 +8,7 @@ import { connectProvider } from "@/blockchain/provider"; import { verifyNetworkLiquidity } from "@/utils/networkLiquidity"; import { NetworkEnum } from "@/model/NetworkEnum"; import type { ValidDeposit } from "@/model/ValidDeposit"; +import { decimalCount } from "@/utils/decimalCount"; // Store reference const etherStore = useEtherStore(); @@ -62,16 +63,6 @@ const handleInputEvent = (event: any): void => { verifyLiquidity(); }; -// Enable button methods -// Check if has more than 2 decimal places -const decimalCount = (num: number): number => { - const numStr = String(num); - if (numStr.includes(".")) { - return numStr.split(".")[1].length; - } - return 0; -}; - // Verify if there is a valid deposit to buy const verifyLiquidity = (): void => { enableConfirmButton.value = false; diff --git a/src/components/SellerSteps/SellerSearchComponent.vue b/src/components/SellerSteps/SellerSearchComponent.vue index 6461f13..99faabc 100644 --- a/src/components/SellerSteps/SellerSearchComponent.vue +++ b/src/components/SellerSteps/SellerSearchComponent.vue @@ -2,6 +2,7 @@ import { ref } from "vue"; import CustomButton from "../../components/CustomButton.vue"; import { debounce } from "@/utils/debounce"; +import { decimalCount } from "@/utils/decimalCount"; // Reactive state const tokenValue = ref(0); @@ -25,16 +26,6 @@ const handleInputEvent = (event: any): void => { } validDecimals.value = true; }; - -// Enable button methods -// Check if has more than 2 decimal places -const decimalCount = (num: number): number => { - const numStr = String(num); - if (numStr.includes(".")) { - return numStr.split(".")[1].length; - } - return 0; -};