otterscan/src/search/useFeeToggler.ts
2021-08-31 16:49:52 -03:00

20 lines
441 B
TypeScript

import { useState } from "react";
export enum FeeDisplay {
TX_FEE,
TX_FEE_USD,
GAS_PRICE,
}
export const useFeeToggler = (): [FeeDisplay, () => void] => {
const [feeDisplay, setFeeDisplay] = useState<FeeDisplay>(FeeDisplay.TX_FEE);
const feeDisplayToggler = () => {
setFeeDisplay(feeDisplay + 1);
if (feeDisplay === FeeDisplay.GAS_PRICE) {
setFeeDisplay(0);
}
};
return [feeDisplay, feeDisplayToggler];
};