Skip to content

Commit

Permalink
fix(trading): withdrawal issues (#6823)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrussell36 authored Aug 26, 2024
1 parent 5417a12 commit 6424747
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
7 changes: 6 additions & 1 deletion apps/trading/components/asset-activity/use-asset-activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
useWithdrawals,
} from '@vegaprotocol/withdraws';
import { toBigNum } from '@vegaprotocol/utils';
import { WithdrawalStatus } from '@vegaprotocol/types';

export interface RowBase {
asset: AssetFieldsFragment | undefined;
Expand Down Expand Up @@ -84,7 +85,11 @@ export const useAssetActivity = () => {
// Filter out any incomplete withdrawals so they can be added as
// pinned rows to the top
const rows = orderedRows.filter((r) => {
if (r.type === 'Withdrawal' && !r.detail.txHash) {
if (
r.type === 'Withdrawal' &&
r.detail.status !== WithdrawalStatus.STATUS_REJECTED &&
!r.detail.txHash
) {
pinnedTopRows.push(r);
return false;
}
Expand Down
24 changes: 20 additions & 4 deletions apps/trading/components/asset-activity/withdrawal-status-cell.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DAY, getDateTimeFormat, getTimeFormat } from '@vegaprotocol/utils';
import { WithdrawalStatusMapping } from '@vegaprotocol/types';
import { WithdrawalStatus, WithdrawalStatusMapping } from '@vegaprotocol/types';
import {
useEVMBridgeConfigs,
useEthereumConfig,
Expand All @@ -20,7 +20,10 @@ type Props = {
};

export const WithdrawalStatusCell = ({ data, openDialog }: Props) => {
if (!data.detail.txHash) {
if (
data.detail.status !== WithdrawalStatus.STATUS_REJECTED &&
!data.detail.txHash
) {
return <WithdrawalStatusOpen data={data} openDialog={openDialog} />;
}

Expand All @@ -39,7 +42,13 @@ const WithdrawalStatusOpen = ({ data, openDialog }: Props) => {
},
});

const [status, setStatus] = useState<'idle' | 'delayed' | 'ready'>(() => {
const [status, setStatus] = useState<
'idle' | 'delayed' | 'ready' | 'rejected'
>(() => {
if (data.detail.status === WithdrawalStatus.STATUS_REJECTED) {
return 'rejected';
}

if (data.asset?.source.__typename === 'ERC20') {
if (data.asset.source.withdrawThreshold === '0') {
return 'ready';
Expand Down Expand Up @@ -70,6 +79,11 @@ const WithdrawalStatusOpen = ({ data, openDialog }: Props) => {
data.asset?.source.__typename === 'ERC20' &&
data.asset?.source.withdrawThreshold !== '0';

if (data.detail.status === WithdrawalStatus.STATUS_REJECTED) {
setStatus('rejected');
return;
}

if (hasThreshold && delay) {
const readyTimestamp =
new Date(data.detail.createdTimestamp).getTime() +
Expand All @@ -86,6 +100,8 @@ const WithdrawalStatusOpen = ({ data, openDialog }: Props) => {
} else {
setStatus('ready');
}
} else {
setStatus('ready');
}
};

Expand All @@ -94,7 +110,7 @@ const WithdrawalStatusOpen = ({ data, openDialog }: Props) => {
return () => {
clearTimeout(timeoutRef.current);
};
}, [delay, data.asset, data.detail.createdTimestamp]);
}, [delay, data.asset, data.detail.createdTimestamp, data.detail.status]);

if (status === 'idle') {
return <>-</>;
Expand Down
16 changes: 13 additions & 3 deletions libs/web3/src/lib/use-vega-transaction-updater.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import groupBy from 'lodash/groupBy';
import { useApolloClient } from '@apollo/client';
import { useVegaWallet } from '@vegaprotocol/wallet-react';
import {
Expand Down Expand Up @@ -63,15 +64,24 @@ export const useVegaTransactionUpdater = () => {
variables,
skip,
fetchPolicy: 'no-cache',
onData: ({ data: result }) =>
result.data?.busEvents?.forEach((event) => {
onData: ({ data: result }) => {
// If a withdrawal is rejected the subscription will get two events the first
// will have STATUS_OPEN and the second will have STATUS_REJECTED, so we need
// to take the last update for each withdrawal
const withdrawals = Object.values(
groupBy(result.data?.busEvents, 'event.id')
);

withdrawals.forEach((w) => {
const event = w[w.length - 1];
if (event.event.__typename === 'Withdrawal') {
const withdrawal = event.event;
waitForWithdrawalApproval(withdrawal.id, client).then((approval) => {
updateWithdrawal(withdrawal, approval);
});
}
}),
});
},
});

useTransactionEventSubscription({
Expand Down

0 comments on commit 6424747

Please sign in to comment.