Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#128 Remove gas based commission #136

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,10 @@ describe('CommissionModel step component', () => {
render(<CommissionModel stepNumber={1} />);

expect(screen.getByText('1')).toBeInTheDocument();
expect(screen.getByText('Commission Model')).toBeInTheDocument();
expect(
screen.getByText(
'Choose the commission model and fee for your pool'
)
).toBeInTheDocument();
expect(screen.getByText('Commission')).toBeInTheDocument();
expect(
screen.queryByLabelText('Flat-rate commission (%)')
).not.toBeInTheDocument();
expect(
screen.queryByLabelText('Gas-based commission (Gas)')
).not.toBeInTheDocument();
expect(screen.queryByText('PREVIOUS')).not.toBeInTheDocument();
expect(screen.queryByText('CREATE POOL')).not.toBeInTheDocument();
});
Expand All @@ -147,11 +139,9 @@ describe('CommissionModel step component', () => {
render(<CommissionModel stepNumber={1} inFocus />);

expect(screen.getByText('1')).toBeInTheDocument();
expect(screen.getByText('Commission Model')).toBeInTheDocument();
expect(screen.getByText('Commission')).toBeInTheDocument();
expect(
screen.getByText(
'Choose the commission model and fee for your pool'
)
screen.getByText('Set the commission fee for your pool')
).toBeInTheDocument();
expect(
screen.getByLabelText('Flat-rate commission (%)')
Expand All @@ -161,15 +151,6 @@ describe('CommissionModel step component', () => {
'This model calculates the commission as a fixed percentage of the block CTSI reward before distributing the remaining amount to the pool users.'
)
).toBeInTheDocument();
expect(
screen.getByLabelText('Gas-based commission (Gas)')
).toBeInTheDocument();

expect(
screen.getByText(
'This model calculates the commission considering the current network gas price, Ethereum price and CTSI price. The configured amount of gas above is multiplied by the gas price provided by a ChainLink oracle, then converted from ETH to CTSI using an Uniswap V2 price oracle.'
)
).toBeInTheDocument();
expect(screen.getByText('PREVIOUS')).toBeInTheDocument();
expect(screen.getByText('CREATE POOL')).toBeInTheDocument();
});
Expand Down Expand Up @@ -278,40 +259,6 @@ describe('CommissionModel step component', () => {
).toBeInTheDocument();
});
});

describe('Gas Based Commission', () => {
it('should display a message when the field is visited and left in blank', async () => {
const { container } = render(
<CommissionModel inFocus stepNumber={1} />
);

const gasBasedOption = container.querySelector(
`input[name='gasBasedOption']`
);

await act(() => {
fireEvent.click(gasBasedOption);
});

await waitFor(() =>
expect(
screen
.getByText('Gas-based commission (Gas)')
.hasAttribute('disabled')
).toBe(false)
);

await act(() => {
fireEvent.blur(
screen.getByLabelText('Gas-based commission (Gas)')
);
});

expect(
await screen.findByText('This field is required.')
).toBeInTheDocument();
});
});
});

