Skip to content

Commit

Permalink
fix: remove unnecsesary variables
Browse files Browse the repository at this point in the history
  • Loading branch information
annipi committed Feb 22, 2024
1 parent 242863c commit 16d6cb3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 38 deletions.
7 changes: 1 addition & 6 deletions src/app/tabs/registrar/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
REQUEST_CONVERSION_RATE, RECEIVE_CONVERSION_RATE, ERROR_CONVERSION_RATE,
TOGGLE_SETUP_ADDRESS, CLOSE_REGISTRATION_ERROR, REQUEST_CHECK_COMMIT_REGISTRAR,
RECEIVE_CHECK_COMMITMENT_REQUIRED, REQUEST_CHECK_COMMITMENT_REQUIRED,
REQUEST_HAS_ENOUGH_RIF, RECEIVE_HAS_ENOUGH_RIF, ERROR_NOT_ENOUGH_RIF,
REQUEST_HAS_ENOUGH_RIF, ERROR_NOT_ENOUGH_RIF,
} from './types';

export const requestGetCost = duration => ({
Expand Down Expand Up @@ -109,11 +109,6 @@ export const requestHasEnoughRif = () => ({
type: REQUEST_HAS_ENOUGH_RIF,
});

export const receiveHasEnoughRif = hasEnoughRif => ({
type: RECEIVE_HAS_ENOUGH_RIF,
hasEnoughRif,
});

export const errorHasEnoughRIF = message => ({
type: ERROR_NOT_ENOUGH_RIF,
message,
Expand Down
35 changes: 13 additions & 22 deletions src/app/tabs/registrar/operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
requestIsCommitmentRequired,
receiveIsCommitmentRequired,
requestHasEnoughRif,
receiveHasEnoughRif,
errorHasEnoughRIF,
} from './actions';
import {
Expand All @@ -32,7 +31,7 @@ import {
rifAbi,
} from './abis.json';
import { FIFS_REGISTRER, FIFS_ADDR_REGISTRER } from './types';
import { sendBrowserNotification } from '../../browerNotifications/operations';
import { getLanguageString, sendBrowserNotification } from '../../browerNotifications/operations';
import { start } from '../../auth/operations';
import {
registrar, partnerConfiguration, getCurrentPartner, provider,
Expand Down Expand Up @@ -95,16 +94,8 @@ export const hasEnoughRif = cost => dispatch => new Promise((resolve, reject) =>
const signer = await getSigner();
const currentUserAccount = await signer.getAddress();
const rif = new ethers.Contract(rifAddress, rifAbi, signer);
rif.balanceOf(currentUserAccount)
.then((balance) => {
if (balance / (10 ** 18) < cost) {
dispatch(errorHasEnoughRIF());
return resolve(false);
}
dispatch(receiveHasEnoughRif((balance / (10 ** 18)) >= cost));
return resolve((balance / (10 ** 18)) >= cost);
})
.catch(error => dispatch(errorHasEnoughRIF(error.message)));
const balance = await rif.balanceOf(currentUserAccount);
return resolve((balance / (10 ** 18)) >= cost);
};

// eslint-disable-next-line no-unused-expressions
Expand Down Expand Up @@ -229,10 +220,10 @@ export const checkIfAlreadyCommitted = domain => async (dispatch) => {
export const revealCommit = domain => async (dispatch, getState) => {
const { rifCost: cost } = getState().registrar;

const errorMessage = getLanguageString('not_enough_rif_balance');
const hasEnough = await dispatch(hasEnoughRif(cost));
if (!hasEnough) return dispatch(errorHasEnoughRIF('Insufficient RIF balance'));
if (!hasEnough) return dispatch(errorHasEnoughRIF(errorMessage));

// eslint-disable-next-line consistent-return
const callback = async () => {
let options = localStorage.getItem(`${domain}-options`);
if (!options) {
Expand All @@ -241,19 +232,19 @@ export const revealCommit = domain => async (dispatch, getState) => {

options = JSON.parse(options);
const {
salt, duration, rifCost, hasEnoughRIF,
salt, duration, rifCost,
} = options;

try {
if (hasEnoughRIF) dispatch(requestRevealCommit());
dispatch(requestRevealCommit());

const signer = await getSigner();
const currentUserAccount = await signer.getAddress();
const signer = await getSigner();
const currentUserAccount = await signer.getAddress();

const Registrar = await registrar(signer);
const durationBN = BigNumber.from(duration);
const rifCostBN = ethers.utils.parseEther(rifCost.toString());
const Registrar = await registrar(signer);
const durationBN = BigNumber.from(duration);
const rifCostBN = ethers.utils.parseEther(rifCost.toString());

try {
const txHash = await Registrar.register(
domain, currentUserAccount, salt, durationBN, rifCostBN,
);
Expand Down
11 changes: 2 additions & 9 deletions src/app/tabs/registrar/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
CLOSE_REGISTRATION_ERROR, REQUEST_CHECK_COMMIT_REGISTRAR,
REQUEST_CHECK_COMMITMENT_REQUIRED,
RECEIVE_CHECK_COMMITMENT_REQUIRED,
REQUEST_HAS_ENOUGH_RIF, RECEIVE_HAS_ENOUGH_RIF, ERROR_NOT_ENOUGH_RIF,
REQUEST_HAS_ENOUGH_RIF, ERROR_NOT_ENOUGH_RIF,
} from './types';

const initialState = {
Expand All @@ -30,7 +30,6 @@ const initialState = {
errorMessage: '',
successTx: '',
hasEnoughRIF: false,
gettingHasEnoughRIF: false,
};
const registrar = (state = initialState, action) => {
switch (action.type) {
Expand Down Expand Up @@ -138,16 +137,10 @@ const registrar = (state = initialState, action) => {
};
case REQUEST_HAS_ENOUGH_RIF: return {
...state,
gettingHasEnoughRIF: true,
};
case RECEIVE_HAS_ENOUGH_RIF: return {
...state,
hasEnoughRIF: action.hasEnoughRIF,
gettingHasEnoughRIF: false,
};
case ERROR_NOT_ENOUGH_RIF: return {
...state,
errorMessage: 'Insufficient RIF balance',
errorMessage: action.message,
};
case RESET_REGISTRAR_STATE:
return initialState;
Expand Down
1 change: 0 additions & 1 deletion src/app/tabs/registrar/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ export const CLOSE_REGISTRATION_ERROR = 'CLOSE_REGISTRATION_ERROR';
export const REQUEST_CHECK_COMMITMENT_REQUIRED = 'REQUEST_CHECK_COMMITMENT_REQUIRED';
export const RECEIVE_CHECK_COMMITMENT_REQUIRED = 'RECEIVE_CHECK_COMMITMENT_REQUIRED';
export const REQUEST_HAS_ENOUGH_RIF = 'REQUEST_HAS_ENOUGH_RIF';
export const RECEIVE_HAS_ENOUGH_RIF = 'RECEIVE_HAS_ENOUGH_RIF';
export const ERROR_NOT_ENOUGH_RIF = 'ERROR_NOT_ENOUGH_RIF';

0 comments on commit 16d6cb3

Please sign in to comment.