Skip to content

Commit

Permalink
[Fixed] depositId instead of withdrawalId passed to withdraw retry
Browse files Browse the repository at this point in the history
  • Loading branch information
greedyboi committed Aug 10, 2023
1 parent c51bb18 commit a2cd0c7
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default {
leavePool: 'Failed to leave {{ denom }} pool #{{ poolId }}',
claimPrize: 'Failed to claim prizes',
claimAndCompound: 'Failed to compound prizes',
withdrawalRetry: 'Failed to retry withdrawal #{{ depositId }} to pool #{{ poolId }}',
withdrawalRetry: 'Failed to retry withdrawal #{{ withdrawalId }} to pool #{{ poolId }}',
},
success: {
wallet: 'Successfully connected',
Expand All @@ -82,15 +82,15 @@ export default {
claimPrize: 'Successfully claimed prizes',
claimAndCompound: 'Successfully compounded prizes',
logOut: 'You have been logged out.',
withdrawalRetry: 'Successfully retried withdrawal #{{ depositId }} to pool #{{ poolId }}',
withdrawalRetry: 'Successfully retried withdrawal #{{ withdrawalId }} to pool #{{ poolId }}',
},
pending: {
ibcTransfer: 'Transferring...',
deposit: 'Depositing to {{ denom }} pool...',
leavePool: 'Leaving {{ denom }} pool #{{ poolId }}',
claimPrize: 'Claiming prizes...',
claimAndCompound: 'Compounding prizes...',
withdrawalRetry: 'Retrying withdrawal #{{ depositId }} to pool #{{ poolId }}',
withdrawalRetry: 'Retrying withdrawal #{{ withdrawalId }} to pool #{{ poolId }}',
},
landing: {
howItWorks: 'How it works',
Expand Down
2 changes: 2 additions & 0 deletions src/models/deposit.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Deposit as MillionsDeposit } from '@lum-network/sdk-javascript/build/codec/lum/network/millions/deposit';
import { WithdrawalState } from '@lum-network/sdk-javascript/build/codec/lum/network/millions/withdrawal';
import Long from 'long';

export interface DepositModel extends MillionsDeposit {
withdrawalId?: Long;
isWithdrawing?: boolean;
isDepositDrop?: boolean;
unbondingEndAt?: Date;
Expand Down
12 changes: 9 additions & 3 deletions src/pages/MySavings/MySavings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,15 @@ const MySavings = () => {
prices={prices}
onLeavePool={(deposit) => setDepositToLeave(deposit)}
onDepositRetry={(deposit) => dispatch.wallet.retryDeposit({ poolId: deposit.poolId, depositId: deposit.depositId })}
onWithdrawalRetry={(deposit) =>
dispatch.wallet.leavePoolRetry({ poolId: deposit.poolId, depositId: deposit.depositId, denom: DenomsUtils.getNormalDenom(deposit.amount?.denom || '') })
}
onWithdrawalRetry={(deposit) => {
if (deposit.withdrawalId) {
dispatch.wallet.leavePoolRetry({
poolId: deposit.poolId,
withdrawalId: deposit.withdrawalId,
denom: DenomsUtils.getNormalDenom(deposit.amount?.denom || ''),
});
}
}}
/>
</Card>
</>
Expand Down
20 changes: 13 additions & 7 deletions src/redux/models/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ interface LeavePoolPayload {
depositId: Long;
}

interface LeavePoolRetryPayload {
poolId: Long;
denom: string;
withdrawalId: Long;
}

interface WalletState {
lumWallet: LumWalletModel | null;
otherWallets: {
Expand Down Expand Up @@ -601,37 +607,37 @@ export const wallet = createModel<RootModel>()({
return null;
}
},
async leavePoolRetry(payload: LeavePoolPayload, state): Promise<{ hash: Uint8Array; error: string | null | undefined } | null> {
async leavePoolRetry(payload: LeavePoolRetryPayload, state): Promise<{ hash: Uint8Array; error: string | null | undefined } | null> {
const { lumWallet } = state.wallet;

const toastId = ToastUtils.showLoadingToast({ content: I18n.t('pending.withdrawalRetry', { depositId: payload.depositId.toString(), poolId: payload.poolId.toString() }) });
const toastId = ToastUtils.showLoadingToast({ content: I18n.t('pending.withdrawalRetry', { withdrawalId: payload.withdrawalId.toString(), poolId: payload.poolId.toString() }) });

try {
if (!lumWallet) {
throw new Error(I18n.t('errors.client.noWalletConnected'));
}

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

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

ToastUtils.updateLoadingToast(toastId, 'success', {
content: I18n.t('success.withdrawalRetry', { depositId: payload.depositId.toString(), poolId: payload.poolId.toString() }),
content: I18n.t('success.withdrawalRetry', { withdrawalId: payload.withdrawalId.toString(), poolId: payload.poolId.toString() }),
});

Firebase.logEvent(FirebaseConstants.ANALYTICS_EVENTS.LEAVE_POOL_RETRY_SUCCESS, {
pool_id: payload.poolId?.toString(),
deposit_id: payload.depositId?.toString(),
pool_id: payload.poolId.toString(),
deposit_id: payload.withdrawalId.toString(),
denom: payload.denom,
});

dispatch.wallet.reloadWalletInfos({ address: lumWallet.address, force: true });
return result;
} catch (e) {
ToastUtils.updateLoadingToast(toastId, 'error', {
content: (e as Error).message || I18n.t('errors.withdrawalRetry', { depositId: payload.depositId.toString(), poolId: payload.poolId.toString() }),
content: (e as Error).message || I18n.t('errors.withdrawalRetry', { withdrawalId: payload.withdrawalId.toString(), poolId: payload.poolId.toString() }),
});
return null;
}
Expand Down
1 change: 1 addition & 0 deletions src/utils/lumClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class LumClient {
poolId: withdrawal.poolId,
amount: withdrawal.amount,
depositId: withdrawal.depositId,
withdrawalId: withdrawal.withdrawalId,
depositorAddress: withdrawal.depositorAddress,
isWithdrawing: true,
isDepositDrop: false,
Expand Down

0 comments on commit a2cd0c7

Please sign in to comment.