Skip to content

Commit

Permalink
Merge branch 'master' into feature/deposit-drop
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/pages/Deposit/components/DepositSteps/DepositSteps.tsx
  • Loading branch information
ThibaultJRD committed Nov 22, 2023
2 parents 74c3a9e + 32f3356 commit 7a55cf2
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 24 deletions.
7 changes: 4 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 @@ -40,7 +40,8 @@ interface Props {
[denom: string]: OtherWalletModel;
};
onNextStep: () => void;
onDeposit: (poolToDeposit: PoolModel, depositAmount: string) => Promise<{ hash: Uint8Array; error: string | null | undefined } | null>;
onPrevStep: (prevAmount: string, nextAmount: string) => void;
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 @@ -496,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 @@ -100,6 +100,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 @@ -643,7 +653,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 @@ -680,7 +690,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 @@ -692,7 +702,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 @@ -709,7 +719,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 @@ -721,7 +731,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 @@ -736,7 +746,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 @@ -748,7 +758,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 @@ -771,7 +781,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 @@ -783,7 +793,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 @@ -806,7 +816,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 @@ -839,7 +849,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 @@ -863,7 +873,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 @@ -905,7 +915,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 7a55cf2

Please sign in to comment.