Skip to content

Commit

Permalink
fix: number input decimal error
Browse files Browse the repository at this point in the history
  • Loading branch information
kvhnuke committed May 6, 2024
1 parent f3a89c4 commit 84ae8b9
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 358 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ const inputAmount = (inputAmount: string) => {
}
const inputAmountBn = new BigNumber(inputAmount);
isMaxSelected.value = false;
amount.value = inputAmountBn.lt(0) ? "0" : inputAmountBn.toFixed();
amount.value = inputAmountBn.lt(0) ? "0" : inputAmount;
};
const toggleSelectFee = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
<input
ref="inputRef"
v-model="amount"
type="number"
type="text"
placeholder="0"
:style="{ color: !hasEnoughBalance ? 'red' : 'black' }"
@keypress="onlyNumber"
@focus="changeFocus"
@blur="changeFocus"
/>
Expand All @@ -31,7 +32,7 @@ import SwitchArrowIcon from "@action/icons/send/switch-arrow-icon.vue";
import BigNumber from "bignumber.js";
const emit = defineEmits<{
(e: "update:inputAmount", address: string): void;
(e: "update:inputAmount", value: string): void;
(e: "update:inputSetMax"): void;
}>();
Expand Down Expand Up @@ -64,10 +65,18 @@ const fiatEquivalent = computed(() => {
const amount = computed({
get: () => props.amount,
set: (value) => {
emit("update:inputAmount", value.toString());
let fValue = value.toString();
if (fValue === ".") fValue = "0.";
emit("update:inputAmount", fValue);
},
});
const onlyNumber = ($event: KeyboardEvent) => {
const keyCode = $event.keyCode ? $event.keyCode : $event.which;
if ((keyCode < 48 || keyCode > 57) && keyCode !== 46) {
$event.preventDefault();
}
};
const changeFocus = () => {
isFocus.value = !isFocus.value;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ const inputAmount = (inputAmount: string) => {
}
const inputAmountBn = new BigNumber(inputAmount);
isMaxSelected.value = false;
amount.value = inputAmountBn.lt(0) ? "0" : inputAmountBn.toFixed();
amount.value = inputAmountBn.lt(0) ? "0" : inputAmount;
if (isInputsValid.value) {
updateTransactionFees(Tx.value);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@

<send-input-amount
:amount="amount"
:show-max="true"
:fiat-value="selectedAsset.price"
:is-valid="fieldsValidation.amount"
:has-enough-balance="fieldsValidation.amount"
@update:input-amount="inputAmount"
@update:input-set-max="setSendMax"
/>
Expand Down Expand Up @@ -103,7 +104,7 @@ import SendContactsList from "./components/send-contacts-list.vue";
import SendFromContactsList from "./components/send-from-contacts-list.vue";
import SendTokenSelect from "./components/send-token-select.vue";
import AssetsSelectList from "@action/views/assets-select-list/index.vue";
import SendInputAmount from "./components/send-input-amount.vue";
import SendInputAmount from "@/providers/common/ui/send-transaction/send-input-amount.vue";
import SendFeeSelect from "./components/send-fee-select.vue";
import SendAlert from "./components/send-alert.vue";
import BaseButton from "@action/components/base-button/index.vue";
Expand Down Expand Up @@ -399,9 +400,13 @@ const selectToken = (token: KDAToken | Partial<KDAToken>) => {
isOpenSelectToken.value = false;
};
const inputAmount = (number: string | undefined) => {
const inputAmount = (inputAmount: string) => {
if (inputAmount === "") {
inputAmount = "0";
}
const inputAmountBn = new BigNumber(inputAmount);
sendMax.value = false;
amount.value = number ? (parseFloat(number) < 0 ? "" : number) : number;
amount.value = inputAmountBn.lt(0) ? "0" : inputAmount;
};
const sendButtonTitle = computed(() => {
Expand Down
Loading

1 comment on commit 84ae8b9

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.