Skip to content

Commit

Permalink
chore: update error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Hemanthghs committed Sep 20, 2024
1 parent 2c592a8 commit 7c436d3
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 39 deletions.
9 changes: 3 additions & 6 deletions frontend/src/custom-hooks/common/useInitApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const useInitApp = () => {
isAuthzMode
? getAuthzDelegations(chainRequestData)
: getDelegations(chainRequestData)
).then();
);

// Fetch available balances
dispatch(
Expand Down Expand Up @@ -108,9 +108,6 @@ const useInitApp = () => {
: getUnbonding(chainRequestData)
);

// Fetch validators
dispatch(getAllValidators({ baseURLs: restURLs, chainID }));

// Mark chain as fetched
fetchedChains.current[chainID] = true;
}
Expand All @@ -132,8 +129,8 @@ const useInitApp = () => {
useEffect(() => {
if (chainIDs.length > 0) {
chainIDs.forEach((chainID) => {
if (!validatorsFetchedChains.current[chainID]) {
const { restURLs } = getChainInfo(chainID);
const { restURLs } = getChainInfo(chainID);
if (restURLs?.length && !validatorsFetchedChains.current[chainID]) {
// Fetch validators
dispatch(getAllValidators({ baseURLs: restURLs, chainID }));

Expand Down
32 changes: 23 additions & 9 deletions frontend/src/store/features/bank/bankSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { GAS_FEE } from '../../../utils/constants';
import { TxStatus } from '../../../types/enums';
import { ERR_UNKNOWN } from '@/utils/errors';
import { NewTransaction } from '@/utils/transaction';
import { setTxAndHash } from '../common/commonSlice';
import { setError, setTxAndHash } from '../common/commonSlice';
import cloneDeep from 'lodash/cloneDeep';
import { trackEvent } from '@/utils/util';

Expand Down Expand Up @@ -136,18 +136,25 @@ export const multiTxns = createAsyncThunk(
})
);

trackEvent('TRANSFER', 'MULTI_SEND', 'SUCCESS')
trackEvent('TRANSFER', 'MULTI_SEND', 'SUCCESS');

return fulfillWithValue({ txHash: result?.transactionHash });
} else {

trackEvent('TRANSFER', 'MULTI_SEND', 'FAILED')
trackEvent('TRANSFER', 'MULTI_SEND', 'FAILED');

return rejectWithValue(result?.rawLog);
}
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
} catch (error: any) {
return rejectWithValue(error.message);
trackEvent('TRANSFER', 'MULTI_SEND', 'FAILED');
const errMessage = error?.response?.data?.error || error?.message;
dispatch(
setError({
type: 'error',
message: errMessage || ERR_UNKNOWN,
})
);
return rejectWithValue(errMessage || ERR_UNKNOWN);
}
}
);
Expand Down Expand Up @@ -220,18 +227,25 @@ export const txBankSend = createAsyncThunk(
);
}

trackEvent('TRANSFER', 'SEND', 'SUCCESS')
trackEvent('TRANSFER', 'SEND', 'SUCCESS');

return fulfillWithValue({ txHash: result?.transactionHash });
} else {

trackEvent('TRANSFER', 'SEND', 'FAILED')
trackEvent('TRANSFER', 'SEND', 'FAILED');

return rejectWithValue(result?.rawLog);
}
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
} catch (error: any) {
return rejectWithValue(error.message);
trackEvent('TRANSFER', 'SEND', 'FAILED');
const errMessage = error?.response?.data?.error || error?.message;
dispatch(
setError({
type: 'error',
message: errMessage || ERR_UNKNOWN,
})
);
return rejectWithValue(errMessage || ERR_UNKNOWN);
}
}
);
Expand Down
10 changes: 6 additions & 4 deletions frontend/src/store/features/gov/govSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,13 +433,14 @@ export const txVote = createAsyncThunk(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
trackEvent('GOV', 'VOTE', FAILED);
const errMessage = error?.response?.data?.error || error?.message;
dispatch(
setError({
type: 'error',
message: error?.message || ERR_UNKNOWN,
message: errMessage || ERR_UNKNOWN,
})
);
return rejectWithValue(error?.message || ERR_UNKNOWN);
return rejectWithValue(errMessage || ERR_UNKNOWN);
}
}
);
Expand Down Expand Up @@ -501,13 +502,14 @@ export const txDeposit = createAsyncThunk(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
trackEvent('GOV', 'DEPOSIT', FAILED);
const errMessage = error?.response?.data?.error || error?.message;
dispatch(
setError({
type: 'error',
message: error?.message || ERR_UNKNOWN,
message: errMessage || ERR_UNKNOWN,
})
);
return rejectWithValue(error?.message || ERR_UNKNOWN);
return rejectWithValue(errMessage || ERR_UNKNOWN);
}
}
);
Expand Down
68 changes: 48 additions & 20 deletions frontend/src/store/features/staking/stakeSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ export const txRestake = createAsyncThunk(
})
);
if (result?.code === 0) {
trackEvent('STAKING', 'RESTAKE', SUCCESS);
if (data.isAuthzMode) {
dispatch(
getAuthzDelegatorTotalRewards({
Expand Down Expand Up @@ -262,10 +263,20 @@ export const txRestake = createAsyncThunk(
}
return fulfillWithValue({ txHash: result?.transactionHash });
} else {
trackEvent('STAKING', 'RESTAKE', FAILED);
return rejectWithValue(result?.rawLog);
}
} catch (error) {
if (error instanceof AxiosError) return rejectWithValue(error.response);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
trackEvent('STAKING', 'RESTAKE', FAILED);
const errMessage = error?.response?.data?.error || error?.message;
dispatch(
setError({
type: 'error',
message: errMessage || ERR_UNKNOWN,
})
);
return rejectWithValue(errMessage || ERR_UNKNOWN);
}
}
);
Expand Down Expand Up @@ -361,9 +372,17 @@ export const txDelegate = createAsyncThunk(
trackEvent('STAKING', 'DELEGATE', FAILED);
return rejectWithValue(result?.rawLog);
}
} catch (error) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
trackEvent('STAKING', 'DELEGATE', FAILED);
if (error instanceof AxiosError) return rejectWithValue(error.response);
const errMessage = error?.response?.data?.error || error?.message;
dispatch(
setError({
type: 'error',
message: errMessage || ERR_UNKNOWN,
})
);
return rejectWithValue(errMessage || ERR_UNKNOWN);
}
}
);
Expand Down Expand Up @@ -451,9 +470,17 @@ export const txReDelegate = createAsyncThunk(

return rejectWithValue(result?.rawLog);
}
} catch (error) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
trackEvent('STAKING', 'REDELEGATE', FAILED);
if (error instanceof AxiosError) return rejectWithValue(error.response);
const errMessage = error?.response?.data?.error || error?.message;
dispatch(
setError({
type: 'error',
message: errMessage || ERR_UNKNOWN,
})
);
return rejectWithValue(errMessage || ERR_UNKNOWN);
}
}
);
Expand Down Expand Up @@ -545,9 +572,17 @@ export const txUnDelegate = createAsyncThunk(

return rejectWithValue(result?.rawLog);
}
} catch (error) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
trackEvent('STAKING', 'UNDELEGATE', FAILED);
if (error instanceof AxiosError) return rejectWithValue(error.response);
const errMessage = error?.response?.data?.error || error?.message;
dispatch(
setError({
type: 'error',
message: errMessage || ERR_UNKNOWN,
})
);
return rejectWithValue(errMessage || ERR_UNKNOWN);
}
}
);
Expand Down Expand Up @@ -634,24 +669,17 @@ export const txCancelUnbonding = createAsyncThunk(

return rejectWithValue(result?.rawLog);
}
} catch (error) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
trackEvent('STAKING', 'CANCEL_UNBONDING', FAILED);
if (error instanceof AxiosError) {
dispatch(
setError({
type: 'error',
message: error.message,
})
);
return rejectWithValue(error.response);
}
const errMessage = error?.response?.data?.error || error?.message;
dispatch(
setError({
type: 'error',
message: ERR_UNKNOWN,
message: errMessage || ERR_UNKNOWN,
})
);
return rejectWithValue(ERR_UNKNOWN);
return rejectWithValue(errMessage || ERR_UNKNOWN);
}
}
);
Expand Down

0 comments on commit 7c436d3

Please sign in to comment.