Skip to content

Commit

Permalink
refactor: remove gas tax from type model
Browse files Browse the repository at this point in the history
  • Loading branch information
dandheedge committed Oct 19, 2023
1 parent 2a72739 commit aa3d674
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
// PARTICULAR PURPOSE. See the GNU General Public License for more details.

import { render, screen } from '@testing-library/react';
import { FaNetworkWired } from 'react-icons/fa';
import PoolCommission from '../../../src/components/pools/PoolCommission';
import { withChakraTheme } from '../../test-utilities';
import { StakingPool } from '../../../src/graphql/models';
import stakingPoolsData from '../../../src/stories/stake/tables/stakingPoolsData';
import { FaNetworkWired } from 'react-icons/fa';
import { withChakraTheme } from '../../test-utilities';

const [pool] = stakingPoolsData as unknown as StakingPool[];

Expand Down Expand Up @@ -43,9 +43,7 @@ describe('PoolCommission component', () => {
pool.commissionPercentage !== null
? numberFormat.format(pool.commissionPercentage)
: '-';
const commissionLabel = pool.fee.commission
? `${(pool.fee.commission / 100).toFixed(2)} %`
: `${pool.fee.gas} Gas`;
const commissionLabel = `${(pool.fee.commission / 100).toFixed(2)} %`;

const valueLabel = `${accruedCommissionLabel} (${commissionLabel})`;

Expand Down
8 changes: 3 additions & 5 deletions apps/staking/src/components/pools/PoolCommission.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
// PARTICULAR PURPOSE. See the GNU General Public License for more details.

import React, { FC } from 'react';
import { Flex, HStack, SystemProps, Text, TextProps } from '@chakra-ui/react';
import { Icon } from '@chakra-ui/icons';
import { Flex, HStack, SystemProps, Text, TextProps } from '@chakra-ui/react';
import { FC } from 'react';
import { IconType } from 'react-icons';
import { StakingPool } from '../../graphql/models';

Expand All @@ -33,9 +33,7 @@ const PoolCommission: FC<PoolCommissionProps> = (props) => {
pool.commissionPercentage !== null
? numberFormat.format(pool.commissionPercentage)
: '-';
const commissionLabel = pool.fee.commission
? `${(pool.fee.commission / 100).toFixed(2)} %`
: `${pool.fee.gas} Gas`;
const commissionLabel = `${(pool.fee.commission / 100).toFixed(2)} %`;

const valueLabel = `${accruedCommissionLabel} (${commissionLabel})`;
return (
Expand Down
2 changes: 1 addition & 1 deletion apps/staking/src/components/stake/CommissionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { useForm } from 'react-hook-form';

export interface CommissionFormProps {
currentValue: number;
unit: '%' | 'gas';
unit: '%';
min?: number;
max?: number;
maxRaise: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
// PARTICULAR PURPOSE. See the GNU General Public License for more details.

import { FC, useState } from 'react';
import { LockIcon } from '@chakra-ui/icons';
import {
Box,
Expand All @@ -25,6 +24,7 @@ import {
import { Address, StakeIcon } from '@explorer/ui';
import { first, last } from 'lodash/fp';
import NextLink from 'next/link';
import { FC, useState } from 'react';
import { StakingPool } from '../../../graphql/models';
import labels from '../../../utils/labels';
import { formatCTSI } from '../../../utils/token';
Expand Down Expand Up @@ -92,29 +92,11 @@ const PoolPerformanceTableRow: FC<PoolPerformanceTableRowProps> = ({
? numberFormat.format(pool.commissionPercentage)
: '-';

let flatRate = pool.fee.commission > 0;
const gasTax = pool.fee.gas > 0;

// XXX: if both are zero, currently we don't which is it, for now let's assume it's flat rate
if (!flatRate && !gasTax) {
flatRate = true;
}

// commission label
let commissionLabel = '';
if (flatRate) {
commissionLabel = `${(pool.fee.commission / 100).toFixed(2)} %`;
} else if (gasTax) {
commissionLabel = `${pool.fee.gas} Gas`;
}
const commissionLabel = `${(pool.fee.commission / 100).toFixed(2)} %`;

// commission help tooltip
let commissionTooltip: string = undefined;
if (flatRate) {
commissionTooltip = labels.flatRateCommission;
} else if (gasTax) {
commissionTooltip = labels.gasTaxCommission;
}
const commissionTooltip: string = labels.flatRateCommission;

const [isHovered, setHovered] = useState(false);
const backgroundColor = useColorModeValue('white', 'dark.gray.primary');
Expand Down
1 change: 0 additions & 1 deletion apps/staking/src/graphql/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ export type StakingPoolFee = {
};

export enum StakingPoolFeeType {
GAS_TAX = 'GAS_TAX_COMMISSION',
FLAT_RATE = 'FLAT_RATE_COMMISSION',
}

Expand Down
16 changes: 1 addition & 15 deletions apps/staking/src/stories/pools/fee/CommissionForm.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
// PARTICULAR PURPOSE. See the GNU General Public License for more details.

import React from 'react';
import { ComponentStory, ComponentMeta } from '@storybook/react';
import { ComponentMeta, ComponentStory } from '@storybook/react';

import CommissionForm from '../../../components/pools/fee/CommissionForm';

Expand Down Expand Up @@ -53,16 +52,3 @@ IncreaseLocked.args = {
helperText:
'Commission is set as a fixed percentage of every block reward (CTSI)',
};

export const GasTax = Template.bind({});
GasTax.args = {
currentValue: 210000,
unit: 'gas',
min: 0,
maxRaise: 20000,
maxDigits: 0,
increaseWaitPeriod: 60 * 60 * 24 * 7, // 7 days
nextIncrease: new Date(now.getTime() - 60 * 1000),
helperText:
'Commission is set as an amount of gas. This amount is converted to CTSI at the time of block production, by using a gas price from an oracle and a ETH/CTSI price from a price oracle.',
};

0 comments on commit aa3d674

Please sign in to comment.