Skip to content

Instantly share code, notes, and snippets.

@sergeysova
Created July 12, 2022 08:57
Show Gist options
  • Save sergeysova/c5c79fbcab58ddbb83e507ddce70d1d5 to your computer and use it in GitHub Desktop.
Save sergeysova/c5c79fbcab58ddbb83e507ddce70d1d5 to your computer and use it in GitHub Desktop.
useEffect(() => {
const durationMs = parseDuration(duration ?? '');
if (durationMs && selectedToken) {
const durationSeconds = new Decimal(durationMs).div(1000);
const speedInYocto = new Decimal(amountToStream)
.div(durationSeconds)
.toFixed();
setValue('speed', speedInYocto);
} else {
setValue('speed', '0');
}
}, [setValue, duration, amountToStream, selectedToken]);
const speedInHuman = useMemo(() => {
if (selectedToken && speed !== '0') {
const formatter = new TokenFormatter(selectedToken.decimals);
return formatter.tokensPerMeaningfulPeriod(speed);
}
return { formattedValue: '0', unit: 'second' };
}, [speed, selectedToken]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment