Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
big-number-input
Advanced tools
A BigNumberInput to use with decentralized applications and React.
You are using big integer numbers that can be expressed as smaller fractional numbers and you want users to be able to
enter them in this format. The originating use case for this library are ERC20 tokens, but a simpler example is having
some amount expressed in millions. You want the user to input 1.5
but to receive a bignumber containing 1500000
. In
this case, you can use big-number-input
with a decimals
value of 6. See Usage
below for more information.
npm install big-number-input
Import the component and pass the required props:
import React from 'react'
import { BigNumberInput } from 'big-number-input'
function App() {
const [value, setValue] = React.useState('1000000')
return (
<div>
<BigNumberInput
decimals={6}
onChange={setValue}
value={value}
/>
<div>{value || 'empty'}</div>
</div>
)
}
export default App
In this case the input value is 1000000 and the rendered value will be 1. If the user changes it to 2 in the UI the onChange will be called with 2000000.
The required props are:
decimals
: The number of decimals you want to usevalue
: A string with the raw value that will be used by the input, eg. 1000000.onChange
: A function that receives the new raw value, or an empty string when the input is emptyThen you have a bunch of optional props you can use:
autofocus
: Set to true if you want the input to obtain focus as soon as it's renderedplaceholder
: A string to use as the input's placeholderdisabled
: A boolean used to disable the inputmin
, max
and step
: The min and max values you want to use and the step used when you increase or decrease the
number with the arrow keys or by clicking the arrows in the input. These values are also strings with the raw values and are interpreted with the same number of decimals as the main value.If you want to use a different input, for example the Input
from Material UI, you can use
the renderInput
prop:
import React from 'react';
import { BigNumberInput } from 'big-number-input'
import { Input } from '@material-ui/core'
function App() {
const [value, setValue] = React.useState('')
return (
<div>
<BigNumberInput decimals={6} onChange={setValue} value={value} renderInput={
props => <Input {...props} />
}/>
<div>{value || 'empty'}</div>
</div>
);
}
If you want to use some big number library to store your value, you can follow an approach like this:
import React from "react";
import Big from 'big.js'
import { BigNumberInput } from "big-number-input";
function App() {
const [value, setValue] = React.useState(null);
return (
<div>
<BigNumberInput
autofocus={true}
decimals={6}
onChange={newValue => newValue ? setValue(new Big(newValue)) : setValue(null)}
value={value ? value.toString() : ''}
/>
<div>{value ? value.toString() : "empty"}</div>
</div>
);
}
Here we use null
to indicate an empty input, and a big number instance when there is something entered in the input.
FAQs
A BigNumberInput to use with decentralized applications and React
The npm package big-number-input receives a total of 112 weekly downloads. As such, big-number-input popularity was classified as not popular.
We found that big-number-input demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.