describe('Notifications', () => {
Expand Down Expand Up @@ -501,46 +448,6 @@ describe('CommissionModel step component', () => {
);
});

it('should call creation pool method based on selected model type (Gas Based)', async () => {
const poolFactory = buildUseStakingPoolFactoryReturn();
mockUseStakingPoolFactory.mockReturnValue(poolFactory);
const { container } = render(
<CommissionModel inFocus stepNumber={1} />
);

const gasBasedOption = container.querySelector(
`input[name='gasBasedOption']`
);

await act(() => {
fireEvent.click(gasBasedOption);
});

await waitFor(() =>
expect(
screen
.getByText('Gas-based commission (Gas)')
.hasAttribute('disabled')
).toBe(false)
);

await act(() => {
fireEvent.change(
screen.getByLabelText('Gas-based commission (Gas)'),
{ target: { value: 400000 } }
);
});

const button = screen.getByText('CREATE POOL');
fireEvent.click(button);

await waitFor(() =>
expect(
poolFactory.createGasTaxCommission
).toHaveBeenCalledWith(400000)
);
});

it('should display spinner when transaction is submitted and avoid any subsequent click', async () => {
const poolFactory = buildUseStakingPoolFactoryReturn();
mockUseStakingPoolFactory.mockReturnValue(poolFactory);
Expand Down Expand Up @@ -632,9 +539,6 @@ describe('CommissionModel step component', () => {
expect(
screen.queryByLabelText('Flat-rate commission (%)')
).not.toBeInTheDocument();
expect(
screen.queryByLabelText('Gas-based commission (Gas)')
).not.toBeInTheDocument();
expect(screen.queryByText('PREVIOUS')).not.toBeInTheDocument();
expect(screen.queryByText('NEXT')).not.toBeInTheDocument();
});
Expand Down
22 changes: 0 additions & 22 deletions apps/staking/__tests__/services/poolFactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ const walletData = {

const stakingPoolFactoryContract = {
createFlatRateCommission: jest.fn(),
createGasTaxCommission: jest.fn(),
paused: () => Promise.resolve(),
referencePool: () => Promise.resolve(),
pos: () => Promise.resolve(),
Expand Down Expand Up @@ -103,27 +102,6 @@ describe('poolFactory service', () => {
expect(mockedCreateFlatRateCommission).toHaveBeenCalled();
});

it('should invoke createGasTaxCommission and related functions when poolFactory exists', async () => {
const mockedSet = jest.fn();
mockedUseTransaction.mockReturnValue({
set: mockedSet,
} as unknown as Transaction<any>);

const mockedCreateGasTaxCommission = jest.fn();
mockedUseStakingPoolFactoryContract.mockReturnValue({
...stakingPoolFactoryContract,
createGasTaxCommission: mockedCreateGasTaxCommission,
} as unknown as StakingPoolFactoryImpl);

const { result } = renderHook(() => useStakingPoolFactory());
await act(async () => {
await result.current.createGasTaxCommission(1000);
});

expect(mockedSet).toHaveBeenCalled();
expect(mockedCreateGasTaxCommission).toHaveBeenCalled();
});

it('should not set pos when poolFactory and account are undefined', () => {
mockedUseStakingPoolFactoryContract.mockReturnValue(undefined);
const { result } = renderHook(() => useStakingPoolFactory());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,22 @@
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
// PARTICULAR PURPOSE. See the GNU General Public License for more details.

import { Heading, RadioGroup, Radio, Stack, Button } from '@chakra-ui/react';
import { Stack, Button } from '@chakra-ui/react';
import { Step, StepActions, StepBody, StepStatus } from '../../../Step';
import { IStep, useStepState } from '../../../StepGroup';
import { useState, useEffect } from 'react';
import { OptionalMappedErrors, ValidationResult } from '../../../BaseInput';
import { useStakingPoolFactory } from '../../../../services/poolFactory';
import TransactionBanner from '../../../TransactionBanner';
import FlatRateCommission, { FlatRateModel } from './FlatRateCommission';
import GasBasedCommission, { GasBasedModel } from './GasBasedCommission';
import { isEmpty, isFunction, omit, toNumber } from 'lodash/fp';
import { Transaction } from '../../../../services/transaction';
import { useMessages } from '../../../../utils/messages';
import { useWallet } from '@explorer/wallet';
import { atom, useAtom } from 'jotai';
import { WalletDisconnectedNotification } from '../WalletDisconnectedNotification';

type CommissionModels = FlatRateModel | GasBasedModel;
type Validation = ValidationResult<FlatRateModel | GasBasedModel>;
type Validation = ValidationResult<FlatRateModel>;
type Errors = OptionalMappedErrors<Validation>;
const { COMPLETED } = StepStatus;
const poolAddressAtom = atom<string>('');
Expand Down Expand Up @@ -93,20 +91,15 @@ const CommissionModel = ({
const { account, active } = wallet;
const poolFactory = useStakingPoolFactory();
const [stepState, setStepState] = useStepState({ inFocus });
const [modelType, setModelType] =
useState<CommissionModels>('flatRateCommission');
const [flatRateVal, setFlatRateVal] = useState<string | null>();
const [gasBasedVal, setGasBasedVal] = useState<string | null>();
const [errors, setErrors] = useState<Errors>({});
const radioHandler = (v: CommissionModels) => setModelType(v);
const notInitialised = !poolFactory.loading && !poolFactory.ready;
const poolCreationIsPaused = !poolFactory.loading && poolFactory.paused;
const disablePoolCreationButton = createPoolDisabled({
creationIsPaused: poolCreationIsPaused,
factoryIsNotReady: notInitialised,
commissionModel: modelType,
commissionValue:
modelType === 'flatRateCommission' ? flatRateVal : gasBasedVal,
commissionModel: 'flatRateCommission',
commissionValue: flatRateVal,
account,
errors,
});
Expand All @@ -133,14 +126,12 @@ const CommissionModel = ({
if (inFocus) return;

setFlatRateVal(null);
setGasBasedVal(null);
setModelType('flatRateCommission');
}, [inFocus]);

return (
<Step
title="Commission Model"
subtitle="Choose the commission model and fee for your pool"
title="Commission"
subtitle="Set the commission fee for your pool"
stepNumber={stepNumber}
status={stepState.status}
onActive={onStepActive}
Expand All @@ -157,47 +148,11 @@ const CommissionModel = ({
successDescription={`Pool ${poolFactory.transaction?.result} created! moving to the next step...`}
transaction={poolFactory.transaction}
/>
<Heading as="h3" size="sm" my={4}>
Choose commission model
</Heading>

<Stack
direction="row"
spacing={{ base: 3, md: 7 }}
mt={2}
onClick={(e) => radioHandler('flatRateCommission')}
>
<RadioGroup value={modelType} pt={1} name="flatRateOption">
<Radio
value="flatRateCommission"
isChecked={modelType === 'flatRateCommission'}
/>
</RadioGroup>
<FlatRateCommission
onChange={setFlatRateVal}
isDisabled={modelType !== 'flatRateCommission'}
onValidationChange={handleValidation}
/>
</Stack>

<Stack
direction="row"
spacing={{ base: 3, md: 7 }}
mt={8}
onClick={(e) => radioHandler('gasBasedCommission')}
>
<RadioGroup value={modelType} pt={1} name="gasBasedOption">
<Radio
value="gasBasedCommission"
isChecked={modelType === 'gasBasedCommission'}
/>
</RadioGroup>
<GasBasedCommission
onChange={setGasBasedVal}
isDisabled={modelType !== 'gasBasedCommission'}
onValidationChange={handleValidation}
/>
</Stack>
<FlatRateCommission
onChange={setFlatRateVal}
onValidationChange={handleValidation}
/>
</StepBody>
<StepActions>
<Stack
Expand All @@ -220,15 +175,9 @@ const CommissionModel = ({
colorScheme="blue"
minWidth={{ base: '50%', md: '10rem' }}
onClick={() => {
if (modelType === 'flatRateCommission') {
poolFactory.createFlatRateCommission(
toNumber(flatRateVal) * 100
);
} else {
poolFactory.createGasTaxCommission(
toNumber(gasBasedVal)
);
}
poolFactory.createFlatRateCommission(
toNumber(flatRateVal) * 100
);
}}
>
CREATE POOL
Expand Down

This file was deleted.

Loading