Skip to content

Commit

Permalink
[Added] Error check to ignore tendermint false error
Browse files Browse the repository at this point in the history
  • Loading branch information
greedyboi committed Nov 21, 2023
1 parent 0179d1b commit b21a674
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 24 deletions.
6 changes: 3 additions & 3 deletions src/pages/Deposit/components/DepositSteps/DepositSteps.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from 'react';
import { FormikProps } from 'formik';
import { LumConstants, LumTypes, LumUtils } from '@lum-network/sdk-javascript';
import { LumConstants, LumTypes } from '@lum-network/sdk-javascript';
import { DepositState } from '@lum-network/sdk-javascript/build/codec/lum/network/millions/deposit';
import numeral from 'numeral';
import { useNavigate, useParams } from 'react-router-dom';
Expand Down Expand Up @@ -41,7 +41,7 @@ interface Props {
};
onNextStep: () => void;
onPrevStep: (prevAmount: string, nextAmount: string) => void;
onDeposit: (poolToDeposit: PoolModel, depositAmount: string) => Promise<{ hash: Uint8Array; error: string | null | undefined } | null>;
onDeposit: (poolToDeposit: PoolModel, depositAmount: string) => Promise<{ hash: string; error: string | null | undefined } | null>;
onFinishDeposit: (callback: () => void) => void;
onTwitterShare: () => void;
lumWallet: LumWalletModel | null;
Expand Down Expand Up @@ -497,7 +497,7 @@ const DepositSteps = (props: Props) => {
if (res && !res.error) {
onFinishDeposit(onNextStep);
setTxInfos({
hash: LumUtils.toHex(res.hash).toUpperCase(),
hash: res.hash.toUpperCase(),
amount: numeral(depositAmount).format('0,0[.]00'),
denom: DenomsUtils.getNormalDenom(poolToDeposit.nativeDenom).toUpperCase(),
tvl: numeral(NumbersUtils.convertUnitNumber(poolToDeposit.tvlAmount) + Number(depositAmount)).format('0,0'),
Expand Down
4 changes: 2 additions & 2 deletions src/pages/MySavings/components/Modals/Claim/Claim.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useRef, useState } from 'react';
import { LumTypes, LumUtils } from '@lum-network/sdk-javascript';
import { LumTypes } from '@lum-network/sdk-javascript';
import { DepositState } from '@lum-network/sdk-javascript/build/codec/lum/network/millions/deposit';
import dayjs from 'dayjs';
import numeral from 'numeral';
Expand Down Expand Up @@ -189,7 +189,7 @@ const Claim = ({ prizes, prices, pools }: Props) => {
setClaimOnly(false);
setCurrentStep(2);
setShareInfos({
hash: LumUtils.toHex(res.hash).toUpperCase(),
hash: res.hash.toUpperCase(),
amount,
tvl: numeral(NumbersUtils.convertUnitNumber(pool?.tvlAmount || '')).format('0,0'),
compounded: compound,
Expand Down
36 changes: 23 additions & 13 deletions src/redux/models/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ interface WalletState {
prizesMutex: boolean;
}

//FIXME: When tendermint invalid string on cosmjs has been fixed
const txHasError = (
result: {
hash: string;
error: string | null | undefined;
} | null,
) => {
return !!(!result || (result && result.error && !result.error.includes('Invalid string')));
};

export const wallet = createModel<RootModel>()({
name: 'wallet',
state: {
Expand Down Expand Up @@ -603,7 +613,7 @@ export const wallet = createModel<RootModel>()({

client.disconnect();

if (!result || (result && result.error)) {
if (txHasError(result)) {
throw new Error(result?.error || I18n.t('errors.ibcTransfer'));
}

Expand Down Expand Up @@ -640,7 +650,7 @@ export const wallet = createModel<RootModel>()({
return null;
}
},
async depositToPool(payload: DepositToPoolPayload, state): Promise<{ hash: Uint8Array; error: string | null | undefined } | null> {
async depositToPool(payload: DepositToPoolPayload, state): Promise<{ hash: string; error: string | null | undefined } | null> {
const { lumWallet } = state.wallet;

const toastId = ToastUtils.showLoadingToast({ content: I18n.t('pending.deposit', { denom: DenomsUtils.getNormalDenom(payload.pool.nativeDenom).toUpperCase() }) });
Expand All @@ -652,7 +662,7 @@ export const wallet = createModel<RootModel>()({

const result = await LumClient.depositToPool(lumWallet.innerWallet, payload.pool, payload.amount);

if (!result || (result && result.error)) {
if (txHasError(result)) {
throw new Error(result?.error || undefined);
}

Expand All @@ -669,7 +679,7 @@ export const wallet = createModel<RootModel>()({
return null;
}
},
async retryDeposit(payload: RetryDepositPayload, state): Promise<{ hash: Uint8Array; error: string | null | undefined } | null> {
async retryDeposit(payload: RetryDepositPayload, state): Promise<{ hash: string; error: string | null | undefined } | null> {
const { lumWallet } = state.wallet;

const toastId = ToastUtils.showLoadingToast({ content: `Retrying deposit #${payload.depositId.toNumber()} to pool #${payload.poolId.toNumber()}` });
Expand All @@ -681,7 +691,7 @@ export const wallet = createModel<RootModel>()({

const result = await LumClient.depositRetry(lumWallet.innerWallet, payload.poolId, payload.depositId);

if (!result || (result && result.error)) {
if (txHasError(result)) {
throw new Error(result?.error || `Failed to retry deposit #${payload.depositId.toNumber()}`);
}

Expand All @@ -696,7 +706,7 @@ export const wallet = createModel<RootModel>()({
return null;
}
},
async leavePool(payload: LeavePoolPayload, state): Promise<{ hash: Uint8Array; error: string | null | undefined } | null> {
async leavePool(payload: LeavePoolPayload, state): Promise<{ hash: string; error: string | null | undefined } | null> {
const { lumWallet } = state.wallet;

const toastId = ToastUtils.showLoadingToast({ content: I18n.t('pending.leavePool', { denom: payload.denom.toUpperCase(), poolId: payload.poolId.toString() }) });
Expand All @@ -708,7 +718,7 @@ export const wallet = createModel<RootModel>()({

const result = await LumClient.leavePool(lumWallet.innerWallet, payload.poolId, payload.depositId);

if (!result || (result && result.error)) {
if (txHasError(result)) {
throw new Error(result?.error || undefined);
}

Expand All @@ -731,7 +741,7 @@ export const wallet = createModel<RootModel>()({
return null;
}
},
async leavePoolRetry(payload: LeavePoolRetryPayload, state): Promise<{ hash: Uint8Array; error: string | null | undefined } | null> {
async leavePoolRetry(payload: LeavePoolRetryPayload, state): Promise<{ hash: string; error: string | null | undefined } | null> {
const { lumWallet } = state.wallet;

const toastId = ToastUtils.showLoadingToast({ content: I18n.t('pending.withdrawalRetry', { withdrawalId: payload.withdrawalId.toString(), poolId: payload.poolId.toString() }) });
Expand All @@ -743,7 +753,7 @@ export const wallet = createModel<RootModel>()({

const result = await LumClient.leavePoolRetry(lumWallet.innerWallet, payload.poolId, payload.withdrawalId);

if (!result || (result && result.error)) {
if (txHasError(result)) {
throw new Error(result?.error || undefined);
}

Expand All @@ -766,7 +776,7 @@ export const wallet = createModel<RootModel>()({
return null;
}
},
async claimPrizes(payload: ClaimPrizesPayload, state): Promise<{ hash: Uint8Array; error: string | null | undefined } | null> {
async claimPrizes(payload: ClaimPrizesPayload, state): Promise<{ hash: string; error: string | null | undefined } | null> {
const { lumWallet } = state.wallet;

const { prizes, batch, batchTotal, onBatchComplete } = payload;
Expand Down Expand Up @@ -799,7 +809,7 @@ export const wallet = createModel<RootModel>()({

result = await LumClient.claimPrizes(lumWallet.innerWallet, toClaim);

if (!result || (result && result.error)) {
if (txHasError(result)) {
throw new Error(result?.error || undefined);
} else {
const newPrizes = prizesToClaim.slice(toClaim.length);
Expand All @@ -823,7 +833,7 @@ export const wallet = createModel<RootModel>()({
return null;
}
},
async claimAndCompoundPrizes(payload: ClaimPrizesPayload, state): Promise<{ hash: Uint8Array; error: string | null | undefined } | null> {
async claimAndCompoundPrizes(payload: ClaimPrizesPayload, state): Promise<{ hash: string; error: string | null | undefined } | null> {
const { prizes } = payload;
const claimRes = await dispatch.wallet.claimPrizes(payload);

Expand Down Expand Up @@ -865,7 +875,7 @@ export const wallet = createModel<RootModel>()({

const result = await LumClient.multiDeposit(lumWallet.innerWallet, toDeposit);

if (!result || (result && result.error)) {
if (txHasError(result)) {
throw new Error(result?.error || undefined);
}

Expand Down
12 changes: 6 additions & 6 deletions src/utils/lumClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ class LumClient {
const broadcasted = LumUtils.broadcastTxCommitSuccess(broadcastResult);

return {
hash: broadcastResult.hash,
hash: LumUtils.toHex(broadcastResult.hash),
error: !broadcasted ? (broadcastResult.deliverTx && broadcastResult.deliverTx.log ? broadcastResult.deliverTx.log : broadcastResult.checkTx.log) : null,
};
};
Expand Down Expand Up @@ -342,7 +342,7 @@ class LumClient {
const broadcasted = LumUtils.broadcastTxCommitSuccess(broadcastResult);

return {
hash: broadcastResult.hash,
hash: LumUtils.toHex(broadcastResult.hash),
error: !broadcasted ? (broadcastResult.deliverTx && broadcastResult.deliverTx.log ? broadcastResult.deliverTx.log : broadcastResult.checkTx.log) : null,
};
};
Expand Down Expand Up @@ -381,7 +381,7 @@ class LumClient {
const broadcasted = LumUtils.broadcastTxCommitSuccess(broadcastResult);

return {
hash: broadcastResult.hash,
hash: LumUtils.toHex(broadcastResult.hash),
error: !broadcasted ? (broadcastResult.deliverTx && broadcastResult.deliverTx.log ? broadcastResult.deliverTx.log : broadcastResult.checkTx.log) : null,
};
};
Expand Down Expand Up @@ -411,7 +411,7 @@ class LumClient {
const broadcasted = LumUtils.broadcastTxCommitSuccess(broadcastResult);

return {
hash: broadcastResult.hash,
hash: LumUtils.toHex(broadcastResult.hash),
error: !broadcasted ? (broadcastResult.deliverTx && broadcastResult.deliverTx.log ? broadcastResult.deliverTx.log : broadcastResult.checkTx.log) : null,
};
};
Expand Down Expand Up @@ -441,7 +441,7 @@ class LumClient {
const broadcasted = LumUtils.broadcastTxCommitSuccess(broadcastResult);

return {
hash: broadcastResult.hash,
hash: LumUtils.toHex(broadcastResult.hash),
error: !broadcasted ? (broadcastResult.deliverTx && broadcastResult.deliverTx.log ? broadcastResult.deliverTx.log : broadcastResult.checkTx.log) : null,
};
};
Expand Down Expand Up @@ -475,7 +475,7 @@ class LumClient {
const broadcasted = LumUtils.broadcastTxCommitSuccess(broadcastResult);

return {
hash: broadcastResult.hash,
hash: LumUtils.toHex(broadcastResult.hash),
error: !broadcasted ? (broadcastResult.deliverTx && broadcastResult.deliverTx.log ? broadcastResult.deliverTx.log : broadcastResult.checkTx.log) : null,
};
};
Expand Down

0 comments on commit b21a674

Please sign in to comment.