diff --git a/src/common/components/resource-credits/delegation.tsx b/src/common/components/resource-credits/delegation.tsx index 884d94a4794..dd531aada65 100644 --- a/src/common/components/resource-credits/delegation.tsx +++ b/src/common/components/resource-credits/delegation.tsx @@ -13,8 +13,14 @@ import { Button, Form, FormControl, InputGroup } from "react-bootstrap"; import { getRcOperationStats } from "../../api/hive"; export const ResourceCreditsDelegation = (props: any) => { - const { resourceCredit, activeUser, hideDelegation, toFromList, amountFromList, delegateeData } = - props; + const { + resourceCredit, + activeUser, + hideDelegation, + toFromList, + amountFromList, + delegateeData, + } = props; const [to, setTo] = useState(toFromList || ""); const [amount, setAmount] = useState(amountFromList || ""); @@ -38,16 +44,16 @@ export const ResourceCreditsDelegation = (props: any) => { const [convertedVal, setConvertedVal] = useState(null); useEffect(() => { - rcOperationsCost() - }, [amount]) + rcOperationsCost(); + }, [amount]); const convertToBillions = (input: string) => { const inputNumber = parseFloat(input); - let resultDivided: number; + let resultDivided: number; if (!isNaN(inputNumber)) { - resultDivided = inputNumber / 1e9; - console.log("resultDivided", resultDivided!.toFixed(2) + "B") + resultDivided = inputNumber / 1e9; + console.log("resultDivided", resultDivided!.toFixed(2) + "B"); } else { setConvertedValue("null"); } @@ -63,17 +69,18 @@ export const ResourceCreditsDelegation = (props: any) => { const amountChanged = (e: React.ChangeEvent): void => { const value = e.target.value; - console.log(Number(value)) + console.log(Number(value)); + + const sonvertedAmount = (parseFloat(value) * 1e9).toFixed(2); + setConvertedVal(sonvertedAmount); - const sonvertedAmount = (parseFloat(value) * 1e9).toFixed(2) - setConvertedVal(sonvertedAmount) - setAmount(Number(value)); - updateOnAmount(Number(value)) - console.log(amount) + updateOnAmount(Number(value)); + console.log(amount); if ( sonvertedAmount === "" || - (Number(sonvertedAmount) >= 5000000000 && Number(sonvertedAmount) < Number(resourceCredit)) || + (Number(sonvertedAmount) >= 5000000000 && + Number(sonvertedAmount) < Number(resourceCredit)) || sonvertedAmount === "0" ) { setAmountError(""); @@ -96,9 +103,9 @@ export const ResourceCreditsDelegation = (props: any) => { const signTransaction = () => { const { activeUser } = props; - console.log(activeUser) + console.log(activeUser); const username = activeUser?.username!; - const max_rc = `${parseFloat(amount) * 1e9}` ; + const max_rc = `${parseFloat(amount) * 1e9}`; delegateRC(username, to, max_rc) .then((res: any) => { return res; @@ -117,13 +124,21 @@ export const ResourceCreditsDelegation = (props: any) => { const commentCost = operationCosts.comment_operation.avg_cost; const transferCost = operationCosts.transfer_operation.avg_cost; const voteCost = operationCosts.vote_operation.avg_cost; - const customJsonOperationsCosts = operationCosts.custom_json_operation.avg_cost; - const createClaimAccountCost = Number(operationCosts.claim_account_operation.avg_cost); + const customJsonOperationsCosts = + operationCosts.custom_json_operation.avg_cost; + const createClaimAccountCost = Number( + operationCosts.claim_account_operation.avg_cost + ); - const commentCount: number = Math.ceil(Number(amount) * 1e9 / commentCost); - const votetCount: number = Math.ceil(Number(amount) * 1e9 / voteCost); - const transferCount: number = Math.ceil(Number(amount) * 1e9 / transferCost); - const customJsonCount: number = Math.ceil(Number(amount) * 1e9 / customJsonOperationsCosts + const commentCount: number = Math.ceil( + (Number(amount) * 1e9) / commentCost + ); + const votetCount: number = Math.ceil((Number(amount) * 1e9) / voteCost); + const transferCount: number = Math.ceil( + (Number(amount) * 1e9) / transferCost + ); + const customJsonCount: number = Math.ceil( + (Number(amount) * 1e9) / customJsonOperationsCosts ); const createClaimAccountCount: number = Math.floor( Number(amount) / createClaimAccountCost @@ -176,8 +191,8 @@ export const ResourceCreditsDelegation = (props: any) => { return resp; }) .catch((err: any) => { - // error(...formatError(err)); - console.log(err) + // error(...formatError(err)); + console.log(err); }) .finally(() => { setInProgress(false); @@ -185,7 +200,10 @@ export const ResourceCreditsDelegation = (props: any) => { } }; - const delayedSearch = useCallback(_.debounce(handleTo, 3000, { leading: true }), []); + const delayedSearch = useCallback( + _.debounce(handleTo, 3000, { leading: true }), + [] + ); const formHeader1 = (
@@ -207,33 +225,43 @@ export const ResourceCreditsDelegation = (props: any) => {
); - const handlePointClick = (event:any, index: number, percentage: number) => { + const handlePointClick = (event: any, index: number, percentage: number) => { event.stopPropagation(); setFillWidth(percentage); - const formartInput = (((percentage / 100) * resourceCredit) / 1e9).toFixed(0) - console.log(percentage) - setAmount(formartInput) + const formartInput = (((percentage / 100) * resourceCredit) / 1e9).toFixed( + 0 + ); + console.log(percentage); + setAmount(formartInput); }; const handleProgressLineClick = (event: any) => { - const clickedPosition = (event.nativeEvent.offsetX / event.currentTarget.clientWidth) * 100; - console.log(clickedPosition) - event.stopPropagation() + const clickedPosition = + (event.nativeEvent.offsetX / event.currentTarget.clientWidth) * 100; + console.log(clickedPosition); + event.stopPropagation(); - const formmattedInput = ((clickedPosition / 100) * resourceCredit / 1e9).toFixed(0); + const formmattedInput = ( + ((clickedPosition / 100) * resourceCredit) / + 1e9 + ).toFixed(0); setFillWidth(clickedPosition); setAmount(formmattedInput); }; const updateOnAmount = (a: number) => { - const rcPercent = (a * 1e9) / resourceCredit * 100 - setFillWidth(rcPercent) - } + const rcPercent = ((a * 1e9) / resourceCredit) * 100; + setFillWidth(rcPercent); + }; return (
{step === 1 && ( -
+
{formHeader1} {inProgress && }
@@ -243,7 +271,11 @@ export const ResourceCreditsDelegation = (props: any) => {
- +
@@ -267,15 +299,22 @@ export const ResourceCreditsDelegation = (props: any) => { {/* */} {toWarning && ( - {toWarning} + + {toWarning} + + )} + {toError && ( + {toError} )} - {toError && {toError}}
- +
@@ -285,14 +324,18 @@ export const ResourceCreditsDelegation = (props: any) => { value={amount} onChange={amountChanged} className={ - Number(amount) > Number(resourceCredit) && amountError ? "is-invalid" : "" + Number(amount) > Number(resourceCredit) && amountError + ? "is-invalid" + : "" } />
- {amount < 5000000000 && {amountError}} + {amount < 5000000000 && ( + {amountError} + )} {amount > Number(resourceCredit) && ( {amountError} )} @@ -301,33 +344,45 @@ export const ResourceCreditsDelegation = (props: any) => { Posts/Comment: {commentAmount} Votes: {voteAmount} Transfers: {transferAmount} - Reblogs/ Follows: {customJsonAmount} + + Reblogs/ Follows: {customJsonAmount} + -
+
-
handlePointClick(e, 0, 0)} - >
-
handlePointClick(e, 1, 25)} - >
-
handlePointClick(e, 2, 50)} - >
-
handlePointClick(e, 3, 75)} - >
-
handlePointClick(e, 4, 100)} - >
+
handlePointClick(e, 0, 0)} + /> +
handlePointClick(e, 1, 25)} + /> +
handlePointClick(e, 2, 50)} + /> +
handlePointClick(e, 3, 75)} + /> +
handlePointClick(e, 4, 100)} + />
- {_t("transfer.balance")} + + {_t("transfer.balance")} + {`: ${convertToBillions(resourceCredit)}`}
@@ -368,7 +423,7 @@ export const ResourceCreditsDelegation = (props: any) => {
{amount}Bn RC
-