Skip to content

Commit

Permalink
(launch) fix: Rewards per second (#127)
Browse files Browse the repository at this point in the history
* feat: change from InputNumber to Input

* feat: allow only numbers
  • Loading branch information
mohandast52 authored Nov 4, 2024
1 parent fac3159 commit 6204d48
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
19 changes: 13 additions & 6 deletions apps/launch/components/MyStakingContracts/Create/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { mainnet } from 'viem/chains';
import { useAccount } from 'wagmi';

import { CHAIN_NAMES, EXPLORER_URLS, UNICODE_SYMBOLS } from 'libs/util-constants/src';
import { notifyWarning } from 'libs/util-functions/src';
import { allowOnlyNumbers, notifyWarning } from 'libs/util-functions/src';

import { ErrorAlert } from 'common-util/ErrorAlert';
import {
Expand Down Expand Up @@ -145,7 +145,10 @@ export const CreateStakingContract = () => {
} = values;

try {
const metadataHash = await getIpfsHash({ name: contractName, description });
const metadataHash = await getIpfsHash({
name: contractName,
description,
});

const implementation = STAKING_TOKEN_ADDRESSES[chain.id];
const initPayload = getStakingContractInitPayload({
Expand All @@ -170,7 +173,11 @@ export const CreateStakingContract = () => {
throw new Error('Validation failed');
}

const result = await createStakingContract({ implementation, initPayload, account });
const result = await createStakingContract({
implementation,
initPayload,
account,
});
if (result) {
const eventLog = result.events?.InstanceCreated?.returnValues;

Expand All @@ -189,7 +196,7 @@ export const CreateStakingContract = () => {
router.push(`/${networkName}/${URL.myStakingContracts}`);
}
} catch (error) {
console.log(error);
console.error(error);

const { message, transactionHash } = getErrorInfo(Feature.CREATE, error as Error);
setError({ message, transactionHash });
Expand Down Expand Up @@ -254,10 +261,10 @@ export const CreateStakingContract = () => {
name="rewardsPerSecond"
rules={rulesConfig.rewardsPerSecond.rules}
>
<InputNumber
<Input
placeholder="e.g. 0.000001649305555557"
step="0.0001"
style={INPUT_WIDTH_STYLE}
onKeyDown={allowOnlyNumbers}
/>
</Form.Item>
</Col>
Expand Down
30 changes: 30 additions & 0 deletions libs/util-functions/src/lib/formValidations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,33 @@ export const FORM_VALIDATION: {
},
},
};

export const allowOnlyNumbers = (e: React.KeyboardEvent<HTMLInputElement>) => {
const isCopy = (e.ctrlKey || e.metaKey) && e.key === 'c';
const isPaste = (e.ctrlKey || e.metaKey) && e.key === 'v';
const isCut = (e.ctrlKey || e.metaKey) && e.key === 'x';
const isSelectAll = (e.ctrlKey || e.metaKey) && e.key === 'a';

if (
!/[0-9]/.test(e.key) &&
e.key !== 'Backspace' &&
e.key !== 'Delete' &&
e.key !== 'ArrowLeft' &&
e.key !== 'ArrowRight' &&
e.key !== 'Tab' &&
e.key !== 'Control' &&
e.key !== '.' &&
!isCopy &&
!isPaste &&
!isCut &&
!isSelectAll
) {
e.preventDefault();
}

// Prevent more than one decimal point
const value = e.currentTarget.value;
if (e.key === '.' && value.includes('.')) {
e.preventDefault();
}
};

0 comments on commit 6204d48

Please sign in to comment.